feat: make elementFactory._getDefaultSize public
This has the benefit of using the public API method across our code base.
This commit is contained in:
parent
ca8488b2c9
commit
5589439774
|
@ -6,7 +6,11 @@ import {
|
||||||
|
|
||||||
import inherits from 'inherits';
|
import inherits from 'inherits';
|
||||||
|
|
||||||
import { is } from '../../util/ModelUtil';
|
import {
|
||||||
|
getBusinessObject,
|
||||||
|
getDi,
|
||||||
|
is
|
||||||
|
} from '../../util/ModelUtil';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
isExpanded
|
isExpanded
|
||||||
|
@ -127,7 +131,7 @@ ElementFactory.prototype.createBpmnElement = function(elementType, attrs) {
|
||||||
delete attrs.eventDefinitionType;
|
delete attrs.eventDefinitionType;
|
||||||
}
|
}
|
||||||
|
|
||||||
size = this._getDefaultSize(businessObject);
|
size = this.getDefaultSize(businessObject, di);
|
||||||
|
|
||||||
attrs = assign({
|
attrs = assign({
|
||||||
businessObject: businessObject,
|
businessObject: businessObject,
|
||||||
|
@ -139,54 +143,56 @@ ElementFactory.prototype.createBpmnElement = function(elementType, attrs) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
ElementFactory.prototype._getDefaultSize = function(semantic) {
|
ElementFactory.prototype.getDefaultSize = function(element, di) {
|
||||||
|
|
||||||
if (is(semantic, 'bpmn:SubProcess')) {
|
var bo = getBusinessObject(element);
|
||||||
|
di = di || getDi(element);
|
||||||
|
|
||||||
if (isExpanded(semantic)) {
|
if (is(bo, 'bpmn:SubProcess')) {
|
||||||
|
if (isExpanded(bo, di)) {
|
||||||
return { width: 350, height: 200 };
|
return { width: 350, height: 200 };
|
||||||
} else {
|
} else {
|
||||||
return { width: 100, height: 80 };
|
return { width: 100, height: 80 };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is(semantic, 'bpmn:Task')) {
|
if (is(bo, 'bpmn:Task')) {
|
||||||
return { width: 100, height: 80 };
|
return { width: 100, height: 80 };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is(semantic, 'bpmn:Gateway')) {
|
if (is(bo, 'bpmn:Gateway')) {
|
||||||
return { width: 50, height: 50 };
|
return { width: 50, height: 50 };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is(semantic, 'bpmn:Event')) {
|
if (is(bo, 'bpmn:Event')) {
|
||||||
return { width: 36, height: 36 };
|
return { width: 36, height: 36 };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is(semantic, 'bpmn:Participant')) {
|
if (is(bo, 'bpmn:Participant')) {
|
||||||
if (isExpanded(semantic)) {
|
if (isExpanded(bo, di)) {
|
||||||
return { width: 600, height: 250 };
|
return { width: 600, height: 250 };
|
||||||
} else {
|
} else {
|
||||||
return { width: 400, height: 60 };
|
return { width: 400, height: 60 };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is(semantic, 'bpmn:Lane')) {
|
if (is(bo, 'bpmn:Lane')) {
|
||||||
return { width: 400, height: 100 };
|
return { width: 400, height: 100 };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is(semantic, 'bpmn:DataObjectReference')) {
|
if (is(bo, 'bpmn:DataObjectReference')) {
|
||||||
return { width: 36, height: 50 };
|
return { width: 36, height: 50 };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is(semantic, 'bpmn:DataStoreReference')) {
|
if (is(bo, 'bpmn:DataStoreReference')) {
|
||||||
return { width: 50, height: 50 };
|
return { width: 50, height: 50 };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is(semantic, 'bpmn:TextAnnotation')) {
|
if (is(bo, 'bpmn:TextAnnotation')) {
|
||||||
return { width: 100, height: 30 };
|
return { width: 100, height: 30 };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is(semantic, 'bpmn:Group')) {
|
if (is(bo, 'bpmn:Group')) {
|
||||||
return { width: 300, height: 300 };
|
return { width: 300, height: 300 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ export default function ToggleElementCollapseBehaviour(
|
||||||
|
|
||||||
this.postExecuted([ 'shape.toggleCollapse' ], LOW_PRIORITY, function(e) {
|
this.postExecuted([ 'shape.toggleCollapse' ], LOW_PRIORITY, function(e) {
|
||||||
var shape = e.context.shape,
|
var shape = e.context.shape,
|
||||||
defaultSize = elementFactory._getDefaultSize(shape),
|
defaultSize = elementFactory.getDefaultSize(shape),
|
||||||
newBounds;
|
newBounds;
|
||||||
|
|
||||||
if (shape.collapsed) {
|
if (shape.collapsed) {
|
||||||
|
|
|
@ -207,12 +207,12 @@ export default function BpmnReplace(
|
||||||
|
|
||||||
// apply same width and default height
|
// apply same width and default height
|
||||||
newElement.width = element.width;
|
newElement.width = element.width;
|
||||||
newElement.height = elementFactory._getDefaultSize(newBusinessObject).height;
|
newElement.height = elementFactory.getDefaultSize(newElement).height;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rules.allowed('shape.resize', { shape: newBusinessObject })) {
|
if (!rules.allowed('shape.resize', { shape: newBusinessObject })) {
|
||||||
newElement.height = elementFactory._getDefaultSize(newBusinessObject).height;
|
newElement.height = elementFactory.getDefaultSize(newElement).height;
|
||||||
newElement.width = elementFactory._getDefaultSize(newBusinessObject).width;
|
newElement.width = elementFactory.getDefaultSize(newElement).width;
|
||||||
}
|
}
|
||||||
|
|
||||||
newBusinessObject.name = oldBusinessObject.name;
|
newBusinessObject.name = oldBusinessObject.name;
|
||||||
|
|
|
@ -335,7 +335,6 @@ describe('features/modeling - create participant', function() {
|
||||||
beforeEach(bootstrapModeler(processDiagramXML, { modules: testModules }));
|
beforeEach(bootstrapModeler(processDiagramXML, { modules: testModules }));
|
||||||
|
|
||||||
var participant,
|
var participant,
|
||||||
participantBo,
|
|
||||||
process,
|
process,
|
||||||
processGfx;
|
processGfx;
|
||||||
|
|
||||||
|
@ -346,7 +345,6 @@ describe('features/modeling - create participant', function() {
|
||||||
processGfx = canvas.getGraphics(process);
|
processGfx = canvas.getGraphics(process);
|
||||||
|
|
||||||
participant = elementFactory.createParticipantShape();
|
participant = elementFactory.createParticipantShape();
|
||||||
participantBo = participant.businessObject;
|
|
||||||
|
|
||||||
create.start(canvasEvent({ x: 100, y: 100 }), participant);
|
create.start(canvasEvent({ x: 100, y: 100 }), participant);
|
||||||
|
|
||||||
|
@ -357,7 +355,7 @@ describe('features/modeling - create participant', function() {
|
||||||
it('should fit participant', inject(function(elementFactory) {
|
it('should fit participant', inject(function(elementFactory) {
|
||||||
|
|
||||||
// then
|
// then
|
||||||
var defaultSize = elementFactory._getDefaultSize(participantBo);
|
var defaultSize = elementFactory.getDefaultSize(participant);
|
||||||
|
|
||||||
expect(participant.width).to.equal(defaultSize.width);
|
expect(participant.width).to.equal(defaultSize.width);
|
||||||
expect(participant.height).to.equal(defaultSize.height);
|
expect(participant.height).to.equal(defaultSize.height);
|
||||||
|
@ -423,7 +421,6 @@ describe('features/modeling - create participant', function() {
|
||||||
var process = canvas.getRootElement(),
|
var process = canvas.getRootElement(),
|
||||||
processGfx = canvas.getGraphics(process),
|
processGfx = canvas.getGraphics(process),
|
||||||
participant = elementFactory.createParticipantShape(),
|
participant = elementFactory.createParticipantShape(),
|
||||||
participantBo = participant.businessObject,
|
|
||||||
groupElement = elementFactory.createShape({ type: 'bpmn:Group' });
|
groupElement = elementFactory.createShape({ type: 'bpmn:Group' });
|
||||||
|
|
||||||
modeling.createShape(groupElement, { x: 100, y: 100 }, process);
|
modeling.createShape(groupElement, { x: 100, y: 100 }, process);
|
||||||
|
@ -433,7 +430,7 @@ describe('features/modeling - create participant', function() {
|
||||||
dragging.hover({ element: process, gfx: processGfx });
|
dragging.hover({ element: process, gfx: processGfx });
|
||||||
|
|
||||||
// then
|
// then
|
||||||
var defaultSize = elementFactory._getDefaultSize(participantBo);
|
var defaultSize = elementFactory.getDefaultSize(participant);
|
||||||
|
|
||||||
expect(participant.width).to.equal(defaultSize.width);
|
expect(participant.width).to.equal(defaultSize.width);
|
||||||
expect(participant.height).to.equal(defaultSize.height);
|
expect(participant.height).to.equal(defaultSize.height);
|
||||||
|
|
Loading…
Reference in New Issue