diff --git a/lib/features/modeling/ElementFactory.js b/lib/features/modeling/ElementFactory.js index ee8abc1f..e45478cd 100644 --- a/lib/features/modeling/ElementFactory.js +++ b/lib/features/modeling/ElementFactory.js @@ -4,6 +4,8 @@ var _ = require('lodash'); var BaseElementFactory = require('diagram-js/lib/core/ElementFactory'); +var LabelUtil = require('../../util/Label'); + /** * A bpmn-aware factory for diagram-js shapes @@ -61,7 +63,9 @@ ElementFactory.prototype.createRoot = function(attrs) { }; ElementFactory.prototype.createLabel = function(attrs) { - return this.create('label', _.extend({ type: 'label' }, attrs)); + return this.create('label', _.extend({ + type: 'label' + }, LabelUtil.DEFAULT_LABEL_SIZE, attrs)); }; ElementFactory.prototype.createShape = function(attrs) { diff --git a/lib/util/Label.js b/lib/util/Label.js index 2412a53f..c40c01ab 100644 --- a/lib/util/Label.js +++ b/lib/util/Label.js @@ -3,6 +3,12 @@ var _ = require('lodash'); +var DEFAULT_LABEL_SIZE = module.exports.DEFAULT_LABEL_SIZE = { + width: 90, + height: 50 +}; + + /** * Returns true if the given semantic has an external label * @@ -47,7 +53,7 @@ var getExternalLabelMid = module.exports.getExternalLabelMid = function(element) } else { return { x: element.x + element.width / 2, - y: element.y + element.height - 5 + y: element.y + element.height + DEFAULT_LABEL_SIZE.height / 2 - 5 }; } }; @@ -83,10 +89,7 @@ module.exports.getExternalLabelBounds = function(semantic, element) { mid = getExternalLabelMid(element); - size = { - width: 90, - height: 50 - }; + size = DEFAULT_LABEL_SIZE; } return _.extend({ diff --git a/test/spec/features/modeling/AppendShapeSpec.js b/test/spec/features/modeling/AppendShapeSpec.js index 63d3d8fd..8afcf1f4 100644 --- a/test/spec/features/modeling/AppendShapeSpec.js +++ b/test/spec/features/modeling/AppendShapeSpec.js @@ -13,6 +13,9 @@ var modelingModule = require('../../../../lib/features/modeling'), drawModule = require('../../../../lib/draw'); +var LabelUtil = require('../../../../lib/util/Label'); + + describe('features/modeling - append shape', function() { beforeEach(Matchers.addDeepEquals); @@ -84,30 +87,57 @@ describe('features/modeling - append shape', function() { })); - it('should add shape label', inject(function(elementRegistry, modeling, commandStack) { + describe('should add external label', function() { - // given - var startEventShape = elementRegistry.getById('StartEvent_1'); - var subProcessShape = elementRegistry.getById('SubProcess_1'); + it('correctly wired and positioned', inject(function(elementRegistry, modeling, commandStack) { - var startEvent = startEventShape.businessObject, - subProcess = subProcessShape.businessObject; + // given + var startEventShape = elementRegistry.getById('StartEvent_1'); + var subProcessShape = elementRegistry.getById('SubProcess_1'); - // when - var targetShape = modeling.appendFlowNode(startEventShape, 'bpmn:EndEvent'), - target = targetShape.businessObject; + var startEvent = startEventShape.businessObject, + subProcess = subProcessShape.businessObject; - // then - expect(targetShape.label).toBeDefined(); - expect(elementRegistry.getById(targetShape.label.id)).toBeDefined(); + // when + var targetShape = modeling.appendFlowNode(startEventShape, 'bpmn:EndEvent'), + target = targetShape.businessObject; - expect(target.di.label).toBeDefined(); + var label = targetShape.label; - expect(target.di.label.bounds.x).toBe(targetShape.label.x); - expect(target.di.label.bounds.y).toBe(targetShape.label.y); - expect(target.di.label.bounds.width).toBe(targetShape.label.width); - expect(target.di.label.bounds.height).toBe(targetShape.label.height); - })); + // then + expect(label).toBeDefined(); + expect(elementRegistry.getById(label.id)).toBeDefined(); + + expect(label.x).toBe(443); + expect(label.y).toBe(273); + expect(label.width).toBe(LabelUtil.DEFAULT_LABEL_SIZE.width); + expect(label.height).toBe(LabelUtil.DEFAULT_LABEL_SIZE.height); + })); + + + it('with di', inject(function(elementRegistry, modeling, commandStack) { + + // given + var startEventShape = elementRegistry.getById('StartEvent_1'); + var subProcessShape = elementRegistry.getById('SubProcess_1'); + + var startEvent = startEventShape.businessObject, + subProcess = subProcessShape.businessObject; + + // when + var targetShape = modeling.appendFlowNode(startEventShape, 'bpmn:EndEvent'), + target = targetShape.businessObject; + + // then + expect(target.di.label).toBeDefined(); + + expect(target.di.label.bounds.x).toBe(targetShape.label.x); + expect(target.di.label.bounds.y).toBe(targetShape.label.y); + expect(target.di.label.bounds.width).toBe(targetShape.label.width); + expect(target.di.label.bounds.height).toBe(targetShape.label.height); + })); + + }); it('should add connection', inject(function(elementRegistry, modeling) {