From f5f05ac0114258e5b313157d60da30ccdf23eacc Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Mon, 27 Jun 2016 00:29:54 +0200 Subject: [PATCH] chore(layouting): account for connection(Start|End) hints Related to bpmn-io/diagram-js#167 --- lib/features/modeling/BpmnLayouter.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/features/modeling/BpmnLayouter.js b/lib/features/modeling/BpmnLayouter.js index 028fcfe2..6bb3867c 100644 --- a/lib/features/modeling/BpmnLayouter.js +++ b/lib/features/modeling/BpmnLayouter.js @@ -37,8 +37,13 @@ BpmnLayouter.prototype.layoutConnection = function(connection, hints) { var manhattanOptions, updatedWaypoints; - start = getConnectionDocking(waypoints, 0, source, start); - end = getConnectionDocking(waypoints, waypoints && waypoints.length - 1, target, end); + if (!start) { + start = getConnectionDocking(waypoints && waypoints[0], source); + } + + if (!end) { + end = getConnectionDocking(waypoints && waypoints[waypoints.length - 1], target); + } // TODO(nikku): support vertical modeling // and invert preferredLayouts accordingly @@ -47,7 +52,7 @@ BpmnLayouter.prototype.layoutConnection = function(connection, hints) { is(connection, 'bpmn:DataAssociation')) { if (waypoints && !isCompensationAssociation(connection)) { - return waypoints; + return [].concat([ start ], waypoints.slice(1, -1), [ end ]); } } @@ -167,10 +172,8 @@ function getAttachOrientation(attachedElement) { } -function getConnectionDocking(waypoints, idx, shape, defaultPoint) { - var point = waypoints && waypoints[idx]; - - return point ? (point.original || point) : (defaultPoint || getMid(shape)); +function getConnectionDocking(point, shape) { + return point ? (point.original || point) : getMid(shape); } function isCompensationAssociation(connection) {