fix(distribute-elements): exclude boundary events from distrubution

closes #605
This commit is contained in:
Philipp Fromme 2016-08-15 14:01:36 +02:00
parent 91cfcd9bac
commit 14ae66e5bb
3 changed files with 104 additions and 8 deletions

View File

@ -13,14 +13,15 @@ function BpmnDistributeElements(distributeElements) {
distributeElements.registerFilter(function(elements) {
return filter(elements, function(element) {
var cannotDistribute = isAny(element, [
'bpmn:SequenceFlow',
'bpmn:MessageFlow',
'bpmn:Association',
'bpmn:BoundaryEvent',
'bpmn:DataInputAssociation',
'bpmn:DataOutputAssociation',
'bpmn:Association',
'bpmn:TextAnnotation',
'bpmn:Lane',
'bpmn:MessageFlow',
'bpmn:Participant',
'bpmn:Lane'
'bpmn:SequenceFlow',
'bpmn:TextAnnotation'
]);
return !(element.labelTarget || cannotDistribute);

View File

@ -0,0 +1,58 @@
<?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:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.2.2">
<bpmn:process id="Process_1" isExecutable="false">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>SequenceFlow_0vrvkcp</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:task id="Task_1">
<bpmn:incoming>SequenceFlow_0vrvkcp</bpmn:incoming>
</bpmn:task>
<bpmn:sequenceFlow id="SequenceFlow_0vrvkcp" sourceRef="StartEvent_1" targetRef="Task_1" />
<bpmn:boundaryEvent id="BoundaryEvent_1" attachedToRef="Task_1">
<bpmn:outgoing>SequenceFlow_1jet52k</bpmn:outgoing>
</bpmn:boundaryEvent>
<bpmn:endEvent id="EndEvent_1">
<bpmn:incoming>SequenceFlow_1jet52k</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_1jet52k" sourceRef="BoundaryEvent_1" targetRef="EndEvent_1" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="37" y="61" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="10" y="97" width="90" height="20" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Task_1qacn6w_di" bpmnElement="Task_1">
<dc:Bounds x="140" y="39" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_0vrvkcp_di" bpmnElement="SequenceFlow_0vrvkcp">
<di:waypoint xsi:type="dc:Point" x="73" y="79" />
<di:waypoint xsi:type="dc:Point" x="140" y="79" />
<bpmndi:BPMNLabel>
<dc:Bounds x="61.5" y="54" width="90" height="20" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="BoundaryEvent_10ce33p_di" bpmnElement="BoundaryEvent_1">
<dc:Bounds x="222" y="101" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="195" y="137" width="90" height="20" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="EndEvent_0lfg1uu_di" bpmnElement="EndEvent_1">
<dc:Bounds x="481" y="101" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="454" y="137" width="90" height="20" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_1jet52k_di" bpmnElement="SequenceFlow_1jet52k">
<di:waypoint xsi:type="dc:Point" x="258" y="119" />
<di:waypoint xsi:type="dc:Point" x="481" y="119" />
<bpmndi:BPMNLabel>
<dc:Bounds x="324.5" y="94" width="90" height="20" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -16,13 +16,14 @@ function last(arr) {
describe('features/distribute-elements', function() {
var testModules = [ bpmnDistributeElements, modelingModule, coreModule ];
var basicXML = require('../../../fixtures/bpmn/distribute-elements.bpmn');
beforeEach(bootstrapModeler(basicXML, { modules: testModules }));
describe('basics', function() {
var basicXML = require('../../../fixtures/bpmn/distribute-elements.bpmn');
beforeEach(bootstrapModeler(basicXML, { modules: testModules }));
var elements;
beforeEach(inject(function(elementRegistry, canvas) {
@ -33,6 +34,7 @@ describe('features/distribute-elements', function() {
it('should align horizontally', inject(function(distributeElements) {
// when
var rangeGroups = distributeElements.trigger(elements, 'horizontal'),
margin = rangeGroups[1].range.min - rangeGroups[0].range.max;
@ -49,10 +51,12 @@ describe('features/distribute-elements', function() {
expect(last(rangeGroups).range).to.eql({
min: 1195, max: 1221
});
}));
it('should align vertically', inject(function(distributeElements) {
// when
var rangeGroups = distributeElements.trigger(elements, 'vertical'),
margin = rangeGroups[1].range.min - rangeGroups[0].range.max;
@ -69,6 +73,39 @@ describe('features/distribute-elements', function() {
expect(last(rangeGroups).range).to.eql({
min: 373, max: 413
});
}));
});
describe('filtering elements', function() {
var xml = require('../../../fixtures/bpmn/distribute-elements-filtering.bpmn');
beforeEach(bootstrapModeler(xml, { modules: testModules }));
var elements;
beforeEach(inject(function(elementRegistry, canvas) {
elements = elementRegistry.filter(function(element) {
return element.parent;
});
}));
it('should not distribute boundary events', inject(function(distributeElements, elementRegistry) {
// given
var boundaryEvent = elementRegistry.get('BoundaryEvent_1');
// when
var rangeGroups = distributeElements.trigger(elements, 'horizontal');
// then
expect(rangeGroups).to.have.length(3);
expect(rangeGroups[1].elements).to.not.include(boundaryEvent);
}));
});