dot-to-ascii
Try it here: https://dot-to-ascii.ggerganov.com
How it works?
- The index.html page sends XHR requests containing your Graphviz input to the dot-to-ascii.php script
- The dot-to-ascii.php script runs the Graph::Easy command line tool to produce a text diagram from the provided Graphviz input
- The result is returned back to index.html where it is displayed in a
<pre>
tag
API
Dot-to-ascii can be easily used in your code by performing https requests to the api.
Python
import requests
def dot_to_ascii(dot: str, fancy: bool = True):
url = 'https://dot-to-ascii.ggerganov.com/dot-to-ascii.php'
boxart = 0
# use nice box drawing char instead of + , | , -
if fancy:
boxart = 1
params = {
'boxart': boxart,
'src': dot,
}
response = requests.get(url, params=params).text
if response == '':
raise SyntaxError('DOT string is not formatted correctly')
return response
graph_dot = '''
graph {
rankdir=LR
0 -- {1 2}
1 -- {2}
2 -- {0 1 3}
3
}
'''
graph_ascii = dot_to_ascii(graph_dot)
print(graph_ascii)
┌─────────┐
│ │
┌───┐ ┌───┐ ┌───┐ ┌───┐
┌─ │ 0 │ ─── │ 1 │ ─── │ │ ─── │ 3 │
│ └───┘ └───┘ │ │ └───┘
│ │ │ │
│ └──────────────── │ 2 │
│ │ │
│ │ │
└───────────────────── │ │
└───┘
Run locally with docker
This uses the minimal Dockerfile with the default apache config etc. Not suitable for production use.
$ docker build -t dot-to-ascii .
$ docker run --rm -d --name dot-to-ascii -p 8080:80 dot-to-ascii
$ # open localhost:8080 in your browser