fix(modeling): correct initial label positioning
This commit is contained in:
parent
9bf74c95e6
commit
b1663db035
|
@ -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) {
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue