fix(draw/BpmnRenderer): ensure labels keep position if width doesn't change
* adjust positioning tests to pass on Arch Linux Closes #613
This commit is contained in:
parent
5441b2e09e
commit
f4023cf321
|
@ -1277,7 +1277,7 @@ function BpmnRenderer(eventBus, styles, pathMap, priority) {
|
|||
|
||||
// update element.x so that the layouted text is still
|
||||
// center alligned (newX = oldMidX - newWidth / 2)
|
||||
element.x = Math.round(element.x + element.width / 2) - Math.round((textBBox.width / 2));
|
||||
element.x = Math.ceil(element.x + element.width / 2) - Math.ceil((textBBox.width / 2));
|
||||
|
||||
// take element width, height from actual bounds
|
||||
element.width = Math.ceil(textBBox.width);
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
var TestContainer = require('mocha-test-container-support');
|
||||
|
||||
var TestHelper = require('../../../TestHelper');
|
||||
|
||||
/* global bootstrapViewer, inject */
|
||||
|
@ -513,12 +511,6 @@ describe('features - label-editing', function() {
|
|||
|
||||
describe('zoom', function() {
|
||||
|
||||
var container;
|
||||
|
||||
beforeEach(function() {
|
||||
container = TestContainer.get(this);
|
||||
});
|
||||
|
||||
it('should have fixed dimensions (low zoom)', testTextboxSizing('empty-task', 0.5, 100, 80, oneWord));
|
||||
|
||||
it('should have fixed dimensions (high zoom)', testTextboxSizing('empty-task', 1.5, 150, 120, oneWord));
|
||||
|
@ -526,7 +518,7 @@ describe('features - label-editing', function() {
|
|||
it('should center text box position (low zoom)', inject(function(canvas, elementRegistry, directEditing) {
|
||||
|
||||
// given
|
||||
canvas.zoom(0.5);
|
||||
canvas.zoom(0.5, { x: 0, y: 0 });
|
||||
|
||||
var shape = elementRegistry.get('empty-task');
|
||||
|
||||
|
@ -534,17 +526,10 @@ describe('features - label-editing', function() {
|
|||
directEditing.activate(shape);
|
||||
|
||||
// then
|
||||
var textbox = directEditing._textbox,
|
||||
gfx = elementRegistry.getGraphics('empty-task'),
|
||||
shapeClientRect = gfx.node.parentNode.getBoundingClientRect();
|
||||
var textbox = directEditing._textbox;
|
||||
|
||||
var shapeRect = {
|
||||
top: shapeClientRect.top - container.offsetTop,
|
||||
left: shapeClientRect.left - container.offsetLeft
|
||||
};
|
||||
|
||||
expect(textbox.content.offsetLeft).to.be.within(shapeRect.left - 28, shapeRect.left - 22);
|
||||
expect(textbox.content.offsetTop).to.be.within(shapeRect.top - 22, shapeRect.top - 17);
|
||||
expect(textbox.content.offsetLeft).to.equal(211);
|
||||
expect(textbox.content.offsetTop).to.equal(17);
|
||||
|
||||
}));
|
||||
|
||||
|
|
|
@ -108,9 +108,9 @@ describe('label bounds', function() {
|
|||
describe('label position', function() {
|
||||
|
||||
var getExpectedX = function(shape) {
|
||||
var shapeMid = shape.x + shape.width/2;
|
||||
var shapeMid = shape.x + Math.ceil(shape.width/2);
|
||||
|
||||
return Math.round(shapeMid - shape.label.width/2);
|
||||
return shapeMid - Math.ceil(shape.label.width/2);
|
||||
};
|
||||
|
||||
it('should shift to left', inject(function(elementRegistry) {
|
||||
|
@ -124,7 +124,7 @@ describe('label bounds', function() {
|
|||
// then
|
||||
var expectedX = getExpectedX(shape);
|
||||
|
||||
expect(shape.label.x).to.be.within(expectedX - 1, expectedX);
|
||||
expect(shape.label.x).to.equal(expectedX);
|
||||
}));
|
||||
|
||||
|
||||
|
@ -139,7 +139,25 @@ describe('label bounds', function() {
|
|||
// then
|
||||
var expectedX = getExpectedX(shape);
|
||||
|
||||
expect(shape.label.x).to.be.within(expectedX -1, expectedX);
|
||||
expect(shape.label.x).to.equal(expectedX);
|
||||
}));
|
||||
|
||||
|
||||
it('should remain the same', inject(function(elementRegistry) {
|
||||
|
||||
// given
|
||||
var shape = elementRegistry.get('StartEvent_1');
|
||||
|
||||
// when
|
||||
updateLabel(shape, 'FOOBAR');
|
||||
|
||||
// copy old horizontal label position
|
||||
var oldX = shape.label.x + 0;
|
||||
|
||||
updateLabel(shape, 'FOOBAR\n1');
|
||||
|
||||
// then
|
||||
expect(shape.label.x).to.equal(oldX);
|
||||
}));
|
||||
|
||||
});
|
||||
|
|
|
@ -309,7 +309,7 @@ describe('modeling - label layouting', function() {
|
|||
dragging.end();
|
||||
|
||||
// then
|
||||
expect(Math.round(connection.label.x)).to.be.equal(467);
|
||||
expect(Math.round(connection.label.x)).to.be.within(467, 468);
|
||||
expect(Math.round(connection.label.y)).to.be.within(170, 171);
|
||||
|
||||
}));
|
||||
|
@ -502,7 +502,7 @@ describe('modeling - label layouting', function() {
|
|||
dragging.end();
|
||||
|
||||
// then
|
||||
expect(connection.label.y - labelPosition.y).to.be.within(-76, -72);
|
||||
expect(connection.label.y - labelPosition.y).to.be.within(-76, -70);
|
||||
expect(connection.label.x - labelPosition.x).to.be.within(-53, -51);
|
||||
|
||||
}));
|
||||
|
|
|
@ -51,12 +51,12 @@ describe('import - labels', function() {
|
|||
expect(endEvent.label.x).to.be.within(236, 237);
|
||||
expect(endEvent.label.y).to.be.within(256, 256);
|
||||
expect(endEvent.label.width).to.be.within(68, 69);
|
||||
expect(endEvent.label.height).to.be.within(25, 30);
|
||||
expect(endEvent.label.height).to.be.within(23, 30);
|
||||
|
||||
expect(sequenceFlow.label.x).to.be.within(441, 442);
|
||||
expect(sequenceFlow.label.y).to.be.within(316, 317);
|
||||
expect(sequenceFlow.label.width).to.be.within(79, 82);
|
||||
expect(sequenceFlow.label.height).to.be.within(13, 15);
|
||||
expect(sequenceFlow.label.height).to.be.within(11, 15);
|
||||
|
||||
done();
|
||||
})();
|
||||
|
|
Loading…
Reference in New Issue