mirror of
https://github.com/sartography/bpmn-js.git
synced 2025-01-11 17:44:12 +00:00
parent
eaddbb31c4
commit
8cc530bf58
@ -10,6 +10,8 @@ var hasExternalLabel = LabelUtil.hasExternalLabel,
|
||||
|
||||
function LabelSupport(eventBus, modeling, bpmnFactory) {
|
||||
|
||||
// create external labels on shape creation
|
||||
|
||||
eventBus.on([
|
||||
'commandStack.shape.create.postExecute',
|
||||
'commandStack.connection.create.postExecute'
|
||||
@ -30,15 +32,52 @@ function LabelSupport(eventBus, modeling, bpmnFactory) {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// indicate label is dragged during move
|
||||
|
||||
eventBus.on('shape.move.start', 50000, function(e) {
|
||||
|
||||
var dragContext = e.dragContext,
|
||||
element = dragContext.element;
|
||||
|
||||
var label = element.label;
|
||||
|
||||
if (label && dragContext.shapes.indexOf(label) === -1) {
|
||||
dragContext.shapes.push(label);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// move labels with shapes
|
||||
|
||||
eventBus.on([
|
||||
'commandStack.shape.move.postExecute'
|
||||
], function(e) {
|
||||
var context = e.context,
|
||||
shape = context.shape;
|
||||
|
||||
if (shape.label && context.hints.layout !== false) {
|
||||
modeling.moveShape(shape.label, context.delta);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// update di information on label movement and creation
|
||||
|
||||
eventBus.on([
|
||||
'commandStack.label.create.executed',
|
||||
'commandStack.label.moved.executed'
|
||||
'commandStack.shape.moved.executed'
|
||||
], function(e) {
|
||||
|
||||
var element = e.context.shape,
|
||||
businessObject = element.businessObject,
|
||||
di = businessObject.di;
|
||||
|
||||
// we want to trigger on real labels only
|
||||
if (!element.labelTarget) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!di.label) {
|
||||
di.label = bpmnFactory.create('bpmndi:BPMNLabel', {
|
||||
bounds: bpmnFactory.create('dc:Bounds')
|
||||
|
@ -84,6 +84,28 @@ describe('features/modeling - move shape', function() {
|
||||
expect(startEvent.di.label.bounds.y).toBe(oldPosition.y + 50);
|
||||
}));
|
||||
|
||||
|
||||
it('should move label with element', inject(function(elementRegistry, modeling) {
|
||||
|
||||
// given
|
||||
var startEventElement = elementRegistry.getById('StartEvent_1'),
|
||||
startEvent = startEventElement.businessObject;
|
||||
|
||||
var label = startEventElement.label;
|
||||
|
||||
var labelPosition = {
|
||||
x: label.x,
|
||||
y: label.y
|
||||
};
|
||||
|
||||
// when
|
||||
modeling.moveShape(startEventElement, { x: 40, y: -80 });
|
||||
|
||||
// then
|
||||
expect(label.x).toBe(labelPosition.x + 40);
|
||||
expect(label.y).toBe(labelPosition.y - 80);
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user