feat(layout): filter redundant connection waypoints
This commit is contained in:
parent
357f3b3e96
commit
f05ad02198
|
@ -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 ];
|
||||
|
|
|
@ -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
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue