fix(modeling/behavior): round label move adjustment

Ensure we don't return floating point numbers for conection label
adjustments calculated on connection changes.
This commit is contained in:
Nico Rehwaldt 2017-12-13 14:20:19 +01:00
parent a708a1cd4e
commit 1333479815
2 changed files with 14 additions and 9 deletions

View File

@ -1,11 +1,13 @@
'use strict';
var GeometricUtil = require('./GeometricUtil');
var getDistancePointPoint = require('./GeometricUtil').getDistancePointPoint;
var getDistancePointPoint = require('./GeometricUtil').getDistancePointPoint,
rotateVector = require('./GeometricUtil').rotateVector,
getAngle = require('./GeometricUtil').getAngle;
var getAttachment = require('./LineAttachmentUtil').getAttachment;
var roundPoint = require('diagram-js/lib/layout/LayoutUtil').roundPoint;
function findNewLabelLineStartIndex(oldWaypoints, newWaypoints, attachment, hints) {
@ -164,7 +166,7 @@ function getLabelAdjustment(label, newWaypoints, oldWaypoints, hints) {
};
// the rotated vector to label
var newLabelVector = GeometricUtil.rotateVector({
var newLabelVector = rotateVector({
x: labelPosition.x - oldFoot.x,
y: labelPosition.y - oldFoot.y
}, angleDelta);
@ -173,7 +175,10 @@ function getLabelAdjustment(label, newWaypoints, oldWaypoints, hints) {
x = newFoot.x + newLabelVector.x - labelPosition.x;
y = newFoot.y + newLabelVector.y - labelPosition.y;
return { x: x, y: y };
return roundPoint({
x: x,
y: y
});
}
module.exports.getLabelAdjustment = getLabelAdjustment;
@ -200,8 +205,8 @@ function getLabelMid(label) {
}
function getAngleDelta(l1, l2) {
var a1 = GeometricUtil.getAngle(l1),
a2 = GeometricUtil.getAngle(l2);
var a1 = getAngle(l1),
a2 = getAngle(l2);
return a2 - a1;
}

View File

@ -416,8 +416,8 @@ describe('modeling - label layouting', function() {
dragging.end();
// then
expect(Math.round(connection.label.x)).to.be.within(240, 242);
expect(Math.round(connection.label.y)).to.be.equal(148);
expect(connection.label.x).to.be.within(240, 242);
expect(connection.label.y).to.be.within(148, 149);
}
));