bpmn-js 9.0.4 → 9.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/assets/diagram-js.css +55 -51
  3. package/dist/bpmn-modeler.development.js +56709 -55920
  4. package/dist/bpmn-modeler.production.min.js +28 -29
  5. package/dist/bpmn-navigated-viewer.development.js +21579 -21237
  6. package/dist/bpmn-navigated-viewer.production.min.js +20 -21
  7. package/dist/bpmn-viewer.development.js +20780 -20438
  8. package/dist/bpmn-viewer.production.min.js +20 -21
  9. package/lib/BaseModeler.js +1 -1
  10. package/lib/BaseViewer.js +14 -4
  11. package/lib/Modeler.js +1 -1
  12. package/lib/NavigatedViewer.js +1 -1
  13. package/lib/Viewer.js +1 -1
  14. package/lib/draw/BpmnRenderUtil.js +3 -1
  15. package/lib/draw/BpmnRenderer.js +11 -9
  16. package/lib/features/auto-place/BpmnAutoPlaceUtil.js +10 -0
  17. package/lib/features/auto-resize/BpmnAutoResize.js +1 -1
  18. package/lib/features/auto-resize/BpmnAutoResizeProvider.js +1 -1
  19. package/lib/features/context-pad/ContextPadProvider.js +57 -3
  20. package/lib/features/copy-paste/ModdleCopy.js +0 -2
  21. package/lib/features/drilldown/DrilldownOverlayBehavior.js +1 -1
  22. package/lib/features/editor-actions/BpmnEditorActions.js +1 -1
  23. package/lib/features/grid-snapping/behavior/LayoutConnectionBehavior.js +1 -1
  24. package/lib/features/interaction-events/BpmnInteractionEvents.js +12 -0
  25. package/lib/features/keyboard/BpmnKeyboardBindings.js +1 -1
  26. package/lib/features/label-editing/LabelEditingProvider.js +14 -1
  27. package/lib/features/modeling/BpmnLayouter.js +1 -1
  28. package/lib/features/modeling/BpmnUpdater.js +1 -1
  29. package/lib/features/modeling/ElementFactory.js +1 -1
  30. package/lib/features/modeling/Modeling.js +1 -1
  31. package/lib/features/modeling/behavior/AdaptiveLabelPositioningBehavior.js +1 -1
  32. package/lib/features/modeling/behavior/AppendBehavior.js +1 -1
  33. package/lib/features/modeling/behavior/AssociationBehavior.js +1 -1
  34. package/lib/features/modeling/behavior/AttachEventBehavior.js +1 -1
  35. package/lib/features/modeling/behavior/BoundaryEventBehavior.js +1 -1
  36. package/lib/features/modeling/behavior/CreateBehavior.js +1 -1
  37. package/lib/features/modeling/behavior/CreateDataObjectBehavior.js +1 -1
  38. package/lib/features/modeling/behavior/CreateParticipantBehavior.js +1 -1
  39. package/lib/features/modeling/behavior/DataInputAssociationBehavior.js +1 -1
  40. package/lib/features/modeling/behavior/DataStoreBehavior.js +1 -1
  41. package/lib/features/modeling/behavior/DeleteLaneBehavior.js +1 -1
  42. package/lib/features/modeling/behavior/DetachEventBehavior.js +1 -1
  43. package/lib/features/modeling/behavior/DropOnFlowBehavior.js +1 -1
  44. package/lib/features/modeling/behavior/EventBasedGatewayBehavior.js +1 -1
  45. package/lib/features/modeling/behavior/GroupBehavior.js +1 -1
  46. package/lib/features/modeling/behavior/IsHorizontalFix.js +1 -1
  47. package/lib/features/modeling/behavior/LabelBehavior.js +1 -1
  48. package/lib/features/modeling/behavior/LayoutConnectionBehavior.js +117 -0
  49. package/lib/features/modeling/behavior/MessageFlowBehavior.js +1 -1
  50. package/lib/features/modeling/behavior/RemoveElementBehavior.js +1 -1
  51. package/lib/features/modeling/behavior/RemoveEmbeddedLabelBoundsBehavior.js +1 -1
  52. package/lib/features/modeling/behavior/RemoveParticipantBehavior.js +1 -1
  53. package/lib/features/modeling/behavior/ReplaceConnectionBehavior.js +1 -1
  54. package/lib/features/modeling/behavior/ReplaceElementBehaviour.js +1 -1
  55. package/lib/features/modeling/behavior/RootElementReferenceBehavior.js +1 -1
  56. package/lib/features/modeling/behavior/SubProcessPlaneBehavior.js +1 -1
  57. package/lib/features/modeling/behavior/SubProcessStartEventBehavior.js +1 -1
  58. package/lib/features/modeling/behavior/ToggleCollapseConnectionBehaviour.js +1 -1
  59. package/lib/features/modeling/behavior/ToggleElementCollapseBehaviour.js +1 -1
  60. package/lib/features/modeling/behavior/UnclaimIdBehavior.js +1 -1
  61. package/lib/features/modeling/behavior/UnsetDefaultFlowBehavior.js +1 -1
  62. package/lib/features/modeling/behavior/UpdateFlowNodeRefsBehavior.js +1 -1
  63. package/lib/features/modeling/behavior/index.js +3 -0
  64. package/lib/features/modeling/behavior/util/ConnectionLayoutUtil.js +16 -0
  65. package/lib/features/modeling/behavior/util/GeometricUtil.js +1 -121
  66. package/lib/features/modeling/behavior/util/LabelLayoutUtil.js +3 -192
  67. package/lib/features/modeling/behavior/util/LayoutUtil.js +230 -0
  68. package/lib/features/modeling/cmd/SetColorHandler.js +6 -2
  69. package/lib/features/ordering/BpmnOrderingProvider.js +1 -1
  70. package/lib/features/replace-preview/BpmnReplacePreview.js +1 -1
  71. package/lib/features/rules/BpmnRules.js +1 -6
  72. package/lib/features/snapping/BpmnCreateMoveSnapping.js +1 -1
  73. package/lib/util/PoweredByUtil.js +59 -44
  74. package/package.json +5 -5
  75. package/test/util/custom-rules/CustomRules.js +1 -1
@@ -0,0 +1,117 @@
1
+ import {
2
+ assign
3
+ } from 'min-dash';
4
+
5
+ import inherits from 'inherits-browser';
6
+
7
+ import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
8
+
9
+ import { getConnectionAdjustment as getConnectionAnchorPoint } from './util/ConnectionLayoutUtil';
10
+
11
+ /**
12
+ * A component that makes sure that Associations connected to Connections
13
+ * are updated together with the Connection.
14
+ *
15
+ * @param {EventBus} eventBus
16
+ * @param {Modeling} modeling
17
+ */
18
+ export default function LayoutConnectionBehavior(
19
+ eventBus, modeling) {
20
+
21
+ CommandInterceptor.call(this, eventBus);
22
+
23
+ function getnewAnchorPoint(event, point) {
24
+
25
+ var context = event.context,
26
+ connection = context.connection,
27
+ hints = assign({}, context.hints),
28
+ newWaypoints = context.newWaypoints || connection.waypoints,
29
+ oldWaypoints = context.oldWaypoints;
30
+
31
+
32
+ if (typeof hints.startChanged === 'undefined') {
33
+ hints.startChanged = !!hints.connectionStart;
34
+ }
35
+
36
+ if (typeof hints.endChanged === 'undefined') {
37
+ hints.endChanged = !!hints.connectionEnd;
38
+ }
39
+
40
+ return getConnectionAnchorPoint(point, newWaypoints, oldWaypoints, hints);
41
+ }
42
+
43
+ this.postExecute([
44
+ 'connection.layout',
45
+ 'connection.updateWaypoints'
46
+ ], function(event) {
47
+ var context = event.context;
48
+
49
+ var connection = context.connection,
50
+ outgoing = connection.outgoing,
51
+ incoming = connection.incoming;
52
+
53
+ incoming.forEach(function(connection) {
54
+ var endPoint = connection.waypoints[connection.waypoints.length - 1];
55
+ var newEndpoint = getnewAnchorPoint(event, endPoint);
56
+
57
+ var newWaypoints = [].concat(connection.waypoints.slice(0, -1), [ newEndpoint ]);
58
+
59
+ modeling.updateWaypoints(connection, newWaypoints);
60
+ });
61
+
62
+ outgoing.forEach(function(connection) {
63
+ var startpoint = connection.waypoints[0];
64
+ var newStartpoint = getnewAnchorPoint(event, startpoint);
65
+
66
+ var newWaypoints = [].concat([ newStartpoint ], connection.waypoints.slice(1));
67
+
68
+ modeling.updateWaypoints(connection, newWaypoints);
69
+ });
70
+
71
+ });
72
+
73
+
74
+ this.postExecute([
75
+ 'connection.move'
76
+ ], function(event) {
77
+ var context = event.context;
78
+
79
+ var connection = context.connection,
80
+ outgoing = connection.outgoing,
81
+ incoming = connection.incoming,
82
+ delta = context.delta;
83
+
84
+ incoming.forEach(function(connection) {
85
+ var endPoint = connection.waypoints[connection.waypoints.length - 1];
86
+ var newEndpoint = {
87
+ x: endPoint.x + delta.x,
88
+ y: endPoint.y + delta.y
89
+ };
90
+
91
+ var newWaypoints = [].concat(connection.waypoints.slice(0, -1), [ newEndpoint ]);
92
+
93
+ modeling.updateWaypoints(connection, newWaypoints);
94
+ });
95
+
96
+ outgoing.forEach(function(connection) {
97
+ var startpoint = connection.waypoints[0];
98
+ var newStartpoint = {
99
+ x: startpoint.x + delta.x,
100
+ y: startpoint.y + delta.y
101
+ };
102
+
103
+ var newWaypoints = [].concat([ newStartpoint ], connection.waypoints.slice(1));
104
+
105
+ modeling.updateWaypoints(connection, newWaypoints);
106
+ });
107
+
108
+ });
109
+
110
+ }
111
+
112
+ inherits(LayoutConnectionBehavior, CommandInterceptor);
113
+
114
+ LayoutConnectionBehavior.$inject = [
115
+ 'eventBus',
116
+ 'modeling'
117
+ ];
@@ -1,4 +1,4 @@
1
- import inherits from 'inherits';
1
+ import inherits from 'inherits-browser';
2
2
 
3
3
  import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
4
4
 
@@ -1,4 +1,4 @@
1
- import inherits from 'inherits';
1
+ import inherits from 'inherits-browser';
2
2
 
3
3
  import { is } from '../../../util/ModelUtil';
4
4
 
@@ -1,4 +1,4 @@
1
- import inherits from 'inherits';
1
+ import inherits from 'inherits-browser';
2
2
 
3
3
  import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
4
4
 
@@ -1,4 +1,4 @@
1
- import inherits from 'inherits';
1
+ import inherits from 'inherits-browser';
2
2
 
3
3
  import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
4
4
 
@@ -4,7 +4,7 @@ import {
4
4
  matchPattern
5
5
  } from 'min-dash';
6
6
 
7
- import inherits from 'inherits';
7
+ import inherits from 'inherits-browser';
8
8
 
9
9
  import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
10
10
 
@@ -1,4 +1,4 @@
1
- import inherits from 'inherits';
1
+ import inherits from 'inherits-browser';
2
2
 
3
3
  import { forEach } from 'min-dash';
4
4
 
@@ -1,4 +1,4 @@
1
- import inherits from 'inherits';
1
+ import inherits from 'inherits-browser';
2
2
 
3
3
  import {
4
4
  find,
@@ -1,4 +1,4 @@
1
- import inherits from 'inherits';
1
+ import inherits from 'inherits-browser';
2
2
 
3
3
  import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
4
4
 
@@ -1,4 +1,4 @@
1
- import inherits from 'inherits';
1
+ import inherits from 'inherits-browser';
2
2
 
3
3
  import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
4
4
 
@@ -1,5 +1,5 @@
1
1
 
2
- import inherits from 'inherits';
2
+ import inherits from 'inherits-browser';
3
3
 
4
4
  import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
5
5
 
@@ -1,4 +1,4 @@
1
- import inherits from 'inherits';
1
+ import inherits from 'inherits-browser';
2
2
 
3
3
  import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
4
4
 
@@ -1,4 +1,4 @@
1
- import inherits from 'inherits';
1
+ import inherits from 'inherits-browser';
2
2
 
3
3
  import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
4
4
 
@@ -1,4 +1,4 @@
1
- import inherits from 'inherits';
1
+ import inherits from 'inherits-browser';
2
2
 
3
3
  import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
4
4
 
@@ -1,4 +1,4 @@
1
- import inherits from 'inherits';
1
+ import inherits from 'inherits-browser';
2
2
 
3
3
  import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
4
4
 
@@ -17,6 +17,7 @@ import GroupBehavior from './GroupBehavior';
17
17
  import ImportDockingFix from './ImportDockingFix';
18
18
  import IsHorizontalFix from './IsHorizontalFix';
19
19
  import LabelBehavior from './LabelBehavior';
20
+ import LayoutConnectionBehavior from './LayoutConnectionBehavior';
20
21
  import MessageFlowBehavior from './MessageFlowBehavior';
21
22
  import ModelingFeedback from './ModelingFeedback';
22
23
  import RemoveEmbeddedLabelBoundsBehavior from './RemoveEmbeddedLabelBoundsBehavior';
@@ -57,6 +58,7 @@ export default {
57
58
  'importDockingFix',
58
59
  'isHorizontalFix',
59
60
  'labelBehavior',
61
+ 'layoutConnectionBehavior',
60
62
  'messageFlowBehavior',
61
63
  'modelingFeedback',
62
64
  'removeElementBehavior',
@@ -95,6 +97,7 @@ export default {
95
97
  importDockingFix: [ 'type', ImportDockingFix ],
96
98
  isHorizontalFix: [ 'type', IsHorizontalFix ],
97
99
  labelBehavior: [ 'type', LabelBehavior ],
100
+ layoutConnectionBehavior: [ 'type', LayoutConnectionBehavior ],
98
101
  messageFlowBehavior: [ 'type', MessageFlowBehavior ],
99
102
  modelingFeedback: [ 'type', ModelingFeedback ],
100
103
  removeElementBehavior: [ 'type', RemoveElementBehavior ],
@@ -0,0 +1,16 @@
1
+ import { getAnchorPointAdjustment } from './LayoutUtil';
2
+
3
+ /**
4
+ * Calculate the new point after the connection waypoints got updated.
5
+ *
6
+ * @param {djs.model.Label} label
7
+ * @param {Array<Point>} newWaypoints
8
+ * @param {Array<Point>} oldWaypoints
9
+ * @param {Object} hints
10
+ *
11
+ * @return {Point} point
12
+ */
13
+ export function getConnectionAdjustment(position, newWaypoints, oldWaypoints, hints) {
14
+ return getAnchorPointAdjustment(position, newWaypoints, oldWaypoints, hints).point;
15
+ }
16
+
@@ -1,121 +1 @@
1
- /**
2
- * Returns the length of a vector
3
- *
4
- * @param {Vector}
5
- * @return {Float}
6
- */
7
- export function vectorLength(v) {
8
- return Math.sqrt(Math.pow(v.x, 2) + Math.pow(v.y, 2));
9
- }
10
-
11
-
12
- /**
13
- * Calculates the angle between a line a the yAxis
14
- *
15
- * @param {Array}
16
- * @return {Float}
17
- */
18
- export function getAngle(line) {
19
-
20
- // return value is between 0, 180 and -180, -0
21
- // @janstuemmel: maybe replace return a/b with b/a
22
- return Math.atan((line[1].y - line[0].y) / (line[1].x - line[0].x));
23
- }
24
-
25
-
26
- /**
27
- * Rotates a vector by a given angle
28
- *
29
- * @param {Vector}
30
- * @param {Float} Angle in radians
31
- * @return {Vector}
32
- */
33
- export function rotateVector(vector, angle) {
34
- return (!angle) ? vector : {
35
- x: Math.cos(angle) * vector.x - Math.sin(angle) * vector.y,
36
- y: Math.sin(angle) * vector.x + Math.cos(angle) * vector.y
37
- };
38
- }
39
-
40
-
41
- /**
42
- * Solves a 2D equation system
43
- * a + r*b = c, where a,b,c are 2D vectors
44
- *
45
- * @param {Vector}
46
- * @param {Vector}
47
- * @param {Vector}
48
- * @return {Float}
49
- */
50
- function solveLambaSystem(a, b, c) {
51
-
52
- // the 2d system
53
- var system = [
54
- { n: a[0] - c[0], lambda: b[0] },
55
- { n: a[1] - c[1], lambda: b[1] }
56
- ];
57
-
58
- // solve
59
- var n = system[0].n * b[0] + system[1].n * b[1],
60
- l = system[0].lambda * b[0] + system[1].lambda * b[1];
61
-
62
- return -n/l;
63
- }
64
-
65
-
66
- /**
67
- * Position of perpendicular foot
68
- *
69
- * @param {Point}
70
- * @param [ {Point}, {Point} ] line defined through two points
71
- * @return {Point} the perpendicular foot position
72
- */
73
- export function perpendicularFoot(point, line) {
74
-
75
- var a = line[0], b = line[1];
76
-
77
- // relative position of b from a
78
- var bd = { x: b.x - a.x, y: b.y - a.y };
79
-
80
- // solve equation system to the parametrized vectors param real value
81
- var r = solveLambaSystem([ a.x, a.y ], [ bd.x, bd.y ], [ point.x, point.y ]);
82
-
83
- return { x: a.x + r*bd.x, y: a.y + r*bd.y };
84
- }
85
-
86
-
87
- /**
88
- * Calculates the distance between a point and a line
89
- *
90
- * @param {Point}
91
- * @param [ {Point}, {Point} ] line defined through two points
92
- * @return {Float} distance
93
- */
94
- export function getDistancePointLine(point, line) {
95
-
96
- var pfPoint = perpendicularFoot(point, line);
97
-
98
- // distance vector
99
- var connectionVector = {
100
- x: pfPoint.x - point.x,
101
- y: pfPoint.y - point.y
102
- };
103
-
104
- return vectorLength(connectionVector);
105
- }
106
-
107
-
108
- /**
109
- * Calculates the distance between two points
110
- *
111
- * @param {Point}
112
- * @param {Point}
113
- * @return {Float} distance
114
- */
115
- export function getDistancePointPoint(point1, point2) {
116
-
117
- return vectorLength({
118
- x: point1.x - point2.x,
119
- y: point1.y - point2.y
120
- });
121
- }
1
+ export * from 'diagram-js/lib/features/bendpoints/GeometricUtil';
@@ -1,95 +1,7 @@
1
- import {
2
- getDistancePointPoint,
3
- rotateVector,
4
- getAngle
5
- } from './GeometricUtil';
6
-
7
- import {
8
- getAttachment
9
- } from './LineAttachmentUtil';
10
-
11
- import {
12
- roundPoint
13
- } from 'diagram-js/lib/layout/LayoutUtil';
14
-
1
+ import { findNewLineStartIndex, getAnchorPointAdjustment } from './LayoutUtil';
15
2
 
16
3
  export function findNewLabelLineStartIndex(oldWaypoints, newWaypoints, attachment, hints) {
17
-
18
- var index = attachment.segmentIndex;
19
-
20
- var offset = newWaypoints.length - oldWaypoints.length;
21
-
22
- // segmentMove happened
23
- if (hints.segmentMove) {
24
-
25
- var oldSegmentStartIndex = hints.segmentMove.segmentStartIndex,
26
- newSegmentStartIndex = hints.segmentMove.newSegmentStartIndex;
27
-
28
- // if label was on moved segment return new segment index
29
- if (index === oldSegmentStartIndex) {
30
- return newSegmentStartIndex;
31
- }
32
-
33
- // label is after new segment index
34
- if (index >= newSegmentStartIndex) {
35
- return (index+offset < newSegmentStartIndex) ? newSegmentStartIndex : index+offset;
36
- }
37
-
38
- // if label is before new segment index
39
- return index;
40
- }
41
-
42
- // bendpointMove happened
43
- if (hints.bendpointMove) {
44
-
45
- var insert = hints.bendpointMove.insert,
46
- bendpointIndex = hints.bendpointMove.bendpointIndex,
47
- newIndex;
48
-
49
- // waypoints length didnt change
50
- if (offset === 0) {
51
- return index;
52
- }
53
-
54
- // label behind new/removed bendpoint
55
- if (index >= bendpointIndex) {
56
- newIndex = insert ? index + 1 : index - 1;
57
- }
58
-
59
- // label before new/removed bendpoint
60
- if (index < bendpointIndex) {
61
-
62
- newIndex = index;
63
-
64
- // decide label should take right or left segment
65
- if (insert && attachment.type !== 'bendpoint' && bendpointIndex-1 === index) {
66
-
67
- var rel = relativePositionMidWaypoint(newWaypoints, bendpointIndex);
68
-
69
- if (rel < attachment.relativeLocation) {
70
- newIndex++;
71
- }
72
- }
73
- }
74
-
75
- return newIndex;
76
- }
77
-
78
- // start/end changed
79
- if (offset === 0) {
80
- return index;
81
- }
82
-
83
- if (hints.connectionStart) {
84
- return (index === 0) ? 0 : null;
85
- }
86
-
87
- if (hints.connectionEnd) {
88
- return (index === oldWaypoints.length - 2) ? newWaypoints.length - 2 : null;
89
- }
90
-
91
- // if nothing fits, return null
92
- return null;
4
+ return findNewLineStartIndex(oldWaypoints, newWaypoints, attachment, hints);
93
5
  }
94
6
 
95
7
 
@@ -105,118 +17,17 @@ export function findNewLabelLineStartIndex(oldWaypoints, newWaypoints, attachmen
105
17
  * @return {Point} delta
106
18
  */
107
19
  export function getLabelAdjustment(label, newWaypoints, oldWaypoints, hints) {
108
-
109
- var x = 0,
110
- y = 0;
111
-
112
20
  var labelPosition = getLabelMid(label);
113
21
 
114
- // get closest attachment
115
- var attachment = getAttachment(labelPosition, oldWaypoints),
116
- oldLabelLineIndex = attachment.segmentIndex,
117
- newLabelLineIndex = findNewLabelLineStartIndex(oldWaypoints, newWaypoints, attachment, hints);
118
-
119
- if (newLabelLineIndex === null) {
120
- return { x: x, y: y };
121
- }
122
-
123
- // should never happen
124
- // TODO(@janstuemmel): throw an error here when connectionSegmentMove is refactored
125
- if (newLabelLineIndex < 0 ||
126
- newLabelLineIndex > newWaypoints.length - 2) {
127
- return { x: x, y: y };
128
- }
129
-
130
- var oldLabelLine = getLine(oldWaypoints, oldLabelLineIndex),
131
- newLabelLine = getLine(newWaypoints, newLabelLineIndex),
132
- oldFoot = attachment.position;
133
-
134
- var relativeFootPosition = getRelativeFootPosition(oldLabelLine, oldFoot),
135
- angleDelta = getAngleDelta(oldLabelLine, newLabelLine);
136
-
137
- // special rule if label on bendpoint
138
- if (attachment.type === 'bendpoint') {
139
-
140
- var offset = newWaypoints.length - oldWaypoints.length,
141
- oldBendpointIndex = attachment.bendpointIndex,
142
- oldBendpoint = oldWaypoints[oldBendpointIndex];
143
-
144
- // bendpoint position hasn't changed, return same position
145
- if (newWaypoints.indexOf(oldBendpoint) !== -1) {
146
- return { x: x, y: y };
147
- }
148
-
149
- // new bendpoint and old bendpoint have same index, then just return the offset
150
- if (offset === 0) {
151
- var newBendpoint = newWaypoints[oldBendpointIndex];
152
-
153
- return {
154
- x: newBendpoint.x - attachment.position.x,
155
- y: newBendpoint.y - attachment.position.y
156
- };
157
- }
158
-
159
- // if bendpoints get removed
160
- if (offset < 0 && oldBendpointIndex !== 0 && oldBendpointIndex < oldWaypoints.length - 1) {
161
- relativeFootPosition = relativePositionMidWaypoint(oldWaypoints, oldBendpointIndex);
162
- }
163
- }
164
-
165
- var newFoot = {
166
- x: (newLabelLine[1].x - newLabelLine[0].x) * relativeFootPosition + newLabelLine[0].x,
167
- y: (newLabelLine[1].y - newLabelLine[0].y) * relativeFootPosition + newLabelLine[0].y
168
- };
169
-
170
- // the rotated vector to label
171
- var newLabelVector = rotateVector({
172
- x: labelPosition.x - oldFoot.x,
173
- y: labelPosition.y - oldFoot.y
174
- }, angleDelta);
175
-
176
- // the new relative position
177
- x = newFoot.x + newLabelVector.x - labelPosition.x;
178
- y = newFoot.y + newLabelVector.y - labelPosition.y;
179
-
180
- return roundPoint({
181
- x: x,
182
- y: y
183
- });
22
+ return getAnchorPointAdjustment(labelPosition, newWaypoints, oldWaypoints, hints).delta;
184
23
  }
185
24
 
186
25
 
187
26
  // HELPERS //////////////////////
188
27
 
189
- function relativePositionMidWaypoint(waypoints, idx) {
190
-
191
- var distanceSegment1 = getDistancePointPoint(waypoints[idx-1], waypoints[idx]),
192
- distanceSegment2 = getDistancePointPoint(waypoints[idx], waypoints[idx+1]);
193
-
194
- var relativePosition = distanceSegment1 / (distanceSegment1 + distanceSegment2);
195
-
196
- return relativePosition;
197
- }
198
-
199
28
  function getLabelMid(label) {
200
29
  return {
201
30
  x: label.x + label.width / 2,
202
31
  y: label.y + label.height / 2
203
32
  };
204
33
  }
205
-
206
- function getAngleDelta(l1, l2) {
207
- var a1 = getAngle(l1),
208
- a2 = getAngle(l2);
209
- return a2 - a1;
210
- }
211
-
212
- function getLine(waypoints, idx) {
213
- return [ waypoints[idx], waypoints[idx+1] ];
214
- }
215
-
216
- function getRelativeFootPosition(line, foot) {
217
-
218
- var length = getDistancePointPoint(line[0], line[1]),
219
- lengthToFoot = getDistancePointPoint(line[0], foot);
220
-
221
- return length === 0 ? 0 : lengthToFoot / length;
222
- }