Skip to content

Commit

Permalink
feat(space-tool): ensure minimum size when resizing shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme authored and nikku committed Feb 6, 2020
1 parent 035bb0c commit 7ee304f
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/features/modeling/behavior/ResizeBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import { getParticipantResizeConstraints } from './util/ResizeUtil';

var HIGH_PRIORITY = 1500;

var PARTICIPANT_MIN_DIMENSIONS = { width: 300, height: 150 },
SUB_PROCESS_MIN_DIMENSIONS = { width: 140, height: 120 },
TEXT_ANNOTATION_MIN_DIMENSIONS = { width: 50, height: 30 };
export var PARTICIPANT_MIN_DIMENSIONS = { width: 300, height: 150 };

export var SUB_PROCESS_MIN_DIMENSIONS = { width: 140, height: 120 };

export var TEXT_ANNOTATION_MIN_DIMENSIONS = { width: 50, height: 30 };


/**
Expand Down
36 changes: 36 additions & 0 deletions lib/features/modeling/behavior/SpaceToolBehavior.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { forEach } from 'min-dash';

import { is } from '../../../util/ModelUtil';

import { isExpanded } from '../../../util/DiUtil';

import {
PARTICIPANT_MIN_DIMENSIONS,
SUB_PROCESS_MIN_DIMENSIONS,
TEXT_ANNOTATION_MIN_DIMENSIONS
} from './ResizeBehavior';

export default function SpaceToolBehavior(eventBus) {
eventBus.on('spaceTool.getMinDimensions', function(context) {
var shapes = context.shapes,
minDimensions = {};

forEach(shapes, function(shape) {
var id = shape.id;

if (is(shape, 'bpmn:Participant')) {
minDimensions[ id ] = PARTICIPANT_MIN_DIMENSIONS;
}

if (is(shape, 'bpmn:SubProcess') && isExpanded(shape)) {
minDimensions[ id ] = SUB_PROCESS_MIN_DIMENSIONS;
}

if (is(shape, 'bpmn:TextAnnotation')) {
minDimensions[ id ] = TEXT_ANNOTATION_MIN_DIMENSIONS;
}
});

return minDimensions;
});
}
3 changes: 3 additions & 0 deletions lib/features/modeling/behavior/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import ReplaceElementBehaviour from './ReplaceElementBehaviour';
import ResizeBehavior from './ResizeBehavior';
import ResizeLaneBehavior from './ResizeLaneBehavior';
import RemoveElementBehavior from './RemoveElementBehavior';
import SpaceToolBehavior from './SpaceToolBehavior';
import SubProcessStartEventBehavior from './SubProcessStartEventBehavior';
import ToggleElementCollapseBehaviour from './ToggleElementCollapseBehaviour';
import UnclaimIdBehavior from './UnclaimIdBehavior';
Expand Down Expand Up @@ -61,6 +62,7 @@ export default {
'resizeBehavior',
'resizeLaneBehavior',
'toggleElementCollapseBehaviour',
'spaceToolBehavior',
'subProcessStartEventBehavior',
'unclaimIdBehavior',
'unsetDefaultFlowBehavior',
Expand Down Expand Up @@ -94,6 +96,7 @@ export default {
resizeLaneBehavior: [ 'type', ResizeLaneBehavior ],
removeElementBehavior: [ 'type', RemoveElementBehavior ],
toggleElementCollapseBehaviour : [ 'type', ToggleElementCollapseBehaviour ],
spaceToolBehavior: [ 'type', SpaceToolBehavior ],
subProcessStartEventBehavior: [ 'type', SubProcessStartEventBehavior ],
unclaimIdBehavior: [ 'type', UnclaimIdBehavior ],
updateFlowNodeRefsBehavior: [ 'type', UpdateFlowNodeRefsBehavior ],
Expand Down
13 changes: 13 additions & 0 deletions test/spec/features/modeling/behavior/SpaceToolBehaviorSpec.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?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:dc="http://www.omg.org/spec/DD/20100524/DC" id="Definitions_1ev9p7s" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.5.0">
<bpmn:process id="Process_1msk4wr" isExecutable="true">
<bpmn:subProcess id="SubProcess_1" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1msk4wr">
<bpmndi:BPMNShape id="SubProcess_04mmoqh_di" bpmnElement="SubProcess_1" isExpanded="true">
<dc:Bounds x="0" y="0" width="350" height="200" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
60 changes: 60 additions & 0 deletions test/spec/features/modeling/behavior/SpaceToolBehaviorSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import {
bootstrapModeler,
inject
} from 'test/TestHelper';

import coreModule from 'lib/core';
import modelingModule from 'lib/features/modeling';
import rulesModule from 'lib/features/rules';
import snappingModule from 'lib/features/snapping';
import spaceToolModule from 'diagram-js/lib/features/space-tool';

import {
createCanvasEvent as canvasEvent
} from '../../../../util/MockEvents';

import { SUB_PROCESS_MIN_DIMENSIONS } from 'lib/features/modeling/behavior/ResizeBehavior';

var testModules = [
coreModule,
modelingModule,
rulesModule,
snappingModule,
spaceToolModule
];


describe('features/modeling - space tool behavior', function() {

describe('participant', function() {

describe('minimum dimensions', function() {

var diagramXML = require('./SpaceToolBehaviorSpec.bpmn');

beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));


it('should ensure minimum dimensions', inject(
function(dragging, elementRegistry, spaceTool) {

// given
var subProcess = elementRegistry.get('SubProcess_1');

// when
spaceTool.activateMakeSpace(canvasEvent({ x: 300, y: 0 }));

dragging.move(canvasEvent({ x: 0, y: 0 }));

dragging.end();

// then
expect(subProcess.width).to.equal(SUB_PROCESS_MIN_DIMENSIONS.width);
})
);

});

});

});

0 comments on commit 7ee304f

Please sign in to comment.