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:
parent
a708a1cd4e
commit
1333479815
|
@ -1,11 +1,13 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var GeometricUtil = require('./GeometricUtil');
|
var getDistancePointPoint = require('./GeometricUtil').getDistancePointPoint,
|
||||||
|
rotateVector = require('./GeometricUtil').rotateVector,
|
||||||
var getDistancePointPoint = require('./GeometricUtil').getDistancePointPoint;
|
getAngle = require('./GeometricUtil').getAngle;
|
||||||
|
|
||||||
var getAttachment = require('./LineAttachmentUtil').getAttachment;
|
var getAttachment = require('./LineAttachmentUtil').getAttachment;
|
||||||
|
|
||||||
|
var roundPoint = require('diagram-js/lib/layout/LayoutUtil').roundPoint;
|
||||||
|
|
||||||
|
|
||||||
function findNewLabelLineStartIndex(oldWaypoints, newWaypoints, attachment, hints) {
|
function findNewLabelLineStartIndex(oldWaypoints, newWaypoints, attachment, hints) {
|
||||||
|
|
||||||
|
@ -164,7 +166,7 @@ function getLabelAdjustment(label, newWaypoints, oldWaypoints, hints) {
|
||||||
};
|
};
|
||||||
|
|
||||||
// the rotated vector to label
|
// the rotated vector to label
|
||||||
var newLabelVector = GeometricUtil.rotateVector({
|
var newLabelVector = rotateVector({
|
||||||
x: labelPosition.x - oldFoot.x,
|
x: labelPosition.x - oldFoot.x,
|
||||||
y: labelPosition.y - oldFoot.y
|
y: labelPosition.y - oldFoot.y
|
||||||
}, angleDelta);
|
}, angleDelta);
|
||||||
|
@ -173,7 +175,10 @@ function getLabelAdjustment(label, newWaypoints, oldWaypoints, hints) {
|
||||||
x = newFoot.x + newLabelVector.x - labelPosition.x;
|
x = newFoot.x + newLabelVector.x - labelPosition.x;
|
||||||
y = newFoot.y + newLabelVector.y - labelPosition.y;
|
y = newFoot.y + newLabelVector.y - labelPosition.y;
|
||||||
|
|
||||||
return { x: x, y: y };
|
return roundPoint({
|
||||||
|
x: x,
|
||||||
|
y: y
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.getLabelAdjustment = getLabelAdjustment;
|
module.exports.getLabelAdjustment = getLabelAdjustment;
|
||||||
|
@ -200,8 +205,8 @@ function getLabelMid(label) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAngleDelta(l1, l2) {
|
function getAngleDelta(l1, l2) {
|
||||||
var a1 = GeometricUtil.getAngle(l1),
|
var a1 = getAngle(l1),
|
||||||
a2 = GeometricUtil.getAngle(l2);
|
a2 = getAngle(l2);
|
||||||
return a2 - a1;
|
return a2 - a1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -416,8 +416,8 @@ describe('modeling - label layouting', function() {
|
||||||
dragging.end();
|
dragging.end();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(Math.round(connection.label.x)).to.be.within(240, 242);
|
expect(connection.label.x).to.be.within(240, 242);
|
||||||
expect(Math.round(connection.label.y)).to.be.equal(148);
|
expect(connection.label.y).to.be.within(148, 149);
|
||||||
|
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
Loading…
Reference in New Issue