mirror of
https://github.com/sartography/bpmn-js.git
synced 2025-01-12 10:04:16 +00:00
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 LayoutUtil = require('diagram-js/lib/layout/LayoutUtil');
|
||||||
|
|
||||||
|
var pointsOnLine = require('diagram-js/lib/util/Geometry').pointsOnLine;
|
||||||
|
|
||||||
var isExpanded = require('../../util/DiUtil').isExpanded;
|
var isExpanded = require('../../util/DiUtil').isExpanded;
|
||||||
|
|
||||||
var getMid = LayoutUtil.getMid,
|
var getMid = LayoutUtil.getMid,
|
||||||
@ -157,6 +159,20 @@ BpmnLayouter.prototype.layoutConnection = function(connection, hints) {
|
|||||||
start, end,
|
start, end,
|
||||||
waypoints,
|
waypoints,
|
||||||
manhattanOptions);
|
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 ];
|
return updatedWaypoints || [ start, end ];
|
||||||
|
@ -13,14 +13,17 @@ describe('features/modeling - layout connection', function() {
|
|||||||
|
|
||||||
var diagramXML = require('../../../../fixtures/bpmn/sequence-flows.bpmn');
|
var diagramXML = require('../../../../fixtures/bpmn/sequence-flows.bpmn');
|
||||||
|
|
||||||
var testModules = [ coreModule, modelingModule ];
|
beforeEach(bootstrapModeler(diagramXML, {
|
||||||
|
modules: [
|
||||||
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
|
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
|
// given
|
||||||
var sequenceFlowConnection = elementRegistry.get('SequenceFlow_1'),
|
var sequenceFlowConnection = elementRegistry.get('SequenceFlow_1'),
|
||||||
@ -44,12 +47,8 @@ describe('features/modeling - layout connection', function() {
|
|||||||
expect(sequenceFlow.di.waypoint).eql(diWaypoints);
|
expect(sequenceFlow.di.waypoint).eql(diWaypoints);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
it('undo', inject(function(elementRegistry, commandStack, modeling) {
|
||||||
describe('undo support', function() {
|
|
||||||
|
|
||||||
it('should undo', inject(function(elementRegistry, commandStack, modeling) {
|
|
||||||
|
|
||||||
// given
|
// given
|
||||||
var sequenceFlowConnection = elementRegistry.get('SequenceFlow_1'),
|
var sequenceFlowConnection = elementRegistry.get('SequenceFlow_1'),
|
||||||
@ -68,12 +67,8 @@ describe('features/modeling - layout connection', function() {
|
|||||||
expect(sequenceFlow.di.waypoint).eql(oldDiWaypoints);
|
expect(sequenceFlow.di.waypoint).eql(oldDiWaypoints);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
it('redo', inject(function(elementRegistry, commandStack, modeling) {
|
||||||
describe('redo support', function() {
|
|
||||||
|
|
||||||
it('should redo', inject(function(elementRegistry, commandStack, modeling) {
|
|
||||||
|
|
||||||
// given
|
// given
|
||||||
var sequenceFlowConnection = elementRegistry.get('SequenceFlow_1'),
|
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…
x
Reference in New Issue
Block a user