fix(snapping): boundary event labels snap to siblings

Closes #327
This commit is contained in:
pedesen 2015-09-07 15:07:09 +02:00
parent 31f0ea1ec0
commit 536eb790a0
3 changed files with 106 additions and 3 deletions

View File

@ -215,7 +215,7 @@ BpmnSnapping.prototype.initSnap = function(event) {
BpmnSnapping.prototype.addTargetSnaps = function(snapPoints, shape, target) {
// use target parent as snap target
if (is(shape, 'bpmn:BoundaryEvent')) {
if (is(shape, 'bpmn:BoundaryEvent') && shape.type !== 'label') {
target = target.parent;
}
@ -385,4 +385,4 @@ function computeParticipantMinBounds(element) {
if (childrenBoxes.length) {
return getBBox(childrenBoxes);
}
}
}

View File

@ -0,0 +1,27 @@
<?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:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn">
<bpmn:process id="Process_1" isExecutable="false">
<bpmn:task id="Task_1" />
<bpmn:boundaryEvent id="BoundaryEvent_1" name="Label" attachedToRef="Task_1" />
<bpmn:startEvent id="StartEvent_1" name="Label" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="Task_1_di" bpmnElement="Task_1">
<dc:Bounds x="156" y="70" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BoundaryEvent_1_di" bpmnElement="BoundaryEvent_1">
<dc:Bounds x="218" y="132" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="191" y="180" width="90" height="20" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="StartEvent_1_di" bpmnElement="StartEvent_1">
<dc:Bounds x="319" y="92" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="292" y="135" width="90" height="20" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -14,7 +14,6 @@ var coreModule = require('../../../../lib/core'),
moveModule = require('diagram-js/lib/features/move'),
rulesModule = require('../../../../lib/features/rules');
describe('features/snapping - BpmnSnapping', function() {
var testModules = [ coreModule, snappingModule, modelingModule, createModule, rulesModule, moveModule ];
@ -401,4 +400,81 @@ describe('features/snapping - BpmnSnapping', function() {
});
describe('labels', function() {
var diagramXML = require('./BpmnSnapping.labels.bpmn');
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
it('should snap to start events', inject(function(canvas, elementRegistry, move, dragging) {
var label = elementRegistry.get('StartEvent_1_label'),
rootElement = canvas.getRootElement();
var originalPosition = { x: label.x, y: label.y };
move.start(canvasEvent({ x: label.x+2, y: label.y+2 }), label);
dragging.hover({
element: rootElement,
gfx: elementRegistry.getGraphics(rootElement)
});
dragging.move(canvasEvent({ x: label.x+4, y: label.y+40 }));
dragging.move(canvasEvent({ x: label.x+4, y: label.y+40 }));
dragging.end();
expect(label.x).to.equal(originalPosition.x);
}));
it('should snap to boundary events', inject(function(canvas, elementRegistry, move, dragging) {
var label = elementRegistry.get('BoundaryEvent_1_label'),
rootElement = canvas.getRootElement();
var originalPosition = { x: label.x, y: label.y };
move.start(canvasEvent({ x: label.x+2, y: label.y+2 }), label);
dragging.hover({
element: rootElement,
gfx: elementRegistry.getGraphics(rootElement)
});
dragging.move(canvasEvent({ x: label.x+4, y: label.y+40 }));
dragging.move(canvasEvent({ x: label.x+4, y: label.y+40 }));
dragging.end();
expect(label.x).to.equal(originalPosition.x);
}));
it('should snap to siblings', inject(function(canvas, elementRegistry, move, dragging) {
var label = elementRegistry.get('BoundaryEvent_1_label'),
rootElement = canvas.getRootElement();
move.start(canvasEvent({ x: label.x+2, y: label.y+2 }), label);
dragging.hover({
element: rootElement,
gfx: elementRegistry.getGraphics(rootElement)
});
dragging.move(canvasEvent({ x: label.x-23, y: label.y+40 }));
dragging.move(canvasEvent({ x: label.x-23, y: label.y+40 }));
dragging.end();
expect(label.x).to.equal(161);
}));
});
});