From f1745547f08e3ab40202d0178628828af3d36360 Mon Sep 17 00:00:00 2001 From: Maciej Barelkowski Date: Wed, 8 Apr 2020 11:37:53 +0200 Subject: [PATCH] feat(layouter): prefer straight layout for sub-process connections Related to https://github.com/camunda/camunda-modeler/issues/1758 --- lib/features/modeling/BpmnLayouter.js | 13 ++ .../modeling/layout/LayoutSequenceFlowSpec.js | 115 ++++++++++++++++++ .../LayoutSequenceFlowSpec.subProcess.bpmn | 25 ++++ 3 files changed, 153 insertions(+) create mode 100644 test/spec/features/modeling/layout/LayoutSequenceFlowSpec.subProcess.bpmn diff --git a/lib/features/modeling/BpmnLayouter.js b/lib/features/modeling/BpmnLayouter.js index c629d0b0..9cbbb78c 100644 --- a/lib/features/modeling/BpmnLayouter.js +++ b/lib/features/modeling/BpmnLayouter.js @@ -98,6 +98,8 @@ BpmnLayouter.prototype.layoutConnection = function(connection, hints) { manhattanOptions = { preferredLayouts: getBoundaryEventPreferredLayouts(source, target, connectionEnd) }; + } else if (isExpandedSubProcess(source) || isExpandedSubProcess(target)) { + manhattanOptions = getSubProcessManhattanOptions(source); } else if (is(source, 'bpmn:Gateway')) { manhattanOptions = { preferredLayouts: [ 'v:h' ] @@ -177,6 +179,17 @@ function getMessageFlowPreserveDocking(source, target) { return null; } +function getSubProcessManhattanOptions(source) { + return { + preferredLayouts: [ 'straight', 'h:h' ], + preserveDocking: getSubProcessPreserveDocking(source) + }; +} + +function getSubProcessPreserveDocking(source) { + return isExpandedSubProcess(source) ? 'target' : 'source'; +} + function getConnectionDocking(point, shape) { return point ? (point.original || point) : getMid(shape); } diff --git a/test/spec/features/modeling/layout/LayoutSequenceFlowSpec.js b/test/spec/features/modeling/layout/LayoutSequenceFlowSpec.js index 07fed5c1..c2f4f1e7 100644 --- a/test/spec/features/modeling/layout/LayoutSequenceFlowSpec.js +++ b/test/spec/features/modeling/layout/LayoutSequenceFlowSpec.js @@ -552,4 +552,119 @@ describe('features/modeling - layout', function() { }); + + describe('subProcess', function() { + + var diagramXML = require('./LayoutSequenceFlowSpec.subProcess.bpmn'); + + var testModules = [ coreModule, modelingModule ]; + + beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); + + + it('should layout straight between subProcesses (top -> bottom)', function() { + + // when + var connection = connect('SubProcess_Center', 'SubProcess_Bottom'), + source = connection.source, + target = connection.target; + + var expectedX = getMid(target).x; + + // then + expect(connection).to.have.waypoints([ + { x: expectedX, y: source.y + source.height }, + { x: expectedX, y: target.y } + ]); + }); + + + it('should layout straight between subProcesses (bottom -> top)', function() { + + // when + var connection = connect('SubProcess_Bottom', 'SubProcess_Center'), + source = connection.source, + target = connection.target; + + var expectedX = getMid(target).x; + + // then + expect(connection).to.have.waypoints([ + { x: expectedX, y: source.y }, + { x: expectedX, y: target.y + target.height } + ]); + }); + + + it('should layout straight between subProcess and task next to it (subProcess -> task)', + function() { + + // when + var connection = connect('SubProcess_Center', 'Task_Right'), + source = connection.source, + target = connection.target; + + var expectedY = getMid(target).y; + + // then + expect(connection).to.have.waypoints([ + { x: source.x + source.width, y: expectedY }, + { x: target.x, y: expectedY } + ]); + } + ); + + + it('should layout straight between subProcess and task next to it (task -> subProcess)', + function() { + + // when + var connection = connect('Task_Right', 'SubProcess_Center'), + source = connection.source, + target = connection.target; + + var expectedY = getMid(source).y; + + // then + expect(connection).to.have.waypoints([ + { x: source.x, y: expectedY }, + { x: target.x + target.width, y: expectedY } + ]); + } + ); + + + it('should layout straight between subProcess and task above (subProcess -> task)', function() { + + // when + var connection = connect('SubProcess_Center', 'Task_Top'), + source = connection.source, + target = connection.target; + + var expectedX = getMid(target).x; + + // then + expect(connection).to.have.waypoints([ + { x: expectedX, y: source.y }, + { x: expectedX, y: target.y + target.height } + ]); + }); + + + it('should layout straight between subProcess and task above (task -> subProcess)', function() { + + // when + var connection = connect('Task_Top', 'SubProcess_Center'), + source = connection.source, + target = connection.target; + + var expectedX = getMid(source).x; + + // then + expect(connection).to.have.waypoints([ + { x: expectedX, y: source.y + source.height }, + { x: expectedX, y: target.y } + ]); + }); + }); }); diff --git a/test/spec/features/modeling/layout/LayoutSequenceFlowSpec.subProcess.bpmn b/test/spec/features/modeling/layout/LayoutSequenceFlowSpec.subProcess.bpmn new file mode 100644 index 00000000..0b1a6edc --- /dev/null +++ b/test/spec/features/modeling/layout/LayoutSequenceFlowSpec.subProcess.bpmn @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + +