fix(auto-place): fix infinite loop during auto-place

* NaN was returned when autoplacing an element after
  a boundary event, attached to its hosts corner.

Closes #788
This commit is contained in:
Nicolas Boissel-Dallier 2018-05-03 17:29:23 +02:00 committed by Nico Rehwaldt
parent 327eb90140
commit 9379abafcc
3 changed files with 24 additions and 9 deletions

View File

@ -37,21 +37,24 @@ export function getFlowNodePosition(source, element) {
if (is(source, 'bpmn:BoundaryEvent')) { if (is(source, 'bpmn:BoundaryEvent')) {
orientation = getOrientation(source, source.host, -25); orientation = getOrientation(source, source.host, -25);
if (orientation === 'top') { if (orientation.indexOf('top') !== -1) {
margin *= -1; margin *= -1;
} }
} }
var verticalDistances = { function getVerticalDistance(orient) {
left: 0, if (orient.indexOf('top') != -1) {
right: 0, return -1 * rowSize;
top: -1 * rowSize, } else if (orient.indexOf('bottom') != -1) {
bottom: rowSize return rowSize;
}; } else {
return 0;
}
}
var position = { var position = {
x: sourceTrbl.right + horizontalDistance + element.width / 2, x: sourceTrbl.right + horizontalDistance + element.width / 2,
y: sourceMid.y + verticalDistances[orientation] y: sourceMid.y + getVerticalDistance(orientation)
}; };
var escapeDirection = { var escapeDirection = {

View File

@ -11,6 +11,7 @@
<sequenceFlow id="SequenceFlow_0o6gp3o" sourceRef="TASK_1" targetRef="TASK_2" /> <sequenceFlow id="SequenceFlow_0o6gp3o" sourceRef="TASK_1" targetRef="TASK_2" />
<task id="TASK_3" name="TASK_3" /> <task id="TASK_3" name="TASK_3" />
<boundaryEvent id="BOUNDARY_TOP" name="BOUNDARY_TOP" attachedToRef="TASK_1" /> <boundaryEvent id="BOUNDARY_TOP" name="BOUNDARY_TOP" attachedToRef="TASK_1" />
<boundaryEvent id="BOUNDARY_TOP_RIGHT" name="BOUNDARY_TOP_RIGHT" attachedToRef="TASK_2" />
<subProcess id="SUBPROCESS" name="SUBPROCESS" /> <subProcess id="SUBPROCESS" name="SUBPROCESS" />
<boundaryEvent id="BOUNDARY_SUBPROCESS_BOTTOM" name="BOUNDARY_SUBPROCESS_BOTTOM" attachedToRef="SUBPROCESS" /> <boundaryEvent id="BOUNDARY_SUBPROCESS_BOTTOM" name="BOUNDARY_SUBPROCESS_BOTTOM" attachedToRef="SUBPROCESS" />
<boundaryEvent id="BOUNDARY_SUBPROCESS_TOP" name="BOUNDARY_SUBPROCESS_TOP" attachedToRef="SUBPROCESS" /> <boundaryEvent id="BOUNDARY_SUBPROCESS_TOP" name="BOUNDARY_SUBPROCESS_TOP" attachedToRef="SUBPROCESS" />
@ -29,7 +30,7 @@
<bpmndi:BPMNShape id="TASK_2_di" bpmnElement="TASK_2"> <bpmndi:BPMNShape id="TASK_2_di" bpmnElement="TASK_2">
<omgdc:Bounds x="305" y="93" width="100" height="80" /> <omgdc:Bounds x="305" y="93" width="100" height="80" />
</bpmndi:BPMNShape> </bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_0o6gp3o_di" bpmnElement="TASK_1"> <bpmndi:BPMNEdge id="SequenceFlow_0o6gp3o_di" bpmnElement="SequenceFlow_0o6gp3o">
<omgdi:waypoint xsi:type="omgdc:Point" x="221" y="133" /> <omgdi:waypoint xsi:type="omgdc:Point" x="221" y="133" />
<omgdi:waypoint xsi:type="omgdc:Point" x="305" y="133" /> <omgdi:waypoint xsi:type="omgdc:Point" x="305" y="133" />
<bpmndi:BPMNLabel> <bpmndi:BPMNLabel>
@ -45,6 +46,12 @@
<omgdc:Bounds x="78" y="52" width="86" height="24" /> <omgdc:Bounds x="78" y="52" width="86" height="24" />
</bpmndi:BPMNLabel> </bpmndi:BPMNLabel>
</bpmndi:BPMNShape> </bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BOUNDARY_TOP_RIGHT_di" bpmnElement="BOUNDARY_TOP_RIGHT">
<omgdc:Bounds x="387" y="75" width="36" height="36" />
<bpmndi:BPMNLabel>
<omgdc:Bounds x="363" y="44" width="84" height="24" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="SUBPROCESS_di" bpmnElement="SUBPROCESS" isExpanded="true"> <bpmndi:BPMNShape id="SUBPROCESS_di" bpmnElement="SUBPROCESS" isExpanded="true">
<omgdc:Bounds x="142" y="314" width="258" height="141" /> <omgdc:Bounds x="142" y="314" width="258" height="141" />
</bpmndi:BPMNShape> </bpmndi:BPMNShape>

View File

@ -216,6 +216,11 @@ describe('features/auto-place', function() {
expectedBounds: { x: 242, y: -27, width: 100, height: 80 } expectedBounds: { x: 242, y: -27, width: 100, height: 80 }
})); }));
it('should place top right of BOUNDARY_TOP_RIGHT without infinite loop', autoPlace({
element: 'bpmn:Task',
behind: 'BOUNDARY_TOP_RIGHT',
expectedBounds: { x: 473, y: -27, width: 100, height: 80 }
}));
it('should place top right of BOUNDARY_SUBPROCESS_TOP', autoPlace({ it('should place top right of BOUNDARY_SUBPROCESS_TOP', autoPlace({
element: 'bpmn:Task', element: 'bpmn:Task',