Skip to main content

Converts ASCII text to a graph (represented as a dictionary).

Project description

https://travis-ci.org/bast/ascii2graph.svg?branch=master https://img.shields.io/badge/license-%20MPL--v2.0-blue.svg

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 ^ < >

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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ascii2graph-0.2.0.tar.gz (4.4 kB view details)

Uploaded Source

File details

Details for the file ascii2graph-0.2.0.tar.gz.

File metadata

File hashes

Hashes for ascii2graph-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1a105150827e3a9da2681f77643008ef49210fd7241572b23f581729238df784
MD5 0fb28a1cad451c8437cc1e1b34287647
BLAKE2b-256 9b551cef0e1d5cb63e87dad85b04bd807938aacc4a5c3121d4aa70865371ec49

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page