Skip to content

Commit c66180f

Browse files
committed
Improve process graph
1 parent 2bc85a9 commit c66180f

File tree

3 files changed

+37
-14
lines changed

3 files changed

+37
-14
lines changed

galahad/models.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,24 @@
2626
class NoDashDiGraph(gv.Digraph):
2727
"""Like `.graphviz.Digraph` but removes underscores from labels."""
2828

29+
def __init__(self, *args, **kwargs):
30+
self._edges = []
31+
super().__init__(*args, **kwargs)
32+
33+
def edge(self, tail_name, head_name, label=None, _attributes=None, **attrs):
34+
if not (tail_name, head_name) in self._edges:
35+
self._edges.append((tail_name, head_name))
36+
super().edge(tail_name, head_name, label=label, _attributes=_attributes, **attrs)
37+
2938
@staticmethod
3039
def _quote(identifier, *args, **kwargs):
40+
"""Remove underscores from labels."""
3141
identifier = identifier.replace('_', ' ')
3242
return gv.lang.quote(identifier, *args, **kwargs)
3343

3444
@staticmethod
3545
def _quote_edge(identifier):
46+
"""Remove underscores from labels."""
3647
identifier = identifier.replace('_', ' ')
3748
return gv.lang.quote_edge(identifier)
3849

@@ -219,18 +230,19 @@ def get_graph_svg(cls):
219230

220231
def get_instance_graph(self):
221232
"""Return process instance graph."""
222-
graph = self.get_graph(color='#666666')
233+
graph = self.get_graph(color='#888888')
234+
235+
node_names = dict(self.get_nodes()).keys()
223236

224-
for task in self.task_set.exclude(node_name='manual_override'):
225-
node = task.node
237+
for task in self.task_set.filter(node_name__in=node_names):
226238
href = task.get_absolute_url()
227239
style = 'filled'
228240

229-
if node.node_type == tasks.HUMAN:
241+
if task.node_type == tasks.HUMAN:
230242
style += ', rounded'
231243
if not task.completed:
232244
style += ', bold'
233-
graph.node(node.node_name, href=href, style=style, color='black', fontcolor='black')
245+
graph.node(task.node_name, href=href, style=style, color='black', fontcolor='black')
234246

235247
for task in self.task_set.filter(node_name='manual_override').prefetch_related(
236248
'parent_task_set', 'child_task_set'
@@ -242,6 +254,18 @@ def get_instance_graph(self):
242254
for child in task.child_task_set.all():
243255
graph.edge('manual_override_%s' % task.pk, child.node_name, style='dashed')
244256

257+
for task in self.task_set.exclude(node_name__in=node_names).exclude(node_name='manual_override'):
258+
style = 'filled, dashed'
259+
if task.node_type == tasks.HUMAN:
260+
style += ', rounded'
261+
if not task.completed:
262+
style += ', bold'
263+
graph.node(task.node_name, style=style, color='black', fontcolor='black')
264+
for parent in task.parent_task_set.all():
265+
graph.edge(parent.node_name, task.node_name, style='dashed')
266+
for child in task.child_task_set.all():
267+
graph.edge(task.node_name, child.node_name, style='dashed')
268+
245269
return graph
246270

247271
def get_instance_graph_svg(self, output_format='svg'):
@@ -499,7 +523,6 @@ def enqueue(self, countdown=None, eta=None):
499523
'exception',
500524
'stacktrace',
501525
])
502-
print(self.status)
503526
transaction.on_commit(lambda: celery.task_wrapper.apply_async(
504527
args=(self.pk, self._process_id),
505528
countdown=countdown,

tests/fixtures/simpleprocess_instance.dot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
digraph {
22
graph [rankdir=LR]
33
node [fillcolor=white fontname="sans-serif" shape=rect style=filled]
4-
"start view" [color="#666666" fontcolor="#666666" style="filled, rounded"]
5-
"start method" [color="#666666" fontcolor="#666666" style=filled]
6-
end [color="#666666" fontcolor="#666666" style=filled]
7-
"save the princess" [color="#666666" fontcolor="#666666" style="filled, rounded"]
4+
"start view" [color="#888888" fontcolor="#888888" style="filled, rounded"]
5+
"start method" [color="#888888" fontcolor="#888888" style=filled]
6+
end [color="#888888" fontcolor="#888888" style=filled]
7+
"save the princess" [color="#888888" fontcolor="#888888" style="filled, rounded"]
88
"start view" -> "save the princess"
99
"start method" -> "save the princess"
1010
"save the princess" -> end

tests/fixtures/simpleprocess_instance_manual_override.dot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
digraph {
22
graph [rankdir=LR]
33
node [fillcolor=white fontname="sans-serif" shape=rect style=filled]
4-
"save the princess" [color="#666666" fontcolor="#666666" style="filled, rounded"]
5-
"start view" [color="#666666" fontcolor="#666666" style="filled, rounded"]
6-
"start method" [color="#666666" fontcolor="#666666" style=filled]
7-
end [color="#666666" fontcolor="#666666" style=filled]
4+
"save the princess" [color="#888888" fontcolor="#888888" style="filled, rounded"]
5+
"start view" [color="#888888" fontcolor="#888888" style="filled, rounded"]
6+
"start method" [color="#888888" fontcolor="#888888" style=filled]
7+
end [color="#888888" fontcolor="#888888" style=filled]
88
"start view" -> "save the princess"
99
"start method" -> "save the princess"
1010
"save the princess" -> end

0 commit comments

Comments
 (0)