Skip to content

Commit a9c35cb

Browse files
committed
Use introspection plots in Graph.visualize
Does still use networkx based plots if given an input dictionary (and networkx is available), falls introspection plot if networkx is unavailable
1 parent 387ecc4 commit a9c35cb

File tree

1 file changed

+33
-32
lines changed

1 file changed

+33
-32
lines changed

data_prototype/conversion_edge.py

+33-32
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,20 @@ def edges(self):
372372
returnSequenceEdge.from_edges("eval", out_edges, output)
373373

374374
defvisualize(self, input: dict[str, Desc] |None=None):
375-
importnetworkxasnx
375+
ifinputisNone:
376+
from .introspectionimportdraw_graph
377+
378+
draw_graph(self)
379+
return
380+
381+
try:
382+
importnetworkxasnx
383+
exceptImportError:
384+
from .introspectionimportdraw_graph
385+
386+
draw_graph(self)
387+
return
388+
376389
importmatplotlib.pyplotasplt
377390

378391
frompprintimportpformat
@@ -382,38 +395,26 @@ def node_format(x):
382395

383396
G=nx.DiGraph()
384397

385-
ifinputisnotNone:
386-
for_, edgesinself._subgraphs:
387-
q: list[dict[str, Desc]] = [input]
388-
explored: set[tuple[tuple[str, str], ...]] =set()
389-
explored.add(
390-
tuple(sorted(((k, v.coordinates) fork, vinq[0].items())))
391-
)
392-
G.add_node(node_format(q[0]))
393-
whileq:
394-
n=q.pop()
395-
foreinedges:
396-
ifDesc.compatible(n, e.input):
397-
w=n|e.output
398-
ifnode_format(w) notinG:
399-
G.add_node(node_format(w))
400-
explored.add(
401-
tuple(
402-
sorted(
403-
((k, v.coordinates) fork, vinw.items())
404-
)
405-
)
398+
for_, edgesinself._subgraphs:
399+
q: list[dict[str, Desc]] = [input]
400+
explored: set[tuple[tuple[str, str], ...]] =set()
401+
explored.add(tuple(sorted(((k, v.coordinates) fork, vinq[0].items()))))
402+
G.add_node(node_format(q[0]))
403+
whileq:
404+
n=q.pop()
405+
foreinedges:
406+
ifDesc.compatible(n, e.input):
407+
w=n|e.output
408+
ifnode_format(w) notinG:
409+
G.add_node(node_format(w))
410+
explored.add(
411+
tuple(
412+
sorted(((k, v.coordinates) fork, vinw.items()))
406413
)
407-
q.append(w)
408-
ifnode_format(w) !=node_format(n):
409-
G.add_edge(node_format(n), node_format(w), name=e.name)
410-
else:
411-
# don't bother separating subgraphs,as the end result is exactly the same here
412-
foredgeinself._edges:
413-
G.add_edge(
414-
node_format(edge.input), node_format(edge.output), name=edge.name
415-
)
416-
414+
)
415+
q.append(w)
416+
ifnode_format(w) !=node_format(n):
417+
G.add_edge(node_format(n), node_format(w), name=e.name)
417418
try:
418419
pos=nx.shell_layout(G)
419420
exceptException:

0 commit comments

Comments
 (0)
close