bpmn-js/lib/features/modeling/BpmnLayouter.js
Nico Rehwaldt b233ab957c feat(snapping): add bpmn-specific move snapping
This commit adds message flow + collaboration specific snapping by
subclassing the diagram-js provided default Snapping implementation.

* Add collaboration snapping
* Rename lib/util/{Name}.js -> lib/util/{Name}Util.js

Closes #255
2015-04-29 15:04:54 +02:00

65 lines
1.5 KiB
JavaScript

'use strict';
var inherits = require('inherits');
var assign = require('lodash/object/assign');
var BaseLayouter = require('diagram-js/lib/layout/BaseLayouter'),
LayoutUtil = require('diagram-js/lib/layout/LayoutUtil'),
ManhattanLayout = require('diagram-js/lib/layout/ManhattanLayout');
var is = require('../../util/ModelUtil').is;
function BpmnLayouter() {}
inherits(BpmnLayouter, BaseLayouter);
module.exports = BpmnLayouter;
function getAttachment(waypoints, idx, shape) {
var point = waypoints && waypoints[idx];
return point ? (point.original || point) : LayoutUtil.getMidPoint(shape);
}
BpmnLayouter.prototype.layoutConnection = function(connection, hints) {
var source = connection.source,
target = connection.target,
waypoints = connection.waypoints,
start,
end;
var layoutManhattan,
updatedWaypoints;
start = getAttachment(waypoints, 0, source);
end = getAttachment(waypoints, waypoints && waypoints.length - 1, target);
// manhattan layout sequence / message flows
if (is(connection, 'bpmn:MessageFlow')) {
layoutManhattan = {
preferStraight: true,
preferVertical: true
};
}
if (is(connection, 'bpmn:SequenceFlow')) {
layoutManhattan = {};
}
if (layoutManhattan) {
layoutManhattan = assign(layoutManhattan, hints);
updatedWaypoints =
ManhattanLayout.repairConnection(
source, target, start, end,
waypoints,
layoutManhattan);
}
return updatedWaypoints || [ start, end ];
};