fix(modeling): adjust position of hidden label on waypoints change

closes bpmn-io/diagram-js#158
This commit is contained in:
Philipp Fromme 2016-04-19 17:12:48 +02:00 committed by Ricardo Matias
parent 690881491d
commit 7de043ab9d
2 changed files with 96 additions and 0 deletions

View File

@ -46,6 +46,28 @@ function LabelSupport(eventBus, modeling, bpmnFactory) {
}
});
// update label position on waypoints change if still hidden
this.postExecute([ 'connection.updateWaypoints' ], function(e) {
var context = e.context,
connection = context.connection,
label = connection.label;
if (!label) {
return;
}
if (label.hidden) {
var position = getExternalLabelMid(connection);
var delta = {
x: position.x - label.x - label.width / 2,
y: position.y - label.y - label.height / 2
};
modeling.moveShape(label, delta);
}
});
// update di information on label creation
this.executed([ 'label.create' ], function(e) {

View File

@ -138,6 +138,80 @@ describe('behavior - LabelBehavior', function() {
expect(startEvent.di.label).to.have.position({ x: 156, y: 128 });
}));
it('should move connection label on waypoints update if still hidden', inject(function(elementRegistry, modeling) {
// given
var startEventShape = elementRegistry.get('StartEvent_1'),
taskShape = elementRegistry.get('Task_1');
var sequenceFlowConnection = modeling.createConnection(startEventShape, taskShape, {
type: 'bpmn:SequenceFlow',
}, startEventShape.parent);
// when
modeling.updateWaypoints(sequenceFlowConnection, [
sequenceFlowConnection.waypoints[0],
{
x: sequenceFlowConnection.waypoints[0].x,
y: 200
},
{
x: sequenceFlowConnection.waypoints[1].x,
y: 200
},
sequenceFlowConnection.waypoints[1]
]);
// then
var expected = {
x: LabelUtil.getExternalLabelMid(sequenceFlowConnection).x - sequenceFlowConnection.label.width / 2,
y: LabelUtil.getExternalLabelMid(sequenceFlowConnection).y - sequenceFlowConnection.label.height / 2
};
expect({
x: sequenceFlowConnection.label.x,
y: sequenceFlowConnection.label.y
}).to.eql(expected);
}));
it('should not move connection label on waypoints change if not hidden', inject(function(elementRegistry, modeling) {
// given
var startEventShape = elementRegistry.get('StartEvent_1'),
taskShape = elementRegistry.get('Task_1');
var sequenceFlowConnection = modeling.createConnection(startEventShape, taskShape, {
type: 'bpmn:SequenceFlow',
}, startEventShape.parent);
var labelPosition = {
x: sequenceFlowConnection.label.x,
y: sequenceFlowConnection.label.y
};
// when
sequenceFlowConnection.label.hidden = false;
modeling.updateWaypoints(sequenceFlowConnection, [
sequenceFlowConnection.waypoints[0],
{
x: sequenceFlowConnection.waypoints[0].x,
y: 200
},
{
x: sequenceFlowConnection.waypoints[1].x,
y: 200
},
sequenceFlowConnection.waypoints[1]
]);
// then
expect({
x: sequenceFlowConnection.label.x,
y: sequenceFlowConnection.label.y
}).to.eql(labelPosition);
}));
});