KrzyHonk / bpmn-python

Project for creating a Python library that allows to import/export BPMN diagram (as an XML file) and provides a simple visualization capabilities
GNU General Public License v3.0
65 stars 44 forks source link

Fix edges direction on png visualization of the bpmn graph. #43

Open DorotaDR opened 4 years ago

DorotaDR commented 4 years ago

I found (and solve in the PR) an issue with converting bpmn graph to png - direction of edges weren't based onincomming and outcomming ids (described in node's details), but based on order of adding nodes.

Example:

import bpmn_python.bpmn_diagram_visualizer as visualizer
import bpmn_python.bpmn_diagram_rep as diagram
import graphviz

if __name__ == "__main__":
    bpmn_graph = diagram.BpmnDiagramGraph()
    bpmn_graph.create_new_diagram_graph(diagram_name="diagram1")
    process_id = bpmn_graph.add_process_to_diagram()
    [start_id, _] = bpmn_graph.add_start_event_to_diagram(process_id, start_event_name="start_event",
                                                          start_event_definition="timer")
    [task1_id, _] = bpmn_graph.add_task_to_diagram(process_id, task_name="task1")
    bpmn_graph.add_sequence_flow_to_diagram(process_id, start_id, task1_id, "start_to_one")
    [task2_id, _] = bpmn_graph.add_task_to_diagram(process_id, task_name="task2")
    [flow_id, _] = bpmn_graph.add_sequence_flow_to_diagram(process_id,
                                                           source_ref_id=task2_id,
                                                           target_ref_id=task1_id,
                                                           sequence_flow_name="two_to_one")

    visualizer.bpmn_diagram_to_png(bpmn_graph, "./../test_png/graph_incorrect")

Result of the code above: graph_incorrect

with corrected function bpmn_diagram_to_png() result of the same code looks: graph_correct

I hope the change will help others student like me to use the package in their project of developing process mining for bussiness processes.

Best regards,

lovehina13 commented 4 years ago

I had the same problem and fixed it the same way!

Moreover, I think that all gateways should also be considered as a diamond shape (line 84):

elif node[1].get(consts.Consts.type) in [consts.Consts.complex_gateway, consts.Consts.event_based_gateway, consts.Consts.inclusive_gateway, consts.Consts.exclusive_gateway, consts.Consts.parallel_gateway]: