diff --git a/lib/features/modeling/BpmnLayouter.js b/lib/features/modeling/BpmnLayouter.js index 6bb3867c..1793464a 100644 --- a/lib/features/modeling/BpmnLayouter.js +++ b/lib/features/modeling/BpmnLayouter.js @@ -9,6 +9,8 @@ var BaseLayouter = require('diagram-js/lib/layout/BaseLayouter'), var LayoutUtil = require('diagram-js/lib/layout/LayoutUtil'); +var pointsOnLine = require('diagram-js/lib/util/Geometry').pointsOnLine; + var isExpanded = require('../../util/DiUtil').isExpanded; var getMid = LayoutUtil.getMid, @@ -157,6 +159,20 @@ BpmnLayouter.prototype.layoutConnection = function(connection, hints) { start, end, waypoints, manhattanOptions); + + // filter un-needed waypoints that may be the result of + // bundle collapsing + updatedWaypoints = updatedWaypoints && updatedWaypoints.reduce(function(points, p, idx) { + + var previous = points[points.length - 1], + next = updatedWaypoints[idx + 1]; + + if (!pointsOnLine(previous, next, p, 0)) { + points.push(p); + } + + return points; + }, []); } return updatedWaypoints || [ start, end ]; diff --git a/test/spec/features/modeling/layout/LayoutConnectionSpec.js b/test/spec/features/modeling/layout/LayoutConnectionSpec.js index 54a8c1c0..b3aeeec5 100644 --- a/test/spec/features/modeling/layout/LayoutConnectionSpec.js +++ b/test/spec/features/modeling/layout/LayoutConnectionSpec.js @@ -13,14 +13,17 @@ describe('features/modeling - layout connection', function() { var diagramXML = require('../../../../fixtures/bpmn/sequence-flows.bpmn'); - var testModules = [ coreModule, modelingModule ]; - - beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); + beforeEach(bootstrapModeler(diagramXML, { + modules: [ + coreModule, + modelingModule + ] + })); - describe('connection handling', function() { + describe('should not touch already layouted', function() { - it('should execute', inject(function(elementRegistry, modeling, bpmnFactory) { + it('execute', inject(function(elementRegistry, modeling, bpmnFactory) { // given var sequenceFlowConnection = elementRegistry.get('SequenceFlow_1'), @@ -44,12 +47,8 @@ describe('features/modeling - layout connection', function() { expect(sequenceFlow.di.waypoint).eql(diWaypoints); })); - }); - - describe('undo support', function() { - - it('should undo', inject(function(elementRegistry, commandStack, modeling) { + it('undo', inject(function(elementRegistry, commandStack, modeling) { // given var sequenceFlowConnection = elementRegistry.get('SequenceFlow_1'), @@ -68,12 +67,8 @@ describe('features/modeling - layout connection', function() { expect(sequenceFlow.di.waypoint).eql(oldDiWaypoints); })); - }); - - describe('redo support', function() { - - it('should redo', inject(function(elementRegistry, commandStack, modeling) { + it('redo', inject(function(elementRegistry, commandStack, modeling) { // given var sequenceFlowConnection = elementRegistry.get('SequenceFlow_1'), @@ -95,4 +90,35 @@ describe('features/modeling - layout connection', function() { }); + + it('should remove un-needed waypoints', inject(function(elementRegistry, modeling) { + + // given + var taskShape = elementRegistry.get('Task_2'), + sequenceFlowConnection = elementRegistry.get('SequenceFlow_1'); + + // when + // moving task + modeling.moveElements([ taskShape ], { x: 250, y: -95 }); + + // then + var newWaypoints = sequenceFlowConnection.waypoints; + + expect(newWaypoints.map(toPoint)).to.eql([ + { x: 578, y: 341 }, + { x: 982, y: 341 } + ]); + })); + }); + + + +///////// helpers /////////////////////////// + +function toPoint(p) { + return { + x: p.x, + y: p.y + }; +} \ No newline at end of file