Skip to content

Commit 97da710

Browse files
committed
feat(extensions): consider machine_attributes for mermaid graphs (root element only so far)
1 parent 0f929ef commit 97da710

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

transitions/extensions/diagrams_mermaid.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ def get_graph(self, title=None, roi_state=None):
6868
title = title if title else self.machine.title
6969

7070
fsm_graph = ['---', title, '---', 'stateDiagram-v2']
71+
fsm_graph.extend(_to_mermaid(self.machine.machine_attributes, " "))
72+
7173
for style_name, style_attrs in self.machine.style_attributes["node"].items():
7274
if style_name:
7375
fsm_graph.append("classDef s_{} {}".format(
74-
style_name, _to_css(style_attrs)))
76+
style_name, ','.join(_to_mermaid(style_attrs, ":"))))
7577
fsm_graph.append("")
7678
states, transitions = self._get_elements()
7779
if roi_state:
@@ -250,16 +252,16 @@ def draw(self, filename, format=None, prog="dot", args=""):
250252
return None
251253

252254

253-
invalid = {"style", "shape", "peripheries"}
254-
convertible = {"fillcolor": "fill"}
255+
invalid = {"style", "shape", "peripheries", "strict", "directed"}
256+
convertible = {"fillcolor": "fill", "rankdir": "direction"}
255257

256258

257-
def _to_css(style_attrs):
259+
def _to_mermaid(style_attrs, sep):
258260
params = []
259261
for k, v in style_attrs.items():
260262
if k in invalid:
261263
continue
262264
if k in convertible:
263265
k = convertible[k]
264-
params.append("{}:{}".format(k, v))
265-
return ','.join(params)
266+
params.append("{}{}{}".format(k, sep, v))
267+
return params

0 commit comments

Comments
 (0)