69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
# File 'app/models/wf/workflow.rb', line 69
def to_graph(wf_case = nil, base = nil)
fontfamily = "system, -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Noto Color Emoji, Segoe UI Symbol"
fontfamily_monospace = "SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace"
graph = base || GraphViz.new(name, type: :digraph, rankdir: "LR", splines: true, ratio: :auto)
free_token_places = if wf_case
wf_case.tokens.free.map(&:place_id)
else
[]
end
pg_mapping = {}
places.order("place_type ASC").each do |p|
if p.start?
fillcolor = "#ffe7ba"
textcolor = "#fa8c16"
shape = :doublecircle
elsif p.end?
fillcolor = "#dff2ef"
textcolor = "#29c0b1"
shape = :doublecircle
else
fillcolor = "#fbdbe1"
textcolor = "#ff3366"
shape = :circle
end
token_count = free_token_places.count(p.id)
if token_count >= 1
label = "•"
xlabel = nil
fontsize = 25
else
label = p.name
xlabel = nil
end
pg = graph.add_nodes(p.graph_id,
label: label,
xlabel: xlabel,
shape: shape,
fixedsize: true,
style: :filled,
fontname: fontfamily,
fontcolor: textcolor,
fontsize: fontsize,
color: fillcolor,
fillcolor: fillcolor,
href: Wf::Engine.routes.url_helpers.edit_workflow_place_path(self, p))
pg_mapping[p] = pg
end
tg_mapping = {}
transitions.each do |t|
peripheries = if t.multiple_instance?
3
else
1
end
tg = graph.add_nodes(t.graph_id, label: t.name, shape: :box, style: :filled, fillcolor: "#d6ddfa", color: "#d6ddfa",
fontcolor: "#2c50ed", fontname: fontfamily, peripheries: peripheries,
href: Wf::Engine.routes.url_helpers.edit_workflow_transition_path(self, t))
tg_mapping[t] = tg
next unless t.is_sub_workflow? && t.sub_workflow != t.workflow
sub_graph = graph.add_graph("cluster#{t.sub_workflow_id}", rankdir: "LR", splines: true, ratio: :auto)
sub_graph[:label] = t.sub_workflow.name
sub_graph[:style] = :dashed
sub_graph[:color] = :lightgrey
t.sub_workflow.to_graph(nil, sub_graph)
graph.add_edges(tg, t.sub_workflow.places.start.first.graph_id, style: :dashed, dir: :both)
end
arcs.order("direction desc").each do |arc|
label = if arc.guards_count > 0
arc.guards.map(&:inspect).join(" & ")
else
""
end
if arc.in?
graph.add_edges(
pg_mapping[arc.place],
tg_mapping[arc.transition],
label: label,
weight: 1,
labelfloat: false,
labelfontcolor: :red,
arrowhead: :vee,
fontsize: 10,
color: "#53585c",
fontcolor: "#53585c",
fontname: fontfamily_monospace,
href: Wf::Engine.routes.url_helpers.edit_workflow_arc_path(self, arc)
)
else
graph.add_edges(
tg_mapping[arc.transition],
pg_mapping[arc.place],
label: label,
weight: 1,
labelfloat: false,
labelfontcolor: :red,
arrowhead: :vee,
fontsize: 10,
color: "#53585c",
fontcolor: "#53585c",
fontname: fontfamily_monospace,
href: Wf::Engine.routes.url_helpers.edit_workflow_arc_path(self, arc)
)
end
end
graph
end
|