generated from FeatureCloud/template_dice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiagram.py
executable file
·37 lines (29 loc) · 1.17 KB
/
diagram.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
import pydot
from app import app
if __name__ == '__main__':
app.register()
graph = pydot.Dot("FeatureCloud State Diagram", graph_type="digraph", bgcolor="white")
for s in app.states:
state = app.states[s]
state_node = pydot.Node(state.name, label=state.name)
if state.coordinator and state.participant:
state_node.set('color', 'purple')
elif state.coordinator:
state_node.set('color', 'red')
elif state.participant:
state_node.set('color', 'blue')
if state.name == 'initial' or state.name == 'finished':
state_node.set('peripheries', 2)
graph.add_node(state_node)
for t in app.transitions:
transition = app.transitions[t]
state_edge = pydot.Edge(transition[0].name, transition[1].name if transition[1] else 'finished', label=t)
if transition[2] and transition[3]:
state_edge.set('color', 'purple')
elif transition[3]:
state_edge.set('color', 'red')
elif transition[2]:
state_edge.set('color', 'blue')
graph.add_edge(state_edge)
graph.write_png("output.png")