feat(resize): snap to minimum bounds during resize

closes #252
This commit is contained in:
Ricardo Matias 2015-04-28 13:24:55 +02:00 committed by Nico Rehwaldt
parent 6f8999b8ae
commit 6fc512b477
3 changed files with 107 additions and 0 deletions

View File

@ -5,6 +5,7 @@ var inherits = require('inherits');
var forEach = require('lodash/collection/forEach'); var forEach = require('lodash/collection/forEach');
var getBoundingBox = require('diagram-js/lib/util/Elements').getBBox; var getBoundingBox = require('diagram-js/lib/util/Elements').getBBox;
var is = require('../modeling/ModelingUtil').is;
var Snapping = require('diagram-js/lib/features/snapping/Snapping'), var Snapping = require('diagram-js/lib/features/snapping/Snapping'),
SnapUtil = require('diagram-js/lib/features/snapping/SnapUtil'); SnapUtil = require('diagram-js/lib/features/snapping/SnapUtil');
@ -119,6 +120,24 @@ function BpmnSnapping(eventBus, canvas) {
snapParticipant(participantSnapBox, shape, event); snapParticipant(participantSnapBox, shape, event);
} }
}); });
eventBus.on('resize.start', 1500, function(event) {
var context = event.context,
shape = context.shape;
if (is(shape, 'bpmn:SubProcess')) {
context.minDimensions = { width: 140, height: 120 };
}
if (is(shape, 'bpmn:Participant')) {
context.minDimensions = { width: 400, height: 200 };
}
if (is(shape, 'bpmn:TextAnnotation')) {
context.minDimensions = { width: 50, height: 50 };
}
});
} }
inherits(BpmnSnapping, Snapping); inherits(BpmnSnapping, Snapping);

View File

@ -0,0 +1,33 @@
<?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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn">
<bpmn:collaboration id="Collaboration_1">
<bpmn:participant id="Participant_1" processRef="Process_1" />
<bpmn:participant id="Participant_2" processRef="Process_2" />
</bpmn:collaboration>
<bpmn:process id="Process_1" isExecutable="false" />
<bpmn:process id="Process_2">
<bpmn:subProcess id="SubProcess_1" />
<bpmn:textAnnotation id="TextAnnotation_1" />
<bpmn:association id="Association_1" sourceRef="SubProcess_1" targetRef="TextAnnotation_1" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_1">
<bpmndi:BPMNShape id="Participant_1_di" bpmnElement="Participant_1">
<dc:Bounds x="14" y="10" width="600" height="300" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Participant_2_di" bpmnElement="Participant_2">
<dc:Bounds x="14" y="341" width="603" height="332" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="SubProcess_1_di" bpmnElement="SubProcess_1" isExpanded="true">
<dc:Bounds x="103" y="424" width="350" height="200" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="TextAnnotation_1_di" bpmnElement="TextAnnotation_1">
<dc:Bounds x="492" y="372" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Association_1_di" bpmnElement="Association_1">
<di:waypoint xsi:type="dc:Point" x="453" y="465" />
<di:waypoint xsi:type="dc:Point" x="492" y="429" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -10,6 +10,7 @@ var coreModule = require('../../../../lib/core'),
snappingModule = require('../../../../lib/features/snapping'), snappingModule = require('../../../../lib/features/snapping'),
modelingModule = require('../../../../lib/features/modeling'), modelingModule = require('../../../../lib/features/modeling'),
createModule = require('diagram-js/lib/features/create'), createModule = require('diagram-js/lib/features/create'),
resizeModule = require('diagram-js/lib/features/resize'),
rulesModule = require('../../../../lib/features/modeling/rules'); rulesModule = require('../../../../lib/features/modeling/rules');
var pick = require('lodash/object/pick'); var pick = require('lodash/object/pick');
@ -165,4 +166,58 @@ describe('features/snapping - BpmnSnapping', function() {
}); });
describe('on shape resize', function () {
var diagramXML = require('../../../fixtures/bpmn/collaboration-resize.bpmn');
var testResizeModules = [ coreModule, resizeModule, rulesModule, snappingModule ];
beforeEach(bootstrapModeler(diagramXML, { modules: testResizeModules }));
var createEvent;
beforeEach(inject(function(canvas, dragging) {
createEvent = Events.scopedCreate(canvas);
}));
it('should snap a SubProcess to minimum bounds', inject(function(canvas, elementRegistry, resize, dragging) {
var subProcess = elementRegistry.get('SubProcess_1');
resize.activate(Events.create(canvas._svg, { x: 453, y: 624 }), subProcess, 'se');
dragging.move(Events.create(canvas._svg, { x: -453, y: -624 }));
dragging.end();
expect(subProcess.width).toEqual(140);
expect(subProcess.height).toEqual(120);
}));
it('should snap a Participant to minimum bounds', inject(function(canvas, elementRegistry, resize, dragging) {
var participant = elementRegistry.get('Participant_1');
resize.activate(Events.create(canvas._svg, { x: 614, y: 310 }), participant, 'se');
dragging.move(Events.create(canvas._svg, { x: -614, y: -310 }));
dragging.end();
expect(participant.width).toEqual(400);
expect(participant.height).toEqual(200);
}));
it('should snap a TextAnnotation to minimum bounds', inject(function(canvas, elementRegistry, resize, dragging) {
var textAnnotation = elementRegistry.get('TextAnnotation_1');
resize.activate(Events.create(canvas._svg, { x: 592, y: 452 }), textAnnotation, 'se');
dragging.move(Events.create(canvas._svg, { x: -592, y: -452 }));
dragging.end();
expect(textAnnotation.width).toEqual(50);
expect(textAnnotation.height).toEqual(50);
}));
});
}); });