Merge branch 'master' into develop

This commit is contained in:
Nico Rehwaldt 2019-12-01 14:01:44 +01:00
commit a86b1476dd
5 changed files with 181 additions and 116 deletions

View File

@ -42,22 +42,29 @@ export default function AdaptiveLabelPositioningBehavior(eventBus, modeling) {
'connection.layout',
'connection.updateWaypoints'
], function(event) {
var context = event.context,
connection = context.connection;
connection = context.connection,
source = connection.source,
target = connection.target,
hints = context.hints || {};
var source = connection.source,
target = connection.target;
checkLabelAdjustment(source);
checkLabelAdjustment(target);
if (hints.createElementsBehavior !== false) {
checkLabelAdjustment(source);
checkLabelAdjustment(target);
}
});
this.postExecuted([
'label.create'
], function(event) {
checkLabelAdjustment(event.context.shape.labelTarget);
var context = event.context,
shape = context.shape,
hints = context.hints || {};
if (hints.createElementsBehavior !== false) {
checkLabelAdjustment(shape.labelTarget);
}
});
@ -65,11 +72,14 @@ export default function AdaptiveLabelPositioningBehavior(eventBus, modeling) {
'elements.create'
], function(event) {
var context = event.context,
elements = context.elements;
elements = context.elements,
hints = context.hints || {};
elements.forEach(function(element) {
checkLabelAdjustment(element);
});
if (hints.createElementsBehavior !== false) {
elements.forEach(function(element) {
checkLabelAdjustment(element);
});
}
});
function checkLabelAdjustment(element) {

View File

@ -12,7 +12,8 @@ import {
import {
isLabelExternal,
getExternalLabelMid,
hasExternalLabel
hasExternalLabel,
isLabel
} from '../../../util/LabelUtil';
import {
@ -110,7 +111,7 @@ export default function LabelBehavior(
var element = context.shape || context.connection,
businessObject = element.businessObject;
if (!isLabelExternal(element)) {
if (isLabel(element) || !isLabelExternal(element)) {
return;
}

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="sid-38422fae-e03e-43a3-bef4-bd33b32041b2" targetNamespace="http://bpmn.io/bpmn" exporter="http://bpmn.io" exporterVersion="0.10.1">
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="sid-38422fae-e03e-43a3-bef4-bd33b32041b2" targetNamespace="http://bpmn.io/bpmn" exporter="Camunda Modeler" exporterVersion="3.5.0">
<process id="Process_1" isExecutable="false">
<exclusiveGateway id="LabelBottom" name="BOTTOM" />
<exclusiveGateway id="LabelLeft" name="LEFT" />
@ -38,116 +38,136 @@
<incoming>SequenceFlow_0isa70k</incoming>
</exclusiveGateway>
<sequenceFlow id="SequenceFlow_0isa70k" sourceRef="NoLabel" targetRef="ExclusiveGateway_02fomt2" />
<exclusiveGateway id="ExclusiveGateway_1" name="Foo">
<outgoing>SequenceFlow_3</outgoing>
</exclusiveGateway>
<endEvent id="EndEvent_1">
<incoming>SequenceFlow_3</incoming>
</endEvent>
<sequenceFlow id="SequenceFlow_3" sourceRef="ExclusiveGateway_1" targetRef="EndEvent_1" />
</process>
<bpmndi:BPMNDiagram id="BpmnDiagram_1">
<bpmndi:BPMNPlane id="BpmnPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="LabelBottom_di" bpmnElement="LabelBottom" isMarkerVisible="true">
<omgdc:Bounds x="113" y="89" width="36" height="36" />
<omgdc:Bounds x="163" y="89" width="36" height="36" />
<bpmndi:BPMNLabel>
<omgdc:Bounds x="107" y="129" width="49" height="12" />
<omgdc:Bounds x="158" y="129" width="48" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="LabelLeft_di" bpmnElement="LabelLeft" isMarkerVisible="true">
<omgdc:Bounds x="309" y="82" width="50" height="50" />
<omgdc:Bounds x="359" y="82" width="50" height="50" />
<bpmndi:BPMNLabel>
<omgdc:Bounds x="263" y="101" width="30" height="24" />
<omgdc:Bounds x="314" y="101" width="28" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="LabelTop_di" bpmnElement="LabelTop" isMarkerVisible="true">
<omgdc:Bounds x="309" y="225" width="50" height="50" />
<omgdc:Bounds x="359" y="225" width="50" height="50" />
<bpmndi:BPMNLabel>
<omgdc:Bounds x="322" y="198" width="24" height="12" />
<omgdc:Bounds x="373" y="198" width="23" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="LabelRight_di" bpmnElement="LabelRight" isMarkerVisible="true">
<omgdc:Bounds x="106" y="225" width="50" height="50" />
<omgdc:Bounds x="156" y="225" width="50" height="50" />
<bpmndi:BPMNLabel>
<omgdc:Bounds x="168" y="244" width="37" height="12" />
<omgdc:Bounds x="219" y="244" width="35" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="LabelBottomLeft_di" bpmnElement="LabelBottomLeft" isMarkerVisible="true">
<omgdc:Bounds x="532" y="82" width="50" height="50" />
<omgdc:Bounds x="582" y="82" width="50" height="50" />
<bpmndi:BPMNLabel>
<omgdc:Bounds x="487" y="146" width="83" height="12" />
<omgdc:Bounds x="538" y="146" width="81" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="LabelBottom_2_di" bpmnElement="LabelBottom_2" isMarkerVisible="true">
<omgdc:Bounds x="106" y="370" width="50" height="50" />
<omgdc:Bounds x="156" y="370" width="50" height="50" />
<bpmndi:BPMNLabel>
<omgdc:Bounds x="101" y="424" width="61" height="12" />
<omgdc:Bounds x="152" y="424" width="60" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="LabelBottom_3_di" bpmnElement="LabelBottom_3" isMarkerVisible="true">
<omgdc:Bounds x="309" y="370" width="50" height="50" />
<omgdc:Bounds x="359" y="370" width="50" height="50" />
<bpmndi:BPMNLabel>
<omgdc:Bounds x="304" y="424" width="61" height="12" />
<omgdc:Bounds x="355" y="424" width="60" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_1_di" bpmnElement="SequenceFlow_1">
<omgdi:waypoint x="334" y="275" />
<omgdi:waypoint x="334" y="370" />
<omgdi:waypoint x="384" y="275" />
<omgdi:waypoint x="384" y="370" />
<bpmndi:BPMNLabel>
<omgdc:Bounds x="346" y="317" width="7" height="12" />
<omgdc:Bounds x="396" y="317" width="7" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="SequenceFlow_2_di" bpmnElement="SequenceFlow_2">
<omgdi:waypoint x="131" y="275" />
<omgdi:waypoint x="131" y="370" />
<omgdi:waypoint x="181" y="275" />
<omgdi:waypoint x="181" y="370" />
<bpmndi:BPMNLabel>
<omgdc:Bounds x="142" y="317" width="8" height="12" />
<omgdc:Bounds x="193" y="317" width="7" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="LabelImpossible_di" bpmnElement="LabelImpossible" isMarkerVisible="true">
<omgdc:Bounds x="633" y="308" width="50" height="50" />
<omgdc:Bounds x="683" y="308" width="50" height="50" />
<bpmndi:BPMNLabel>
<omgdc:Bounds x="694" y="327" width="68" height="12" />
<omgdc:Bounds x="745" y="327" width="67" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Task_di" bpmnElement="Task">
<omgdc:Bounds x="776" y="293" width="100" height="80" />
<omgdc:Bounds x="826" y="293" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_1qmllcx_di" bpmnElement="SequenceFlow_1qmllcx">
<omgdi:waypoint x="826" y="293" />
<omgdi:waypoint x="826" y="202" />
<omgdi:waypoint x="658" y="202" />
<omgdi:waypoint x="658" y="308" />
<omgdi:waypoint x="876" y="293" />
<omgdi:waypoint x="876" y="202" />
<omgdi:waypoint x="708" y="202" />
<omgdi:waypoint x="708" y="308" />
<bpmndi:BPMNLabel>
<omgdc:Bounds x="742" y="181" width="0" height="12" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="SequenceFlow_0s993e4_di" bpmnElement="SequenceFlow_0s993e4">
<omgdi:waypoint x="826" y="373" />
<omgdi:waypoint x="826" y="424" />
<omgdi:waypoint x="658" y="424" />
<omgdi:waypoint x="658" y="358" />
<omgdi:waypoint x="876" y="373" />
<omgdi:waypoint x="876" y="424" />
<omgdi:waypoint x="708" y="424" />
<omgdi:waypoint x="708" y="358" />
<bpmndi:BPMNLabel>
<omgdc:Bounds x="742" y="403" width="0" height="12" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="SequenceFlow_022at7e_di" bpmnElement="SequenceFlow_022at7e">
<omgdi:waypoint x="845" y="373" />
<omgdi:waypoint x="845" y="453" />
<omgdi:waypoint x="594" y="453" />
<omgdi:waypoint x="594" y="333" />
<omgdi:waypoint x="633" y="333" />
<omgdi:waypoint x="895" y="373" />
<omgdi:waypoint x="895" y="453" />
<omgdi:waypoint x="644" y="453" />
<omgdi:waypoint x="644" y="333" />
<omgdi:waypoint x="683" y="333" />
<bpmndi:BPMNLabel>
<omgdc:Bounds x="719.5" y="432" width="0" height="12" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="NoLabel_di" bpmnElement="NoLabel" isMarkerVisible="true">
<omgdc:Bounds x="633" y="82" width="50" height="50" />
<omgdc:Bounds x="683" y="82" width="50" height="50" />
<bpmndi:BPMNLabel>
<omgdc:Bounds x="120" y="570" width="22" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="ExclusiveGateway_02fomt2_di" bpmnElement="ExclusiveGateway_02fomt2" isMarkerVisible="true">
<omgdc:Bounds x="836" y="82" width="50" height="50" />
<omgdc:Bounds x="886" y="82" width="50" height="50" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_0isa70k_di" bpmnElement="SequenceFlow_0isa70k">
<omgdi:waypoint x="658" y="132" />
<omgdi:waypoint x="658" y="159" />
<omgdi:waypoint x="861" y="159" />
<omgdi:waypoint x="861" y="132" />
<omgdi:waypoint x="708" y="132" />
<omgdi:waypoint x="708" y="159" />
<omgdi:waypoint x="911" y="159" />
<omgdi:waypoint x="911" y="132" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="ExclusiveGateway_0i2uvba_di" bpmnElement="ExclusiveGateway_1" isMarkerVisible="true">
<omgdc:Bounds x="1035" y="82" width="50" height="50" />
<bpmndi:BPMNLabel>
<omgdc:Bounds x="1050" y="152" width="20" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="EndEvent_0l1udor_di" bpmnElement="EndEvent_1">
<omgdc:Bounds x="1042" y="315" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_1hp7ppg_di" bpmnElement="SequenceFlow_3">
<omgdi:waypoint x="1060" y="132" />
<omgdi:waypoint x="1060" y="315" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>

View File

@ -1,3 +1,5 @@
/* global sinon */
import {
bootstrapModeler,
inject
@ -8,16 +10,13 @@ import { getOrientation } from 'diagram-js/lib/layout/LayoutUtil';
import modelingModule from 'lib/features/modeling';
import coreModule from 'lib/core';
import {
DEFAULT_LABEL_SIZE,
getExternalLabelMid
} from 'lib/util/LabelUtil';
var testModules = [
modelingModule,
coreModule
];
var spy = sinon.spy;
var ATTACH = { attach: true };
describe('modeling/behavior - AdaptiveLabelPositioningBehavior', function() {
@ -270,51 +269,6 @@ describe('modeling/behavior - AdaptiveLabelPositioningBehavior', function() {
describe('on label creation', function() {
describe('through <create.shape>', function() {
it('should create at LEFT', inject(function(bpmnFactory, elementFactory, elementRegistry, modeling, textRenderer) {
// given
var sequenceFlow = elementRegistry.get('SequenceFlow_1');
var intermediateThrowEvent = elementFactory.createShape({
businessObject: bpmnFactory.create('bpmn:IntermediateThrowEvent', {
name: 'Foo'
}),
type: 'bpmn:IntermediateThrowEvent',
x: 0,
y: 0
});
var externalLabelMid = getExternalLabelMid(intermediateThrowEvent);
var externalLabelBounds = textRenderer.getExternalLabelBounds(DEFAULT_LABEL_SIZE, 'Foo');
var label = elementFactory.createLabel({
labelTarget: intermediateThrowEvent,
x: externalLabelMid.x - externalLabelBounds.width / 2,
y: externalLabelMid.y - externalLabelBounds.height / 2,
width: externalLabelBounds.width,
height: externalLabelBounds.height
});
var sequenceFlowMid = getConnectionMid(sequenceFlow.waypoints[0], sequenceFlow.waypoints[1]);
// when
modeling.createElements([ intermediateThrowEvent, label ], sequenceFlowMid, sequenceFlow, {
createElementsBehavior: false
});
// then
expect(label.x).to.be.closeTo(287, 1);
expect(label.y).to.be.closeTo(307, 1);
expect(label.width).to.be.closeTo(19, 1);
expect(label.height).to.be.closeTo(14, 1);
}));
});
describe('through <element.updateProperties>', function() {
it('should create label at TOP', inject(
@ -458,13 +412,45 @@ describe('modeling/behavior - AdaptiveLabelPositioningBehavior', function() {
});
describe('integration', function() {
describe('copy and paste', function() {
var diagramXML = require('./AdaptiveLabelPositioningBehavior.basics.bpmn');
beforeEach(bootstrapModeler(diagramXML, {
modules: testModules
}));
it('should NOT adjust on paste', inject(
function(canvas, copyPaste, elementRegistry, modeling) {
// given
var exclusiveGateway = elementRegistry.get('ExclusiveGateway_1'),
endEvent = elementRegistry.get('EndEvent_1');
var moveShapeSpy = spy(modeling, 'moveShape');
// when
copyPaste.copy([ exclusiveGateway, endEvent ]);
copyPaste.paste({
element: canvas.getRootElement(),
point: {
x: 1000,
y: 1000
}
});
// then
expect(moveShapeSpy).not.to.have.been.called;
})
);
});
});
});
// helpers //////////
function getConnectionMid(a, b) {
return {
x: (a.x + b.x) / 2,
y: (a.y + b.y) / 2
};
}

View File

@ -9,6 +9,11 @@ import {
resizeBounds
} from 'diagram-js/lib/features/resize/ResizeUtil';
import {
DEFAULT_LABEL_SIZE,
getExternalLabelMid
} from 'lib/util/LabelUtil';
import {
pick
} from 'min-dash';
@ -17,6 +22,8 @@ import modelingModule from 'lib/features/modeling';
import coreModule from 'lib/core';
import gridSnappingModule from 'lib/features/grid-snapping';
var spy = sinon.spy;
describe('behavior - LabelBehavior', function() {
@ -196,6 +203,47 @@ describe('behavior - LabelBehavior', function() {
));
it('should not add label if created shape is label', inject(
function(bpmnFactory, elementFactory, elementRegistry, modeling, textRenderer) {
// given
var parentShape = elementRegistry.get('Process_1');
var createLabelSpy = spy(modeling, 'createLabel');
var exclusiveGatewayBo = bpmnFactory.create('bpmn:ExclusiveGateway', {
name: 'Foo'
});
var exclusiveGateway = elementFactory.createShape({
type: 'bpmn:ExclusiveGateway',
businessObject: exclusiveGatewayBo
});
modeling.createElements([ exclusiveGateway ], { x: 50, y: 50 }, parentShape, {
createElementsBehavior: false
});
var externalLabelMid = getExternalLabelMid(exclusiveGateway);
var externalLabelBounds = textRenderer.getExternalLabelBounds(DEFAULT_LABEL_SIZE, 'Foo');
var label = elementFactory.createLabel({
businessObject: exclusiveGatewayBo,
labelTarget: exclusiveGateway,
width: externalLabelBounds.width,
height: externalLabelBounds.height
});
// when
modeling.createElements([ label ], externalLabelMid, parentShape);
// then
expect(createLabelSpy).not.to.have.been.called;
})
);
describe('on append', function() {
it('correctly wired and positioned', inject(