Giter Site home page Giter Site logo

ascii2graph's Introduction

image

image

ascii2graph

Converts ASCII text to a graph (represented as a dictionary of connections and angles). It can represent directed and undirected graphs.

Installation

$ pip install ascii2graph

Example

from ascii2graph import graph

text = r'''
a->boo
^   |   x
|   v  /
c<--d-e
    | |
    f-g'''

result = graph(text)
print(result)

This produces the following graph (dictionary):

result = {(1, 4, 'a'): [(1, 7, 'boo', 90)],
          (4, 4, 'c'): [(1, 4, 'a', 0)],
          (4, 8, 'd'): [(4, 4, 'c', 270), (4, 10, 'e', 90), (6, 8, 'f', 180)],
          (4, 10, 'e'): [(2, 12, 'x', 45), (4, 8, 'd', 270), (6, 10, 'g', 180)],
          (2, 12, 'x'): [(4, 10, 'e', 225)],
          (6, 8, 'f'): [(6, 10, 'g', 90), (4, 8, 'd', 0)],
          (6, 10, 'g'): [(6, 8, 'f', 270), (4, 10, 'e', 0)],
          (1, 7, 'boo'): [(4, 8, 'd', 180)]}

Nodes can be anything that is not one of these characters:

- | / \ v ^ < >

There is one exception (sorry!): If "/" is part of [sometext/foo], then it is not interpreted as an edge. The reason is that I needed this to visualize Git branches and Git history where I needed [origin/somebranch].

But ... why?

I use it to create SVG graphics for teaching Git DAGs from plain text files because it is so easy to change a text file and simply generate a new SVG image. This module helps me to obtain a graph representation that I can use somewhere else to generate graphics.

Suggestions? Corrections? Pull requests?

Yes please!

ascii2graph's People

Contributors

bast avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.