From cdacc69a3dd909c555b38bd045d14f06e2eb7433 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Wed, 22 Aug 2018 13:54:24 +0200 Subject: [PATCH] chore(modeling/BpmnLayouter): simplify manhattan layout logic --- lib/features/modeling/BpmnLayouter.js | 79 +++++++++++++++------------ 1 file changed, 45 insertions(+), 34 deletions(-) diff --git a/lib/features/modeling/BpmnLayouter.js b/lib/features/modeling/BpmnLayouter.js index ee5030ba..39c8d351 100644 --- a/lib/features/modeling/BpmnLayouter.js +++ b/lib/features/modeling/BpmnLayouter.js @@ -61,41 +61,8 @@ BpmnLayouter.prototype.layoutConnection = function(connection, hints) { // manhattan layout sequence / message flows if (is(connection, 'bpmn:MessageFlow')) { - manhattanOptions = { - preferredLayouts: [ 'v:v' ] - }; + manhattanOptions = getMessageFlowManhattanOptions(source, target); - if (is(target, 'bpmn:Participant')) { - manhattanOptions = { - preferredLayouts: [ 'straight', 'v:v' ] - }; - } - - if (isExpandedSubProcess(target)) { - manhattanOptions = { - preferredLayouts: [ 'straight', 'v:v' ] - }; - } - - if (isExpandedSubProcess(source) && is(target, 'bpmn:FlowNode')) { - manhattanOptions = { - preferredLayouts: [ 'straight', 'v:v' ], - preserveDocking: isExpandedSubProcess(target) ? 'source' : 'target' - }; - } - - if (is(source, 'bpmn:Participant') && is(target, 'bpmn:FlowNode')) { - manhattanOptions = { - preferredLayouts: [ 'straight', 'v:v' ], - preserveDocking: 'target' - }; - } - - if (is(target, 'bpmn:Event')) { - manhattanOptions = { - preferredLayouts: [ 'v:v' ] - }; - } } else @@ -174,6 +141,50 @@ function getAttachOrientation(attachedElement) { } +function getMessageFlowManhattanOptions(source, target) { + return { + preferredLayouts: [ 'straight', 'v:v' ], + preserveDocking: getMessageFlowPreserveDocking(source, target) + }; +} + + +function getMessageFlowPreserveDocking(source, target) { + + // (1) docking element connected to participant has precedence + + if (is(target, 'bpmn:Participant')) { + return 'source'; + } + + if (is(source, 'bpmn:Participant')) { + return 'target'; + } + + // (2) docking element connected to expanded sub-process has precedence + + if (isExpandedSubProcess(target)) { + return 'source'; + } + + if (isExpandedSubProcess(source)) { + return 'target'; + } + + // (3) docking event has precedence + + if (is(target, 'bpmn:Event')) { + return 'target'; + } + + if (is(source, 'bpmn:Event')) { + return 'source'; + } + + return null; +} + + function getConnectionDocking(point, shape) { return point ? (point.original || point) : getMid(shape); }