From 1333479815ff0803762133d369e28d8428a66563 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Wed, 13 Dec 2017 14:20:19 +0100 Subject: [PATCH] fix(modeling/behavior): round label move adjustment Ensure we don't return floating point numbers for conection label adjustments calculated on connection changes. --- .../modeling/behavior/util/LabelLayoutUtil.js | 19 ++++++++++++------- .../features/modeling/LabelLayoutingSpec.js | 4 ++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/features/modeling/behavior/util/LabelLayoutUtil.js b/lib/features/modeling/behavior/util/LabelLayoutUtil.js index 0f41022f..318d6796 100644 --- a/lib/features/modeling/behavior/util/LabelLayoutUtil.js +++ b/lib/features/modeling/behavior/util/LabelLayoutUtil.js @@ -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; } diff --git a/test/spec/features/modeling/LabelLayoutingSpec.js b/test/spec/features/modeling/LabelLayoutingSpec.js index 512efa68..3e154a99 100644 --- a/test/spec/features/modeling/LabelLayoutingSpec.js +++ b/test/spec/features/modeling/LabelLayoutingSpec.js @@ -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); } ));