diff --git a/lib/features/snapping/BpmnSnapping.js b/lib/features/snapping/BpmnSnapping.js index 9e1a3e93..d13fb50a 100644 --- a/lib/features/snapping/BpmnSnapping.js +++ b/lib/features/snapping/BpmnSnapping.js @@ -5,6 +5,7 @@ var inherits = require('inherits'); var forEach = require('lodash/collection/forEach'); var getBoundingBox = require('diagram-js/lib/util/Elements').getBBox; +var is = require('../modeling/ModelingUtil').is; var Snapping = require('diagram-js/lib/features/snapping/Snapping'), SnapUtil = require('diagram-js/lib/features/snapping/SnapUtil'); @@ -119,6 +120,24 @@ function BpmnSnapping(eventBus, canvas) { 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); diff --git a/test/fixtures/bpmn/collaboration-resize.bpmn b/test/fixtures/bpmn/collaboration-resize.bpmn new file mode 100644 index 00000000..637faff0 --- /dev/null +++ b/test/fixtures/bpmn/collaboration-resize.bpmn @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/spec/features/snapping/BpmnSnappingSpec.js b/test/spec/features/snapping/BpmnSnappingSpec.js index 7f70cacc..fc2c604f 100644 --- a/test/spec/features/snapping/BpmnSnappingSpec.js +++ b/test/spec/features/snapping/BpmnSnappingSpec.js @@ -10,6 +10,7 @@ var coreModule = require('../../../../lib/core'), snappingModule = require('../../../../lib/features/snapping'), modelingModule = require('../../../../lib/features/modeling'), createModule = require('diagram-js/lib/features/create'), + resizeModule = require('diagram-js/lib/features/resize'), rulesModule = require('../../../../lib/features/modeling/rules'); 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); + })); + + }); + }); \ No newline at end of file