diff --git a/src/outils_graph.py b/src/outils_graph.py index 5a4f5d6b9385a3702dd12fe467a75c61ac9338dc..3ba0f6d228325881dd176264a843f317008b2cf9 100644 --- a/src/outils_graph.py +++ b/src/outils_graph.py @@ -15,7 +15,8 @@ def is_operation(node_id): return True return False -def fill_dot(dot, dico, label_node = True, label_edge = True): + +def add_nodes(dot, dico, label_node = True): for n in dico["nodes"]: try: color = n["color"] @@ -33,16 +34,64 @@ def fill_dot(dot, dico, label_node = True, label_edge = True): dot.node(n["id"], n["name"], shape=n["shape"], xlabel= xlabel, fillcolor=fillcolor, color = color, style="filled") else: dot.node(n["id"], n["name"], shape=n["shape"], fillcolor=fillcolor, color=color, style="filled") + + for sub in dico["subworkflows"]: + with dot.subgraph(name="cluster"+sub) as c: + add_nodes(c, dico["subworkflows"][sub], label_node = label_node) + c.attr(label=sub) + +def add_edges(dot, dico, label_edge = True): for e in dico["edges"]: if(label_edge): dot.edge(e['A'], e['B'], label= e['label']) else: dot.edge(e['A'], e['B']) + for sub in dico["subworkflows"]: with dot.subgraph(name="cluster"+sub) as c: + add_edges(dot, dico["subworkflows"][sub], label_edge = label_edge) + +def fill_dot(dot, dico, label_node = True, label_edge = True): + add_nodes(dot, dico, label_node = label_node) + add_edges(dot, dico, label_edge = label_edge) + + +def fill_dot_2(dot, dico, label_node = True, label_edge = True): + def add_nodes(dot, dico, label_node = True): + for n in dico["nodes"]: + try: + color = n["color"] + except: + color = "" + try: + xlabel = n["xlabel"] + except: + xlabel = "" + try: + fillcolor = n["fillcolor"] + except: + fillcolor = "" + if(label_node): + dot.node(n["id"], n["name"], shape=n["shape"], xlabel= xlabel, fillcolor=fillcolor, color = color, style="filled") + else: + dot.node(n["id"], n["name"], shape=n["shape"], fillcolor=fillcolor, color=color, style="filled") + add_nodes(dot, dico, label_node = label_node) + def add_edges(dot, dico, label_edge = True): + for e in dico["edges"]: + if(label_edge): + dot.edge(e['A'], e['B'], label= e['label']) + else: + dot.edge(e['A'], e['B']) + add_edges(dot, dico, label_edge = label_edge) + + for sub in dico["subworkflows"]: + with dot.subgraph(name="cluster"+sub) as c: + #add_nodes(c, dico["subworkflows"][sub], label_node = label_node) + #add_edges(dot, dico["subworkflows"][sub], label_edge = label_edge) fill_dot(c, dico["subworkflows"][sub], label_node, label_edge) c.attr(label=sub) + def generate_graph_dot(filename, dico, label_node = True, label_edge = True, render_graphs = True): dot = graphviz.Digraph(filename=filename, format='png', comment="temp") fill_dot(dot, dico, label_node, label_edge)