Skip to content

Commit eb27442

Browse files
author
Ludovic Coquelle
committed
diagrams: condition label similar to UML notation
1 parent 94ccf7c commit eb27442

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

tests/test_graphing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_agraph_diagram(self):
3232
set(m.states.keys()), set([n.name for n in graph.nodes()]))
3333
triggers = set([n.attr['label'] for n in graph.edges()])
3434
for t in triggers:
35-
t = t.split(AGraph.trigger_condition_sep)[0]
35+
t = AGraph.edge_label_from_transition_label(t)
3636
self.assertIsNotNone(getattr(m, t))
3737

3838
self.assertEqual(len(graph.edges()), len(transitions))
@@ -71,7 +71,7 @@ def test_nested_agraph_diagram(self):
7171

7272
triggers = set([n.attr['label'] for n in graph.edges()])
7373
for t in triggers:
74-
t = t.split(AGraph.trigger_condition_sep)[0]
74+
t = AGraph.edge_label_from_transition_label(t)
7575
self.assertIsNotNone(getattr(m, t))
7676

7777
self.assertEqual(len(graph.edges()), 8) # see above
@@ -111,7 +111,7 @@ def test_store_nested_agraph_diagram(self):
111111

112112
triggers = set([n.attr['label'] for n in graph.edges()])
113113
for t in triggers:
114-
t = t.split(AGraph.trigger_condition_sep)[0]
114+
t = AGraph.edge_label_from_transition_label(t)
115115
self.assertIsNotNone(getattr(m, t))
116116

117117
self.assertEqual(len(graph.edges()), 8) # see above

transitions/extensions/diagrams.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ def get_graph(self):
1818

1919
class AGraph(Diagram):
2020

21-
trigger_condition_sep = ' / '
22-
2321
machine_attributes = {
2422
'directed': True,
2523
'strict': False,
@@ -79,11 +77,18 @@ def _add_edges(self, events, container):
7977
lbl = self._transition_label(label, t)
8078
container.add_edge(src, dst, label=lbl)
8179

80+
@staticmethod
81+
def edge_label_from_transition_label(label):
82+
return label.split(' [')[0] # if no condition, label is returned
83+
8284
def _transition_label(self, edge_label, tran):
8385
if self.machine.show_conditions and tran.conditions:
84-
return edge_label + AGraph.trigger_condition_sep + '&'.join(
85-
c.func if c.target else '!' + c.func
86-
for c in tran.conditions
86+
return '{edge_label} [{conditions}]'.format(
87+
edge_label=edge_label,
88+
conditions='&'.join(
89+
c.func if c.target else '!' + c.func
90+
for c in tran.conditions
91+
),
8792
)
8893
return edge_label
8994

0 commit comments

Comments
 (0)