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 BaseElementFactory = require('diagram-js/lib/core/ElementFactory');
|
||||||
|
|
||||||
|
var LabelUtil = require('../../util/Label');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A bpmn-aware factory for diagram-js shapes
|
* A bpmn-aware factory for diagram-js shapes
|
||||||
|
@ -61,7 +63,9 @@ ElementFactory.prototype.createRoot = function(attrs) {
|
||||||
};
|
};
|
||||||
|
|
||||||
ElementFactory.prototype.createLabel = 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) {
|
ElementFactory.prototype.createShape = function(attrs) {
|
||||||
|
|
|
@ -3,6 +3,12 @@
|
||||||
var _ = require('lodash');
|
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
|
* Returns true if the given semantic has an external label
|
||||||
*
|
*
|
||||||
|
@ -47,7 +53,7 @@ var getExternalLabelMid = module.exports.getExternalLabelMid = function(element)
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
x: element.x + element.width / 2,
|
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);
|
mid = getExternalLabelMid(element);
|
||||||
|
|
||||||
size = {
|
size = DEFAULT_LABEL_SIZE;
|
||||||
width: 90,
|
|
||||||
height: 50
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return _.extend({
|
return _.extend({
|
||||||
|
|
|
@ -13,6 +13,9 @@ var modelingModule = require('../../../../lib/features/modeling'),
|
||||||
drawModule = require('../../../../lib/draw');
|
drawModule = require('../../../../lib/draw');
|
||||||
|
|
||||||
|
|
||||||
|
var LabelUtil = require('../../../../lib/util/Label');
|
||||||
|
|
||||||
|
|
||||||
describe('features/modeling - append shape', function() {
|
describe('features/modeling - append shape', function() {
|
||||||
|
|
||||||
beforeEach(Matchers.addDeepEquals);
|
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
|
it('correctly wired and positioned', inject(function(elementRegistry, modeling, commandStack) {
|
||||||
var startEventShape = elementRegistry.getById('StartEvent_1');
|
|
||||||
var subProcessShape = elementRegistry.getById('SubProcess_1');
|
|
||||||
|
|
||||||
var startEvent = startEventShape.businessObject,
|
// given
|
||||||
subProcess = subProcessShape.businessObject;
|
var startEventShape = elementRegistry.getById('StartEvent_1');
|
||||||
|
var subProcessShape = elementRegistry.getById('SubProcess_1');
|
||||||
|
|
||||||
// when
|
var startEvent = startEventShape.businessObject,
|
||||||
var targetShape = modeling.appendFlowNode(startEventShape, 'bpmn:EndEvent'),
|
subProcess = subProcessShape.businessObject;
|
||||||
target = targetShape.businessObject;
|
|
||||||
|
|
||||||
// then
|
// when
|
||||||
expect(targetShape.label).toBeDefined();
|
var targetShape = modeling.appendFlowNode(startEventShape, 'bpmn:EndEvent'),
|
||||||
expect(elementRegistry.getById(targetShape.label.id)).toBeDefined();
|
target = targetShape.businessObject;
|
||||||
|
|
||||||
expect(target.di.label).toBeDefined();
|
var label = targetShape.label;
|
||||||
|
|
||||||
expect(target.di.label.bounds.x).toBe(targetShape.label.x);
|
// then
|
||||||
expect(target.di.label.bounds.y).toBe(targetShape.label.y);
|
expect(label).toBeDefined();
|
||||||
expect(target.di.label.bounds.width).toBe(targetShape.label.width);
|
expect(elementRegistry.getById(label.id)).toBeDefined();
|
||||||
expect(target.di.label.bounds.height).toBe(targetShape.label.height);
|
|
||||||
}));
|
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) {
|
it('should add connection', inject(function(elementRegistry, modeling) {
|
||||||
|
|
Loading…
Reference in New Issue