fix(space-tool): consider lanes when resizing participant
Related to camunda/camunda-modeler#1703
This commit is contained in:
parent
ffa0a88d30
commit
dafa6f138c
|
@ -6,6 +6,8 @@ import { getParticipantResizeConstraints } from './util/ResizeUtil';
|
|||
|
||||
var HIGH_PRIORITY = 1500;
|
||||
|
||||
export var LANE_MIN_DIMENSIONS = { width: 300, height: 60 };
|
||||
|
||||
export var PARTICIPANT_MIN_DIMENSIONS = { width: 300, height: 150 };
|
||||
|
||||
export var SUB_PROCESS_MIN_DIMENSIONS = { width: 140, height: 120 };
|
||||
|
|
|
@ -1,25 +1,45 @@
|
|||
import { forEach } from 'min-dash';
|
||||
import {
|
||||
forEach,
|
||||
reduce
|
||||
} from 'min-dash';
|
||||
|
||||
import { is } from '../../../util/ModelUtil';
|
||||
|
||||
import { isExpanded } from '../../../util/DiUtil';
|
||||
|
||||
import {
|
||||
LANE_MIN_DIMENSIONS,
|
||||
PARTICIPANT_MIN_DIMENSIONS,
|
||||
SUB_PROCESS_MIN_DIMENSIONS,
|
||||
TEXT_ANNOTATION_MIN_DIMENSIONS
|
||||
} from './ResizeBehavior';
|
||||
|
||||
import { getChildLanes } from '../util/LaneUtil';
|
||||
|
||||
var max = Math.max;
|
||||
|
||||
|
||||
export default function SpaceToolBehavior(eventBus) {
|
||||
eventBus.on('spaceTool.getMinDimensions', function(context) {
|
||||
var shapes = context.shapes,
|
||||
axis = context.axis,
|
||||
start = context.start,
|
||||
minDimensions = {};
|
||||
|
||||
forEach(shapes, function(shape) {
|
||||
var id = shape.id;
|
||||
|
||||
if (is(shape, 'bpmn:Participant')) {
|
||||
minDimensions[ id ] = PARTICIPANT_MIN_DIMENSIONS;
|
||||
|
||||
if (isHorizontal(axis)) {
|
||||
minDimensions[ id ] = PARTICIPANT_MIN_DIMENSIONS;
|
||||
} else {
|
||||
minDimensions[ id ] = {
|
||||
width: PARTICIPANT_MIN_DIMENSIONS.width,
|
||||
height: getParticipantMinHeight(shape, start)
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (is(shape, 'bpmn:SubProcess') && isExpanded(shape)) {
|
||||
|
@ -36,3 +56,52 @@ export default function SpaceToolBehavior(eventBus) {
|
|||
}
|
||||
|
||||
SpaceToolBehavior.$inject = [ 'eventBus' ];
|
||||
|
||||
|
||||
// helpers //////////
|
||||
|
||||
/**
|
||||
* Get minimum height for participant taking lanes into account.
|
||||
*
|
||||
* @param {<djs.model.Shape>} participant
|
||||
* @param {number} start
|
||||
*
|
||||
* @returns {Object}
|
||||
*/
|
||||
function getParticipantMinHeight(participant, start) {
|
||||
var lanes = getChildLanes(participant);
|
||||
|
||||
if (!lanes.length) {
|
||||
return PARTICIPANT_MIN_DIMENSIONS.height;
|
||||
}
|
||||
|
||||
function getLanesMinHeight(element) {
|
||||
return reduce(getChildLanes(element), function(minHeight, lane) {
|
||||
if (start >= lane.y && start <= lane.y + lane.height) {
|
||||
|
||||
// resizing lane
|
||||
if (hasChildLanes(lane)) {
|
||||
minHeight += getLanesMinHeight(lane);
|
||||
} else {
|
||||
minHeight += lane.y + LANE_MIN_DIMENSIONS.height - participant.y;
|
||||
}
|
||||
} else if (start <= lane.y) {
|
||||
|
||||
// lane after resizing lane
|
||||
minHeight += lane.height;
|
||||
}
|
||||
|
||||
return minHeight;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
return max(PARTICIPANT_MIN_DIMENSIONS.height, getLanesMinHeight(participant));
|
||||
}
|
||||
|
||||
function hasChildLanes(element) {
|
||||
return !!getChildLanes(element).length;
|
||||
}
|
||||
|
||||
function isHorizontal(axis) {
|
||||
return axis === 'x';
|
||||
}
|
|
@ -9,6 +9,8 @@ import {
|
|||
getLanesRoot
|
||||
} from '../../../modeling/util/LaneUtil';
|
||||
|
||||
import { LANE_MIN_DIMENSIONS } from '../ResizeBehavior';
|
||||
|
||||
var abs = Math.abs,
|
||||
min = Math.min,
|
||||
max = Math.max;
|
||||
|
@ -31,9 +33,7 @@ function addMax(trbl, attr, value) {
|
|||
return addToTrbl(trbl, attr, value, max);
|
||||
}
|
||||
|
||||
var LANE_MIN_HEIGHT = 60,
|
||||
LANE_MIN_WIDTH = 300,
|
||||
LANE_RIGHT_PADDING = 20,
|
||||
var LANE_RIGHT_PADDING = 20,
|
||||
LANE_LEFT_PADDING = 50,
|
||||
LANE_TOP_PADDING = 20,
|
||||
LANE_BOTTOM_PADDING = 20;
|
||||
|
@ -54,10 +54,10 @@ export function getParticipantResizeConstraints(laneShape, resizeDirection, bala
|
|||
minTrbl = {};
|
||||
|
||||
if (/e/.test(resizeDirection)) {
|
||||
minTrbl.right = laneTrbl.left + LANE_MIN_WIDTH;
|
||||
minTrbl.right = laneTrbl.left + LANE_MIN_DIMENSIONS.width;
|
||||
} else
|
||||
if (/w/.test(resizeDirection)) {
|
||||
minTrbl.left = laneTrbl.right - LANE_MIN_WIDTH;
|
||||
minTrbl.left = laneTrbl.right - LANE_MIN_DIMENSIONS.width;
|
||||
}
|
||||
|
||||
allLanes.forEach(function(other) {
|
||||
|
@ -72,12 +72,12 @@ export function getParticipantResizeConstraints(laneShape, resizeDirection, bala
|
|||
|
||||
// max top size (based on next element)
|
||||
if (balanced && abs(laneTrbl.top - otherTrbl.bottom) < 10) {
|
||||
addMax(maxTrbl, 'top', otherTrbl.top + LANE_MIN_HEIGHT);
|
||||
addMax(maxTrbl, 'top', otherTrbl.top + LANE_MIN_DIMENSIONS.height);
|
||||
}
|
||||
|
||||
// min top size (based on self or nested element)
|
||||
if (abs(laneTrbl.top - otherTrbl.top) < 5) {
|
||||
addMin(minTrbl, 'top', otherTrbl.bottom - LANE_MIN_HEIGHT);
|
||||
addMin(minTrbl, 'top', otherTrbl.bottom - LANE_MIN_DIMENSIONS.height);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,12 +89,12 @@ export function getParticipantResizeConstraints(laneShape, resizeDirection, bala
|
|||
|
||||
// max bottom size (based on previous element)
|
||||
if (balanced && abs(laneTrbl.bottom - otherTrbl.top) < 10) {
|
||||
addMin(maxTrbl, 'bottom', otherTrbl.bottom - LANE_MIN_HEIGHT);
|
||||
addMin(maxTrbl, 'bottom', otherTrbl.bottom - LANE_MIN_DIMENSIONS.height);
|
||||
}
|
||||
|
||||
// min bottom size (based on self or nested element)
|
||||
if (abs(laneTrbl.bottom - otherTrbl.bottom) < 5) {
|
||||
addMax(minTrbl, 'bottom', otherTrbl.top + LANE_MIN_HEIGHT);
|
||||
addMax(minTrbl, 'bottom', otherTrbl.top + LANE_MIN_DIMENSIONS.height);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -13,7 +13,11 @@ import {
|
|||
createCanvasEvent as canvasEvent
|
||||
} from '../../../../util/MockEvents';
|
||||
|
||||
import { SUB_PROCESS_MIN_DIMENSIONS } from 'lib/features/modeling/behavior/ResizeBehavior';
|
||||
import {
|
||||
LANE_MIN_DIMENSIONS,
|
||||
PARTICIPANT_MIN_DIMENSIONS,
|
||||
SUB_PROCESS_MIN_DIMENSIONS
|
||||
} from 'lib/features/modeling/behavior/ResizeBehavior';
|
||||
|
||||
var testModules = [
|
||||
coreModule,
|
||||
|
@ -26,16 +30,16 @@ var testModules = [
|
|||
|
||||
describe('features/modeling - space tool behavior', function() {
|
||||
|
||||
describe('participant', function() {
|
||||
describe('subprocess', function() {
|
||||
|
||||
describe('minimum dimensions', function() {
|
||||
|
||||
var diagramXML = require('./SpaceToolBehaviorSpec.bpmn');
|
||||
var diagramXML = require('./SpaceToolBehaviorSpec.subprocess.bpmn');
|
||||
|
||||
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
|
||||
|
||||
|
||||
it('should ensure minimum dimensions', inject(
|
||||
it('should ensure subprocess minimum dimensions', inject(
|
||||
function(dragging, elementRegistry, spaceTool) {
|
||||
|
||||
// given
|
||||
|
@ -57,4 +61,73 @@ describe('features/modeling - space tool behavior', function() {
|
|||
|
||||
});
|
||||
|
||||
describe('participant', function() {
|
||||
|
||||
describe('minimum dimensions', function() {
|
||||
|
||||
var diagramXML = require('./SpaceToolBehaviorSpec.participant.bpmn');
|
||||
|
||||
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
|
||||
|
||||
|
||||
it('should ensure participant minimum dimensions', inject(
|
||||
function(dragging, elementRegistry, spaceTool) {
|
||||
|
||||
// given
|
||||
var participant = elementRegistry.get('Participant_1');
|
||||
|
||||
// when
|
||||
spaceTool.activateMakeSpace(canvasEvent({ x: 300, y: 0 }));
|
||||
|
||||
dragging.move(canvasEvent({ x: 0, y: 0 }));
|
||||
|
||||
dragging.end();
|
||||
|
||||
// then
|
||||
expect(participant.width).to.equal(PARTICIPANT_MIN_DIMENSIONS.width);
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
it('should ensure lane minimum dimensions', inject(
|
||||
function(dragging, elementRegistry, spaceTool) {
|
||||
|
||||
// given
|
||||
var lane = elementRegistry.get('Lane_1');
|
||||
|
||||
// when
|
||||
spaceTool.activateMakeSpace(canvasEvent({ x: 0, y: 400 }));
|
||||
|
||||
dragging.move(canvasEvent({ x: 0, y: 0 }));
|
||||
|
||||
dragging.end();
|
||||
|
||||
// then
|
||||
expect(lane.height).to.equal(LANE_MIN_DIMENSIONS.height);
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
it('should ensure nested lane minimum dimensions', inject(
|
||||
function(dragging, elementRegistry, spaceTool) {
|
||||
|
||||
// given
|
||||
var lane = elementRegistry.get('Lane_6');
|
||||
|
||||
// when
|
||||
spaceTool.activateMakeSpace(canvasEvent({ x: 0, y: 925 }));
|
||||
|
||||
dragging.move(canvasEvent({ x: 0, y: 0 }));
|
||||
|
||||
dragging.end();
|
||||
|
||||
// then
|
||||
expect(lane.height).to.equal(LANE_MIN_DIMENSIONS.height);
|
||||
})
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
|
@ -0,0 +1,57 @@
|
|||
<?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_0mdr1un" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.7.0">
|
||||
<bpmn:collaboration id="Collaboration_1">
|
||||
<bpmn:participant id="Participant_1" processRef="Process_1" />
|
||||
<bpmn:participant id="Participant_2" name="Participant_2" processRef="Process_2" />
|
||||
<bpmn:participant id="Participant_3" name="Participant_3" processRef="Process_3" />
|
||||
</bpmn:collaboration>
|
||||
<bpmn:process id="Process_1" isExecutable="true" />
|
||||
<bpmn:process id="Process_2" isExecutable="false">
|
||||
<bpmn:laneSet id="LaneSet_16fkurg">
|
||||
<bpmn:lane id="Lane_1" name="Lane_1" />
|
||||
<bpmn:lane id="Lane_2" name="Lane_2" />
|
||||
</bpmn:laneSet>
|
||||
</bpmn:process>
|
||||
<bpmn:process id="Process_3" isExecutable="false">
|
||||
<bpmn:laneSet id="LaneSet_04c016w">
|
||||
<bpmn:lane id="Lane_3" name="Lane_3" />
|
||||
<bpmn:lane id="Lane_4" name="Lane_4">
|
||||
<bpmn:childLaneSet id="LaneSet_1eow6b9">
|
||||
<bpmn:lane id="Lane_5" name="Lane_5" />
|
||||
<bpmn:lane id="Lane_6" name="Lane_6" />
|
||||
</bpmn:childLaneSet>
|
||||
</bpmn:lane>
|
||||
</bpmn:laneSet>
|
||||
</bpmn:process>
|
||||
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
|
||||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_1">
|
||||
<bpmndi:BPMNShape id="Participant_06757og_di" bpmnElement="Participant_1" isHorizontal="true">
|
||||
<dc:Bounds x="0" y="0" width="600" height="250" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Participant_0ae1cne_di" bpmnElement="Participant_2" isHorizontal="true">
|
||||
<dc:Bounds x="700" y="350" width="600" height="250" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Lane_030yoo3_di" bpmnElement="Lane_1" isHorizontal="true">
|
||||
<dc:Bounds x="730" y="350" width="570" height="130" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Lane_1bwlv2s_di" bpmnElement="Lane_2" isHorizontal="true">
|
||||
<dc:Bounds x="730" y="480" width="570" height="120" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Participant_01wmlzw_di" bpmnElement="Participant_3" isHorizontal="true">
|
||||
<dc:Bounds x="1400" y="700" width="600" height="250" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Lane_0jco8kr_di" bpmnElement="Lane_3" isHorizontal="true">
|
||||
<dc:Bounds x="1430" y="700" width="570" height="125" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Lane_0zojmuw_di" bpmnElement="Lane_4" isHorizontal="true">
|
||||
<dc:Bounds x="1430" y="825" width="570" height="125" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Lane_1xlpjnj_di" bpmnElement="Lane_5" isHorizontal="true">
|
||||
<dc:Bounds x="1460" y="825" width="540" height="63" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Lane_0k03ea4_di" bpmnElement="Lane_6" isHorizontal="true">
|
||||
<dc:Bounds x="1460" y="888" width="540" height="62" />
|
||||
</bpmndi:BPMNShape>
|
||||
</bpmndi:BPMNPlane>
|
||||
</bpmndi:BPMNDiagram>
|
||||
</bpmn:definitions>
|
Loading…
Reference in New Issue