Skip to content

Commit 756f498

Browse files
committed
refactor insert function in hover.js
1 parent 12f199a commit 756f498

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/components/fx/hover.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -667,28 +667,29 @@ function _hover(gd, evt, subplot, noHoverEvent) {
667667
var finalPoints = [];
668668
var seen = {};
669669
var id = 0;
670-
var insert = function(hd) {
671-
var type = hd.trace.type;
670+
var insert = function(newHd) {
671+
var type = newHd.trace.type;
672672
var multiplePoints = (
673673
type === 'box' ||
674674
type === 'violin' ||
675675
type === 'ohlc' ||
676676
type === 'candlestick'
677677
);
678678

679-
var key = multiplePoints ? hoverDataKey(hd) : hd.trace.index;
679+
var key = multiplePoints ? hoverDataKey(newHd) : newHd.trace.index;
680680
if(!seen[key]) {
681681
id++;
682682
seen[key] = id;
683-
finalPoints.push(hd);
683+
finalPoints.push(newHd);
684684
} else {
685685
var oldId = seen[key] - 1;
686+
var oldHd = finalPoints[oldId];
686687
if(
687-
Math.abs(winningPoint.distance - hd.distance) <
688-
Math.abs(winningPoint.distance - finalPoints[oldId].distance)
688+
Math.abs(winningPoint.distance - newHd.distance) <
689+
Math.abs(winningPoint.distance - oldHd.distance)
689690
) {
690691
// replace with closest
691-
finalPoints[oldId] = hd;
692+
finalPoints[oldId] = newHd;
692693
}
693694
}
694695
};

0 commit comments

Comments
 (0)