From fa2e47236186cad0737d212544f9bb2726f3377d Mon Sep 17 00:00:00 2001 From: Philipp Fromme Date: Thu, 18 Apr 2019 13:25:53 +0200 Subject: [PATCH] feat(grid-snapping): integrate auto resize Related to camunda/camunda-modeler#1344 Related to camunda/camunda-modeler#1349 --- lib/features/auto-resize/BpmnAutoResize.js | 6 +- .../ToggleElementCollapseBehaviour.js | 4 +- .../grid-snapping/BpmnGridSnapping.bpmn | 38 +++++- .../grid-snapping/BpmnGridSnappingSpec.js | 122 +++++++++++++++++- 4 files changed, 163 insertions(+), 7 deletions(-) diff --git a/lib/features/auto-resize/BpmnAutoResize.js b/lib/features/auto-resize/BpmnAutoResize.js index 78705ffe..569d8b3e 100644 --- a/lib/features/auto-resize/BpmnAutoResize.js +++ b/lib/features/auto-resize/BpmnAutoResize.js @@ -27,11 +27,11 @@ inherits(BpmnAutoResize, AutoResize); * @param {djs.model.Shape} target * @param {Object} newBounds */ -BpmnAutoResize.prototype.resize = function(target, newBounds) { +BpmnAutoResize.prototype.resize = function(target, newBounds, hints) { if (is(target, 'bpmn:Participant')) { - this._modeling.resizeLane(target, newBounds); + this._modeling.resizeLane(target, newBounds, null, hints); } else { - this._modeling.resizeShape(target, newBounds); + this._modeling.resizeShape(target, newBounds, null, hints); } }; \ No newline at end of file diff --git a/lib/features/modeling/behavior/ToggleElementCollapseBehaviour.js b/lib/features/modeling/behavior/ToggleElementCollapseBehaviour.js index 7e4becd1..b1e67a3a 100644 --- a/lib/features/modeling/behavior/ToggleElementCollapseBehaviour.js +++ b/lib/features/modeling/behavior/ToggleElementCollapseBehaviour.js @@ -119,7 +119,9 @@ export default function ToggleElementCollapseBehaviour( newBounds = expandedBounds(shape, defaultSize); } - modeling.resizeShape(shape, newBounds); + modeling.resizeShape(shape, newBounds, null, { + autoResize: shape.collapsed ? false : 'nwse' + }); }); } diff --git a/test/spec/features/grid-snapping/BpmnGridSnapping.bpmn b/test/spec/features/grid-snapping/BpmnGridSnapping.bpmn index 21c0e224..0975c337 100644 --- a/test/spec/features/grid-snapping/BpmnGridSnapping.bpmn +++ b/test/spec/features/grid-snapping/BpmnGridSnapping.bpmn @@ -8,7 +8,20 @@ - + + + SequenceFlow_0e7hjjz + SequenceFlow_0jhtpzs + + + SequenceFlow_0e7hjjz + + + SequenceFlow_0jhtpzs + + + + @@ -25,6 +38,29 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/spec/features/grid-snapping/BpmnGridSnappingSpec.js b/test/spec/features/grid-snapping/BpmnGridSnappingSpec.js index 89c816eb..ea9ca7d3 100644 --- a/test/spec/features/grid-snapping/BpmnGridSnappingSpec.js +++ b/test/spec/features/grid-snapping/BpmnGridSnappingSpec.js @@ -13,7 +13,13 @@ import { createCanvasEvent as canvasEvent } from '../../../util/MockEvents'; -import { isString } from 'min-dash'; +import { getMid } from 'diagram-js/lib/layout/LayoutUtil'; + +import { + isString, + pick, + assign +} from 'min-dash'; var LOW_PRIORITY = 500; @@ -43,7 +49,7 @@ describe('features/grid-snapping', function() { })); - describe('snap top-left', function() { + describe('snap top-left on move', function() { it('participant', inject(function(dragging, eventBus, move) { @@ -151,6 +157,114 @@ describe('features/grid-snapping', function() { }); + + describe('auto resize on toggle collapse', function() { + + describe('collapsing', function() { + + it('participant (no auto resize)', inject(function(bpmnReplace) { + + // given + var bounds = assign( + getBounds(participant), + { height: 100 } + ); + + // when + var collapsedParticipant = bpmnReplace.replaceElement(participant, + { + type: 'bpmn:Participant', + isExpanded: false + } + ); + + // then + expect(getBounds(collapsedParticipant)).to.eql(bounds); + })); + + + it('sub process (no auto resize)', inject(function(bpmnReplace) { + + // given + var mid = getMid(subProcess); + + // when + var collapsedSubProcess = bpmnReplace.replaceElement(subProcess, + { + type: 'bpmn:SubProcess', + isExpanded: false + } + ); + + // then + expect(getMid(collapsedSubProcess)).to.eql(mid); + expect(collapsedSubProcess).to.include({ + width: 100, + height: 80 + }); + })); + + }); + + + describe('expanding', function() { + + it('participant (auto resize )', inject(function(bpmnReplace) { + + // given + var bounds = getBounds(participant); + + var collapsedParticipant = bpmnReplace.replaceElement(participant, + { + type: 'bpmn:Participant', + isExpanded: false + } + ); + + // when + var expandedParticipant = bpmnReplace.replaceElement(collapsedParticipant, + { + type: 'bpmn:Participant', + isExpanded: true + } + ); + + // then + expect(getBounds(expandedParticipant)).to.eql(bounds); + })); + + + it('sub process (auto resize )', inject(function(bpmnReplace) { + + // given + var collapsedSubProcess = bpmnReplace.replaceElement(subProcess, + { + type: 'bpmn:SubProcess', + isExpanded: false + } + ); + + // when + var expandedSubProcess = bpmnReplace.replaceElement(collapsedSubProcess, + { + type: 'bpmn:SubProcess', + isExpanded: true + } + ); + + // then + expect(expandedSubProcess).to.include({ + x: 140, + y: 120, + width: 360, + height: 210 + }); + })); + + }); + + }); + }); // helpers ////////// @@ -214,4 +328,8 @@ function position(event) { x: event.x, y: event.y }; +} + +function getBounds(shape) { + return pick(shape, [ 'x', 'y', 'width', 'height' ]); } \ No newline at end of file