Commit 553ef8bf authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 5d7c4811
......@@ -434,16 +434,16 @@ import sys
# graphviz returns tree graph representation in dot language.
@func(Tree)
def graphviz(t):
def graphviz(t, clustername=''):
assert isinstance(t, Tree)
symtab = {} # node -> name
outv = []
def emit(line):
outv.append(line)
def emit(text):
outv.append(text)
emit('digraph {')
#emit('subgraph %s {' % clustername) FIXME kills arrows
emit(' splines=false')
for (level, nodev) in enumerate(_walkBFS(t)):
......@@ -453,7 +453,7 @@ def graphviz(t):
# register node insymtab
assert node not in symtab
kind = ('T' if isinstance(node, Tree) else 'B')
symtab[node] = '%s%d:%d' % (kind, level, i)
symtab[node] = '%s%s%d:%d' % (clustername+'_', kind, level, i)
# emit node itself
# approach based on https://github.com/Felerius/btree-generator
......@@ -490,8 +490,8 @@ def graphviz(t):
continue
for (j,child) in enumerate(node.children):
emit(' %s:"con%d" -> %s' % (qq(symtab[node]), j, qq(symtab[child])))
#emit('}')
emit('}')
emit('')
return '\n'.join(outv)
......@@ -501,14 +501,27 @@ def topoview(argv):
if len(argv) == 0:
raise RuntimeError('E: empty argument')
topov = [TopoDecode(_) for _ in argv]
treev = [TopoDecode(_) for _ in argv]
outv = []
def emit(text):
outv.append(text)
emit('digraph {')
emit(' label=%s' % qq(' '.join(argv)))
emit(' labelloc="t"')
for (i, tree) in enumerate(treev):
emit(tree.graphviz(clustername='c%d' % i))
emit('}')
import graphviz as gv
#g = gv.Digraph(comment='AAA')
#print(g.render(format='pdf', view=True))
g = gv.Source(topov[0].graphviz())
#g.view()
g.render('x', format='svg')
g = gv.Source('\n'.join(outv))
g.view()
#g.render('x', format='svg')
if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment