diff --git a/src/outils_graph.py b/src/outils_graph.py index 776d5a974370c0d8aa9795c68f62900840870827..95a931351ab64c0a6bf20652f43833c14dc2e46d 100644 --- a/src/outils_graph.py +++ b/src/outils_graph.py @@ -45,22 +45,28 @@ def generate_graph_mermaid(filename, dico, label_node = True, label_edge = True, import re for match in re.finditer(r"object at (\w+)>", txt): return match.group(1) + + def quoted(label): + if not label.strip(): + return label + return f'"{label}"' + def get_graph_wo_operations_mermaid_temp(dico, txt, count): count+=1 for node in dico["nodes"]: tab= count*"\t" if(node['name']==''): if(label_node): - txt+=f"{tab}{get_id(node['id'])}(({node['xlabel']}));\n" + txt+=f"{tab}{get_id(node['id'])}(({quoted(node['xlabel'])}));\n" else: txt+=f"{tab}{get_id(node['id'])}(({' '}));\n" else: - txt+=f"{tab}{get_id(node['id'])}({node['name']});\n" + txt+=f"{tab}{get_id(node['id'])}({quoted(node['name'])});\n" for edge in dico["edges"]: tab= count*"\t" if(label_edge): - txt+=f"{tab}{get_id(edge['A'])}--{edge['label']}-->{get_id(edge['B'])};\n" + txt+=f"{tab}{get_id(edge['A'])}--{quoted(edge['label'])}-->{get_id(edge['B'])};\n" else: txt+=f"{tab}{get_id(edge['A'])}-->{get_id(edge['B'])};\n" for subworkflow in dico["subworkflows"]: @@ -73,7 +79,7 @@ def generate_graph_mermaid(filename, dico, label_node = True, label_edge = True, return txt txt = get_graph_wo_operations_mermaid_temp(dico, txt, 0) - with open(f"{filename}.md", "w") as text_file: + with open(f"{filename}.mmd", "w") as text_file: text_file.write(txt)