Skip to content

Commit

Permalink
Merge branch '124-added-rankdir-option-for-simplified-interface-s-vis…
Browse files Browse the repository at this point in the history
…ualizations' into 'integration'

[PRIORITY 1] Added rankdir option for simplified interface's visualizations (and fixing here and there support in main methods)

Closes #124

See merge request process-mining/pm4py/pm4py-core!1071
  • Loading branch information
fit-alessandro-berti committed Aug 28, 2023
2 parents 95bbaee + 3bc282c commit 69e6692
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 35 deletions.
74 changes: 48 additions & 26 deletions pm4py/vis.py

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions pm4py/visualization/dfg/util/dfg_gviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def assign_penwidth_edges(dfg):

def graphviz_visualization(activities_count, dfg, image_format="png", measure="frequency",
max_no_of_edges_in_diagram=100000, start_activities=None, end_activities=None, soj_time=None,
font_size="12", bgcolor=constants.DEFAULT_BGCOLOR):
font_size="12", bgcolor=constants.DEFAULT_BGCOLOR, rankdir="TB"):
"""
Do GraphViz visualization of a DFG graph
Expand All @@ -140,6 +140,12 @@ def graphviz_visualization(activities_count, dfg, image_format="png", measure="f
End activities of the log
soj_time
For each activity, the sojourn time in the log
font_size
Size of the text on the activities/edges
bgcolor
Background color of the visualization (i.e., 'transparent', 'white', ...)
rankdir
Direction of the graph ("LR" for left-to-right; "TB" for top-to-bottom)
Returns
-----------
Expand All @@ -152,7 +158,7 @@ def graphviz_visualization(activities_count, dfg, image_format="png", measure="f
end_activities = []

filename = tempfile.NamedTemporaryFile(suffix='.gv')
viz = Digraph("", filename=filename.name, engine='dot', graph_attr={'bgcolor': bgcolor})
viz = Digraph("", filename=filename.name, engine='dot', graph_attr={'bgcolor': bgcolor, 'rankdir': rankdir})

# first, remove edges in diagram that exceeds the maximum number of edges in the diagram
dfg_key_value_list = []
Expand Down
5 changes: 4 additions & 1 deletion pm4py/visualization/dfg/variants/cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Parameters(Enum):
START_TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_START_TIMESTAMP_KEY
FONT_SIZE = "font_size"
AGGREGATION_MEASURE = "aggregation_measure"
RANKDIR = "rankdir"
BGCOLOR = "bgcolor"


Expand Down Expand Up @@ -63,6 +64,8 @@ def apply(dfg: Dict[Tuple[str, str], int], log: EventLog = None, parameters: Opt
font_size = str(font_size)
activities = dfg_utils.get_activities_from_dfg(dfg)
aggregation_measure = exec_utils.get_param_value(Parameters.AGGREGATION_MEASURE, parameters, "mean")

rankdir = exec_utils.get_param_value(Parameters.RANKDIR, parameters, "TB")
bgcolor = exec_utils.get_param_value(Parameters.BGCOLOR, parameters, constants.DEFAULT_BGCOLOR)

# if all the aggregation measures are provided for a given key,
Expand Down Expand Up @@ -101,4 +104,4 @@ def apply(dfg: Dict[Tuple[str, str], int], log: EventLog = None, parameters: Opt
return dfg_gviz.graphviz_visualization(activities_count, dfg, image_format=image_format, measure="cost",
max_no_of_edges_in_diagram=max_no_of_edges_in_diagram,
start_activities=start_activities, end_activities=end_activities, soj_time=soj_time,
font_size=font_size, bgcolor=bgcolor)
font_size=font_size, bgcolor=bgcolor, rankdir=rankdir)
4 changes: 3 additions & 1 deletion pm4py/visualization/dfg/variants/frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Parameters(Enum):
TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_TIMESTAMP_KEY
START_TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_START_TIMESTAMP_KEY
FONT_SIZE = "font_size"
RANKDIR = "rankdir"
BGCOLOR = "bgcolor"


Expand Down Expand Up @@ -63,6 +64,7 @@ def apply(dfg: Dict[Tuple[str, str], int], log: EventLog = None, parameters: Opt
end_activities = dict()
activities = sorted(list(set(dfg_utils.get_activities_from_dfg(dfg)).union(set(start_activities)).union(set(end_activities))))

rankdir = exec_utils.get_param_value(Parameters.RANKDIR, parameters, "TB")
bgcolor = exec_utils.get_param_value(Parameters.BGCOLOR, parameters, constants.DEFAULT_BGCOLOR)

if activities_count is None:
Expand All @@ -88,4 +90,4 @@ def apply(dfg: Dict[Tuple[str, str], int], log: EventLog = None, parameters: Opt
return dfg_gviz.graphviz_visualization(activities_count, dfg, image_format=image_format, measure="frequency",
max_no_of_edges_in_diagram=max_no_of_edges_in_diagram,
start_activities=start_activities, end_activities=end_activities, soj_time=soj_time,
font_size=font_size, bgcolor=bgcolor)
font_size=font_size, bgcolor=bgcolor, rankdir=rankdir)
5 changes: 4 additions & 1 deletion pm4py/visualization/dfg/variants/performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Parameters(Enum):
START_TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_START_TIMESTAMP_KEY
FONT_SIZE = "font_size"
AGGREGATION_MEASURE = "aggregation_measure"
RANKDIR = "rankdir"
BGCOLOR = "bgcolor"


Expand Down Expand Up @@ -60,6 +61,8 @@ def apply(dfg: Dict[Tuple[str, str], int], log: EventLog = None, parameters: Opt
font_size = str(font_size)
activities = dfg_utils.get_activities_from_dfg(dfg)
aggregation_measure = exec_utils.get_param_value(Parameters.AGGREGATION_MEASURE, parameters, "mean")

rankdir = exec_utils.get_param_value(Parameters.RANKDIR, parameters, "TB")
bgcolor = exec_utils.get_param_value(Parameters.BGCOLOR, parameters, constants.DEFAULT_BGCOLOR)

# if all the aggregation measures are provided for a given key,
Expand Down Expand Up @@ -98,4 +101,4 @@ def apply(dfg: Dict[Tuple[str, str], int], log: EventLog = None, parameters: Opt
return dfg_gviz.graphviz_visualization(activities_count, dfg, image_format=image_format, measure="performance",
max_no_of_edges_in_diagram=max_no_of_edges_in_diagram,
start_activities=start_activities, end_activities=end_activities, soj_time=soj_time,
font_size=font_size, bgcolor=bgcolor)
font_size=font_size, bgcolor=bgcolor, rankdir=rankdir)
5 changes: 4 additions & 1 deletion pm4py/visualization/ocel/ocdfg/variants/classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class Parameters(Enum):
FORMAT = "format"
BGCOLOR = "bgcolor"
RANKDIR = "rankdir"
ACT_METRIC = "act_metric"
EDGE_METRIC = "edge_metric"
ACT_THRESHOLD = "act_threshold"
Expand Down Expand Up @@ -125,6 +126,7 @@ def apply(ocdfg: Dict[str, Any], parameters: Optional[Dict[Any, Any]] = None) ->
Parameters of the algorithm:
- Parameters.FORMAT => the format of the output visualization (default: "png")
- Parameters.BGCOLOR => the default background color (default: "bgcolor")
- Parameters.RANKDIR => direction of the graph ("LR" for left-to-right; "TB" for top-to-bottom)
- Parameters.ACT_METRIC => the metric to use for the activities. Available values:
- "events" => number of events (default)
- "unique_objects" => number of unique objects
Expand Down Expand Up @@ -157,6 +159,7 @@ def apply(ocdfg: Dict[str, Any], parameters: Optional[Dict[Any, Any]] = None) ->

image_format = exec_utils.get_param_value(Parameters.FORMAT, parameters, "png")
bgcolor = exec_utils.get_param_value(Parameters.BGCOLOR, parameters, constants.DEFAULT_BGCOLOR)
rankdir = exec_utils.get_param_value(Parameters.RANKDIR, parameters, "TB")
act_metric = exec_utils.get_param_value(Parameters.ACT_METRIC, parameters, "events")
edge_metric = exec_utils.get_param_value(Parameters.EDGE_METRIC, parameters, "event_couples")
act_threshold = exec_utils.get_param_value(Parameters.ACT_THRESHOLD, parameters, 0)
Expand Down Expand Up @@ -263,7 +266,7 @@ def apply(ocdfg: Dict[str, Any], parameters: Optional[Dict[Any, Any]] = None) ->
add_end_node(viz, ot, act, len(ea_count[ot][act]), edge_prefix, nodes, annotation,
min_edges_count[ot], max_edges_count[ot])

viz.attr(rankdir='LR')
viz.attr(rankdir=rankdir)
viz.format = image_format.replace("html", "plain-ext")

return viz
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Parameters(Enum):
ENABLE_DEEPCOPY = "enable_deepcopy"
FONT_SIZE = "font_size"
BGCOLOR = "bgcolor"
RANKDIR = "rankdir"
NUM_EVENTS_PROPERTY = "num_events_property"
NUM_CASES_PROPERTY = "num_cases_property"

Expand Down Expand Up @@ -86,8 +87,9 @@ def apply(tree: ProcessTree, parameters: Optional[Dict[Union[str, Parameters], A
filename = tempfile.NamedTemporaryFile(suffix='.gv')

bgcolor = exec_utils.get_param_value(Parameters.BGCOLOR, parameters, constants.DEFAULT_BGCOLOR)
rankdir = exec_utils.get_param_value(Parameters.RANKDIR, parameters, "TB")

viz = Graph("pt", filename=filename.name, engine='dot', graph_attr={'bgcolor': bgcolor})
viz = Graph("pt", filename=filename.name, engine='dot', graph_attr={'bgcolor': bgcolor, "rankdir": rankdir})
viz.attr('node', shape='ellipse', fixedsize='false')

image_format = exec_utils.get_param_value(Parameters.FORMAT, parameters, "png")
Expand Down
4 changes: 3 additions & 1 deletion pm4py/visualization/process_tree/variants/symbolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Parameters(Enum):
ENABLE_DEEPCOPY = "enable_deepcopy"
FONT_SIZE = "font_size"
BGCOLOR = "bgcolor"
RANKDIR = "rankdir"


def get_color(node, color_map):
Expand Down Expand Up @@ -82,8 +83,9 @@ def apply(tree: ProcessTree, parameters: Optional[Dict[Union[str, Parameters], A
filename = tempfile.NamedTemporaryFile(suffix='.gv')

bgcolor = exec_utils.get_param_value(Parameters.BGCOLOR, parameters, constants.DEFAULT_BGCOLOR)
rankdir = exec_utils.get_param_value(Parameters.RANKDIR, parameters, "TB")

viz = Graph("pt", filename=filename.name, engine='dot', graph_attr={'bgcolor': bgcolor})
viz = Graph("pt", filename=filename.name, engine='dot', graph_attr={'bgcolor': bgcolor, "rankdir": rankdir})
viz.attr('node', shape='ellipse', fixedsize='false')

image_format = exec_utils.get_param_value(Parameters.FORMAT, parameters, "png")
Expand Down
4 changes: 3 additions & 1 deletion pm4py/visualization/process_tree/variants/wo_decoration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Parameters(Enum):
ENABLE_DEEPCOPY = "enable_deepcopy"
FONT_SIZE = "font_size"
BGCOLOR = "bgcolor"
RANKDIR = "rankdir"


# maps the operators to the ProM strings
Expand Down Expand Up @@ -84,8 +85,9 @@ def apply(tree: ProcessTree, parameters: Optional[Dict[Union[str, Parameters], A
filename = tempfile.NamedTemporaryFile(suffix='.gv')

bgcolor = exec_utils.get_param_value(Parameters.BGCOLOR, parameters, constants.DEFAULT_BGCOLOR)
rankdir = exec_utils.get_param_value(Parameters.RANKDIR, parameters, "TB")

viz = Graph("pt", filename=filename.name, engine='dot', graph_attr={'bgcolor': bgcolor})
viz = Graph("pt", filename=filename.name, engine='dot', graph_attr={'bgcolor': bgcolor, 'rankdir': rankdir})
viz.attr('node', shape='ellipse', fixedsize='false')

image_format = exec_utils.get_param_value(Parameters.FORMAT, parameters, "png")
Expand Down
2 changes: 2 additions & 0 deletions pm4py/visualization/process_tree/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def apply(tree0: ProcessTree, parameters: Optional[Dict[Any, Any]] = None, varia
parameters
Possible parameters of the algorithm:
Parameters.FORMAT -> Format of the image (PDF, PNG, SVG; default PNG)
Parameters.BGCOLOR -> Background color to be used (i.e., 'white' or 'transparent')
Parameters.RANKDIR -> Direction of the graph ("LR" for left-to-right; "TB" for top-to-bottom)
variant
Variant of the algorithm to use:
- Variants.WO_DECORATION
Expand Down

0 comments on commit 69e6692

Please sign in to comment.