fix(modeling): correct initial label positioning

This commit is contained in:
Nico Rehwaldt 2014-08-03 14:30:53 +02:00
parent 9bf74c95e6
commit b1663db035
3 changed files with 61 additions and 24 deletions

View File

@ -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) {

View File

@ -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({

View File

@ -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,7 +87,35 @@ describe('features/modeling - append shape', function() {
}));
it('should add shape label', inject(function(elementRegistry, modeling, commandStack) {
describe('should add external label', function() {
it('correctly wired and positioned', 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;
var label = targetShape.label;
// 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');
@ -98,9 +129,6 @@ describe('features/modeling - append shape', function() {
target = targetShape.businessObject;
// then
expect(targetShape.label).toBeDefined();
expect(elementRegistry.getById(targetShape.label.id)).toBeDefined();
expect(target.di.label).toBeDefined();
expect(target.di.label.bounds.x).toBe(targetShape.label.x);
@ -109,6 +137,8 @@ describe('features/modeling - append shape', function() {
expect(target.di.label.bounds.height).toBe(targetShape.label.height);
}));
});
it('should add connection', inject(function(elementRegistry, modeling) {