fix(label-behavior): do not move labels if labelBehavior=false

This commit is contained in:
Philipp Fromme 2020-01-20 11:13:05 +01:00 committed by Nico Rehwaldt
parent 7ee304f424
commit 50630c7aac
3 changed files with 70 additions and 2 deletions

View File

@ -209,8 +209,15 @@ export default function LabelBehavior(
'connection.layout',
'connection.updateWaypoints'
], function(event) {
var context = event.context,
hints = context.hints || {};
var label = event.context.connection.label,
if (hints.labelBehavior === false) {
return;
}
var connection = context.connection,
label = connection.label,
labelAdjustment;
// handle missing label as well as the case

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.2.0-dev">
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.5.0">
<bpmn:category id="Category_1">
<bpmn:categoryValue id="CategoryValue_1" value="Value" />
</bpmn:category>
@ -7,6 +7,13 @@
<bpmn:startEvent id="StartEvent_1" name="foo" />
<bpmn:task id="Task_1" />
<bpmn:exclusiveGateway id="ExclusiveGateway_1" />
<bpmn:startEvent id="StartEvent_2">
<bpmn:outgoing>SequenceFlow_1</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:endEvent id="EndEvent_1">
<bpmn:incoming>SequenceFlow_1</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_1" name="SequenceFlow_1" sourceRef="StartEvent_2" targetRef="EndEvent_1" />
<bpmn:textAnnotation id="TextAnnotation_1">
<bpmn:text>foo</bpmn:text>
</bpmn:textAnnotation>
@ -68,6 +75,19 @@
<dc:Bounds x="403" y="583" width="28" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="StartEvent_0c95td1_di" bpmnElement="StartEvent_2">
<dc:Bounds x="564" y="582" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="EndEvent_0r7j2ed_di" bpmnElement="EndEvent_1">
<dc:Bounds x="700" y="582" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_0pgg94c_di" bpmnElement="SequenceFlow_1">
<di:waypoint x="600" y="600" />
<di:waypoint x="700" y="600" />
<bpmndi:BPMNLabel>
<dc:Bounds x="608" y="582" width="85" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -13,6 +13,8 @@ import {
} from 'lib/util/LabelUtil';
import {
assign,
map,
pick
} from 'min-dash';
@ -412,6 +414,28 @@ describe('behavior - LabelBehavior', function() {
}
));
it('should NOT move label if labelBehavior=false', inject(function(elementRegistry, modeling) {
// given
var connection = elementRegistry.get('SequenceFlow_1'),
waypoints = copyWaypoints(connection),
label = connection.label,
oldLabelPosition = pick(label, [ 'x', 'y' ]);
var newWaypoints = [
waypoints[ 0 ],
{ x: 0, y: 0 },
waypoints[ 1 ]
];
// when
modeling.updateWaypoints(connection, newWaypoints, { labelBehavior: false });
// then
expect(pick(label, [ 'x', 'y' ])).to.eql(oldLabelPosition);
}));
});
});
@ -772,6 +796,23 @@ describe('behavior - LabelBehavior', function() {
// helpers //////////
function copyWaypoint(waypoint) {
return assign({}, waypoint);
}
function copyWaypoints(connection) {
return map(connection.waypoints, function(waypoint) {
waypoint = copyWaypoint(waypoint);
if (waypoint.original) {
waypoint.original = copyWaypoint(waypoint.original);
}
return waypoint;
});
}
function getBounds(element) {
return pick(element, [ 'x', 'y', 'width', 'height' ]);
}