Skip to content

Commit e13b66b

Browse files
committed
Add plotting function
1 parent a2ba005 commit e13b66b

File tree

1 file changed

+36
-0
lines changed
  • python_workflow_definition/src/python_workflow_definition

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import json
2+
3+
from IPython.display import SVG, display
4+
import networkx as nx
5+
6+
7+
from python_workflow_definition.shared import get_kwargs, convert_nodes_list_to_dict
8+
from python_workflow_definition.purepython import group_edges
9+
10+
11+
def plot(json_file_name):
12+
with open(json_file_name, "r") as f:
13+
content = json.load(f)
14+
15+
graph = nx.DiGraph()
16+
node_dict = convert_nodes_list_to_dict(nodes_list=content["nodes"])
17+
total_lst = group_edges(edges_lst=content["edges"])
18+
19+
for node_id, node_name in node_dict.items():
20+
graph.add_node(node_id, name=str(node_name), label=str(node_name))
21+
22+
for edge_tuple in total_lst:
23+
target_node, edge_dict = edge_tuple
24+
edge_label_dict = {}
25+
for k, v in edge_dict.items():
26+
if v["source"] not in edge_label_dict:
27+
edge_label_dict[v["source"]] = []
28+
if v["sourcePort"] is None:
29+
edge_label_dict[v["source"]].append(k)
30+
else:
31+
edge_label_dict[v["source"]].append(v["sourcePort"] + "=" + k)
32+
for k, v in edge_label_dict.items():
33+
graph.add_edge(str(k), str(target_node), label=", ".join(v))
34+
35+
svg = nx.nx_agraph.to_agraph(graph).draw(prog="dot", format="svg")
36+
display(SVG(svg))

0 commit comments

Comments
 (0)