-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviz.py
More file actions
46 lines (36 loc) · 1.08 KB
/
viz.py
File metadata and controls
46 lines (36 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import sys
import os
root = os.path.normpath(os.path.join(__file__, './../../'))
sys.path.append(root) #allows us to fetch files from the project root
from modules.open_digraph import *
import graphviz
def vizualize_graph(graph: open_digraph):
dot = graphviz.Digraph()
with dot.subgraph(name='inputs') as s:
s.attr(rank='same')
for i in graph.inputs:
nd = graph.nodes[i]
s.node(str(nd.id), nd.label, shape='none')
with dot.subgraph(name='outputs') as s:
s.attr(rank='same')
for i in graph.outputs:
nd = graph.nodes[i]
s.node(str(nd.id), nd.label)
for i in graph.nodes.keys():
if (i not in graph.inputs )and (i not in graph.outputs):
nd = graph.nodes[i]
dot.node(str(nd.id), nd.label)
stack = graph.inputs
def run(ind):
if(ind == len(stack)):
return
if stack[ind] in graph.outputs:
run(ind+1)
else:
for c in graph[stack[ind]].children:
dot.edge(str(graph[stack[ind]].id), str(graph[c].id))
if c not in stack:
stack.append(c)
run(ind+1)
run(0)
return dot