Skip to content

Commit

Permalink
Setting all Petri net arcs visible when weight of one is != 1
Browse files Browse the repository at this point in the history
  • Loading branch information
fit-alessandro-berti committed Jan 6, 2022
1 parent b1666b1 commit 74ce9b9
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pm4py/visualization/petri_net/common/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ def graphviz_visualization(net, image_format="png", initial_marking=None, final_

# add arcs, in order by their source and target objects names, to avoid undeterminism in the visualization
arcs_sort_list = sorted(list(net.arcs), key=lambda x: (x.source.name, x.target.name))

# check if there is an arc with weight different than 1.
# in that case, all the arcs in the visualization should have the arc weight visible
arc_weight_visible = False
for arc in arcs_sort_list:
if arc.weight != 1:
arc_weight_visible = True
break

for a in arcs_sort_list:
arrowhead = "normal"
if petri_properties.ARCTYPE in a.properties:
Expand All @@ -171,7 +180,7 @@ def graphviz_visualization(net, image_format="png", initial_marking=None, final_
elif a in decorations and "color" in decorations[a]:
viz.edge(str(id(a.source)), str(id(a.target)), color=decorations[a]["color"], fontsize=font_size, arrowhead=arrowhead)
else:
if a.weight != 1:
if arc_weight_visible:
viz.edge(str(id(a.source)), str(id(a.target)), fontsize=font_size, arrowhead=arrowhead, label=str(a.weight))
else:
viz.edge(str(id(a.source)), str(id(a.target)), fontsize=font_size, arrowhead=arrowhead)
Expand Down

0 comments on commit 74ce9b9

Please sign in to comment.