Skip to main content

Converts ASCII text to a graph (represented as a dictionary of connections and

Project description

image image PyPI badge

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].

Use case

I use it in https://github.com/bast/gitink 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.

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.3.3.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

ascii2graph-0.3.3-py2.py3-none-any.whl (10.5 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: ascii2graph-0.3.3.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for ascii2graph-0.3.3.tar.gz
Algorithm Hash digest
SHA256 3214dc0f0ee057dcc5c6ab9b67dc8bb912954680d6515eb01747f770417159bc
MD5 f9fd272b06a6e4f46c1bba3a8e72051a
BLAKE2b-256 cfbf2f4a38e3fc6079442ae1591fa78a90f6a6315ed346c75a9b0774a68877ed

See more details on using hashes here.

File details

Details for the file ascii2graph-0.3.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for ascii2graph-0.3.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 28b84afffdd9dd4a379ea66bd8d7238238076e720e5a22d3221af5641a78036c
MD5 d253569edca1885eee117c55258ff37a
BLAKE2b-256 04a20e55ec2e24fbd9710cd85e9d6cef915a5e8b66f6b96b8ae73b5fdab65e46

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