Skip to content
Snippets Groups Projects
Commit 4ba563e8 authored by George Marchment's avatar George Marchment
Browse files

Merge branch 'mermaid-improvments' into 'main'

Improvements related to mermaid

See merge request !3
parents 8ddd70da 8b00c8a6
No related branches found
No related tags found
1 merge request!3Improvements related to mermaid
Pipeline #13118 passed with stages
in 1 minute and 17 seconds
...@@ -45,22 +45,28 @@ def generate_graph_mermaid(filename, dico, label_node = True, label_edge = True, ...@@ -45,22 +45,28 @@ def generate_graph_mermaid(filename, dico, label_node = True, label_edge = True,
import re import re
for match in re.finditer(r"object at (\w+)>", txt): for match in re.finditer(r"object at (\w+)>", txt):
return match.group(1) 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): def get_graph_wo_operations_mermaid_temp(dico, txt, count):
count+=1 count+=1
for node in dico["nodes"]: for node in dico["nodes"]:
tab= count*"\t" tab= count*"\t"
if(node['name']==''): if(node['name']==''):
if(label_node): 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: else:
txt+=f"{tab}{get_id(node['id'])}(({' '}));\n" txt+=f"{tab}{get_id(node['id'])}(({' '}));\n"
else: 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"]: for edge in dico["edges"]:
tab= count*"\t" tab= count*"\t"
if(label_edge): 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: else:
txt+=f"{tab}{get_id(edge['A'])}-->{get_id(edge['B'])};\n" txt+=f"{tab}{get_id(edge['A'])}-->{get_id(edge['B'])};\n"
for subworkflow in dico["subworkflows"]: for subworkflow in dico["subworkflows"]:
...@@ -73,7 +79,7 @@ def generate_graph_mermaid(filename, dico, label_node = True, label_edge = True, ...@@ -73,7 +79,7 @@ def generate_graph_mermaid(filename, dico, label_node = True, label_edge = True,
return txt return txt
txt = get_graph_wo_operations_mermaid_temp(dico, txt, 0) 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) text_file.write(txt)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment