Skip to content

Commit

Permalink
fix(adaptive-label-positioning): ignore labels that are being created
Browse files Browse the repository at this point in the history
Closes #1211
  • Loading branch information
philippfromme authored and fake-join[bot] committed Oct 11, 2019
1 parent 13d89a7 commit 7754a7e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ export default function AdaptiveLabelPositioningBehavior(eventBus, modeling) {
label = element.label,
labelMid = getMid(label);

// ignore labels that are being created
if (!label.parent) {
return;
}

var elementTrbl = asTRBL(element);

var newLabelMid;
Expand Down Expand Up @@ -125,7 +130,6 @@ export default function AdaptiveLabelPositioningBehavior(eventBus, modeling) {
break;
}


var delta = substract(newLabelMid, labelMid);

modeling.moveShape(label, delta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import {
inject
} from 'test/TestHelper';

import {
getOrientation
} from 'diagram-js/lib/layout/LayoutUtil';
import { getOrientation } from 'diagram-js/lib/layout/LayoutUtil';

import modelingModule from 'lib/features/modeling';
import coreModule from 'lib/core';

import {
DEFAULT_LABEL_SIZE,
getExternalLabelMid
} from 'lib/util/LabelUtil';

var testModules = [
modelingModule,
coreModule
Expand Down Expand Up @@ -281,6 +284,45 @@ describe('modeling/behavior - AdaptiveLabelPositioningBehavior', function() {
}
));


it('should not adjust position', inject(function(bpmnFactory, elementFactory, elementRegistry, modeling, textRenderer) {

// given
var sequenceFlow = elementRegistry.get('SequenceFlow_1');

var intermediateThrowEvent = elementFactory.createShape({
businessObject: bpmnFactory.create('bpmn:IntermediateThrowEvent', {
name: 'Foo'
}),
type: 'bpmn:IntermediateThrowEvent',
x: 0,
y: 0
});

var externalLabelMid = getExternalLabelMid(intermediateThrowEvent);

var externalLabelBounds = textRenderer.getExternalLabelBounds(DEFAULT_LABEL_SIZE, 'Foo');

var label = elementFactory.createLabel({
labelTarget: intermediateThrowEvent,
x: externalLabelMid.x - externalLabelBounds.width / 2,
y: externalLabelMid.y - externalLabelBounds.height / 2,
width: externalLabelBounds.width,
height: externalLabelBounds.height
});

var sequenceFlowMid = getConnectionMid(sequenceFlow.waypoints[0], sequenceFlow.waypoints[1]);

// when
modeling.createElements([ intermediateThrowEvent, label ], sequenceFlowMid, sequenceFlow);

// then
expect(label.x).to.be.closeTo(325, 1);
expect(label.y).to.be.closeTo(335, 1);
expect(label.width).to.be.closeTo(19, 1);
expect(label.height).to.be.closeTo(14, 1);
}));

});

});
Expand Down Expand Up @@ -407,3 +449,12 @@ describe('modeling/behavior - AdaptiveLabelPositioningBehavior', function() {
});

});

// helpers //////////

function getConnectionMid(a, b) {
return {
x: (a.x + b.x) / 2,
y: (a.y + b.y) / 2
};
}

0 comments on commit 7754a7e

Please sign in to comment.