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

.

parent 5d7c4811
...@@ -434,16 +434,16 @@ import sys ...@@ -434,16 +434,16 @@ import sys
# graphviz returns tree graph representation in dot language. # graphviz returns tree graph representation in dot language.
@func(Tree) @func(Tree)
def graphviz(t): def graphviz(t, clustername=''):
assert isinstance(t, Tree) assert isinstance(t, Tree)
symtab = {} # node -> name symtab = {} # node -> name
outv = [] outv = []
def emit(line): def emit(text):
outv.append(line) outv.append(text)
emit('digraph {') #emit('subgraph %s {' % clustername) FIXME kills arrows
emit(' splines=false') emit(' splines=false')
for (level, nodev) in enumerate(_walkBFS(t)): for (level, nodev) in enumerate(_walkBFS(t)):
...@@ -453,7 +453,7 @@ def graphviz(t): ...@@ -453,7 +453,7 @@ def graphviz(t):
# register node insymtab # register node insymtab
assert node not in symtab assert node not in symtab
kind = ('T' if isinstance(node, Tree) else 'B') 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 # emit node itself
# approach based on https://github.com/Felerius/btree-generator # approach based on https://github.com/Felerius/btree-generator
...@@ -490,8 +490,8 @@ def graphviz(t): ...@@ -490,8 +490,8 @@ def graphviz(t):
continue continue
for (j,child) in enumerate(node.children): for (j,child) in enumerate(node.children):
emit(' %s:"con%d" -> %s' % (qq(symtab[node]), j, qq(symtab[child]))) emit(' %s:"con%d" -> %s' % (qq(symtab[node]), j, qq(symtab[child])))
#emit('}')
emit('}')
emit('') emit('')
return '\n'.join(outv) return '\n'.join(outv)
...@@ -501,14 +501,27 @@ def topoview(argv): ...@@ -501,14 +501,27 @@ def topoview(argv):
if len(argv) == 0: if len(argv) == 0:
raise RuntimeError('E: empty argument') 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 import graphviz as gv
#g = gv.Digraph(comment='AAA') g = gv.Source('\n'.join(outv))
#print(g.render(format='pdf', view=True))
g = gv.Source(topov[0].graphviz()) g.view()
#g.view() #g.render('x', format='svg')
g.render('x', format='svg')
if __name__ == '__main__': 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