From 82321b3496bee84846e47e999619f8a6a374d810 Mon Sep 17 00:00:00 2001 From: David Benson Date: Wed, 11 Nov 2020 12:44:27 +0000 Subject: [PATCH] https://github.com/jgraph/mxgraph/issues/510 Fix for https://github.com/jgraph/mxgraph/issues/510 --- javascript/src/js/view/mxGraphView.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/javascript/src/js/view/mxGraphView.js b/javascript/src/js/view/mxGraphView.js index 49c95e665..640dc7e52 100644 --- a/javascript/src/js/view/mxGraphView.js +++ b/javascript/src/js/view/mxGraphView.js @@ -2099,29 +2099,27 @@ mxGraphView.prototype.getRelativePoint = function(edgeState, x, y) var totalLength = edgeState.length; var segments = edgeState.segments; - // Works which line segment the point of the label is closest to + // Works out which line segment the point of the label is closest to var p0 = edgeState.absolutePoints[0]; var pe = edgeState.absolutePoints[1]; var minDist = mxUtils.ptSegDistSq(p0.x, p0.y, pe.x, pe.y, x, y); - + var length = 0; var index = 0; var tmp = 0; - var length = 0; for (var i = 2; i < pointCount; i++) { - tmp += segments[i - 2]; + p0 = pe; pe = edgeState.absolutePoints[i]; var dist = mxUtils.ptSegDistSq(p0.x, p0.y, pe.x, pe.y, x, y); - + tmp += segments[i - 2]; + if (dist <= minDist) { minDist = dist; index = i - 1; length = tmp; } - - p0 = pe; } var seg = segments[index];