Skip to content

Commit 44cceb5

Browse files
committed
fix(adaptive-label-positioning): ignore labels that are being created
Closes #1211
1 parent 168a149 commit 44cceb5

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

lib/features/modeling/behavior/AdaptiveLabelPositioningBehavior.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ export default function AdaptiveLabelPositioningBehavior(eventBus, modeling) {
8484
label = element.label,
8585
labelMid = getMid(label);
8686

87+
// ignore labels that are being created
88+
if (!label.parent) {
89+
return;
90+
}
91+
8792
var elementTrbl = asTRBL(element);
8893

8994
var newLabelMid;
@@ -125,7 +130,6 @@ export default function AdaptiveLabelPositioningBehavior(eventBus, modeling) {
125130
break;
126131
}
127132

128-
129133
var delta = substract(newLabelMid, labelMid);
130134

131135
modeling.moveShape(label, delta);

test/spec/features/modeling/behavior/AdaptiveLabelPositioningBehaviorSpec.js

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ import {
33
inject
44
} from 'test/TestHelper';
55

6-
import {
7-
getOrientation
8-
} from 'diagram-js/lib/layout/LayoutUtil';
6+
import { getOrientation } from 'diagram-js/lib/layout/LayoutUtil';
97

108
import modelingModule from 'lib/features/modeling';
119
import coreModule from 'lib/core';
1210

11+
import {
12+
DEFAULT_LABEL_SIZE,
13+
getExternalLabelMid
14+
} from 'lib/util/LabelUtil';
15+
1316
var testModules = [
1417
modelingModule,
1518
coreModule
@@ -281,6 +284,45 @@ describe('modeling/behavior - AdaptiveLabelPositioningBehavior', function() {
281284
}
282285
));
283286

287+
288+
it('should not adjust position', inject(function(bpmnFactory, elementFactory, elementRegistry, modeling, textRenderer) {
289+
290+
// given
291+
var sequenceFlow = elementRegistry.get('SequenceFlow_1');
292+
293+
var intermediateThrowEvent = elementFactory.createShape({
294+
businessObject: bpmnFactory.create('bpmn:IntermediateThrowEvent', {
295+
name: 'Foo'
296+
}),
297+
type: 'bpmn:IntermediateThrowEvent',
298+
x: 0,
299+
y: 0
300+
});
301+
302+
var externalLabelMid = getExternalLabelMid(intermediateThrowEvent);
303+
304+
var externalLabelBounds = textRenderer.getExternalLabelBounds(DEFAULT_LABEL_SIZE, 'Foo');
305+
306+
var label = elementFactory.createLabel({
307+
labelTarget: intermediateThrowEvent,
308+
x: externalLabelMid.x - externalLabelBounds.width / 2,
309+
y: externalLabelMid.y - externalLabelBounds.height / 2,
310+
width: externalLabelBounds.width,
311+
height: externalLabelBounds.height
312+
});
313+
314+
var sequenceFlowMid = getConnectionMid(sequenceFlow.waypoints[0], sequenceFlow.waypoints[1]);
315+
316+
// when
317+
modeling.createElements([ intermediateThrowEvent, label ], sequenceFlowMid, sequenceFlow);
318+
319+
// then
320+
expect(label.x).to.be.closeTo(325, 1);
321+
expect(label.y).to.be.closeTo(335, 1);
322+
expect(label.width).to.be.closeTo(19, 1);
323+
expect(label.height).to.be.closeTo(14, 1);
324+
}));
325+
284326
});
285327

286328
});
@@ -407,3 +449,12 @@ describe('modeling/behavior - AdaptiveLabelPositioningBehavior', function() {
407449
});
408450

409451
});
452+
453+
// helpers //////////
454+
455+
function getConnectionMid(a, b) {
456+
return {
457+
x: (a.x + b.x) / 2,
458+
y: (a.y + b.y) / 2
459+
};
460+
}

0 commit comments

Comments
 (0)