8000 use winning point coords to pickup other points · plotly/plotly.js@520dc80 · GitHub
[go: up one dir, main page]

Skip to content

Commit 520dc80

Browse files
committed
use winning point coords to pickup other points
1 parent c24e12e commit 520dc80

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

src/components/fx/hover.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -643,49 +643,49 @@ function _hover(gd, evt, subplot, noHoverEvent) {
643643
}
644644
}
645645

646-
hoverData.sort(function(d1, d2) { return d1.distance - d2.distance; });
646+
var sortHoverData = function() {
647+
hoverData.sort(function(d1, d2) { return d1.distance - d2.distance; });
647648

648-
// move period positioned points and box/bar-like traces to the end of the list
649-
hoverData = orderRangePoints(hoverData, hovermode);
649+
// move period positioned points and box/bar-like traces to the end of the list
650+
hoverData = orderRangePoints(hoverData, hovermode);
651+
};
652+
sortHoverData();
650653

651654
// If in compare mode, select every point at position
652655
if(
653656
helpers.isXYhover(_mode) &&
654657
hoverData[0].length !== 0 &&
655658
hoverData[0].trace.type !== 'splom' // TODO: add support for splom
656659
) {
657-
var initLen = hoverData.length;
658660
var winningPoint = hoverData[0];
659661

660662
var customXVal = customVal('x', winningPoint, fullLayout);
661663
var customYVal = customVal('y', winningPoint, fullLayout);
662664

663665
findHoverPoints(customXVal, customYVal);
664666

665-
var k;
667+
var finalPoints = [];
666668
var seen = {};
667-
for(k = 0; k < initLen; k++) {
668-
seen[hoverData[k].trace.index] = true;
669-
}
670-
671-
// remove aditions and traces that seen before
672-
for(k = hoverData.length - 1; k >= initLen; k--) {
673-
if(
674-
seen[hoverData[k].trace.index]
675-
) {
676-
hoverData.splice(k, 1);
669+
var insert = function(hd) {
670+
var type = hd.trace.type;
671+
var key = (
672+
type === 'ohlc' ||
673+
type === 'candlestick'
674+
) ? hoverDataKey(hd) : hd.trace.index;
675+
if(!seen[key]) {
676+
seen[key] = true;
677+
finalPoints.push(hd);
677678
}
678-
}
679+
};
679680

680-
// Remove duplicated hoverData points
681-
var repeated = {};
682-
hoverData = hoverData.filter(function(hd) {
683-
var key = hoverDataKey(hd);
684-
if(!repeated[key]) {
685-
repeated[key] = true;
686-
return repeated[key];
687-
}
688-
});
681+
// insert the winnig point first
682+
insert(winningPoint);
683+
// override from the end
684+
for(var k = hoverData.length - 1; k > 0; k--) {
685+
insert(hoverData[k]);
686+
}
687+
hoverData = finalPoints;
688+
sortHoverData();
689689
}
690690

691691
// lastly, emit custom hover/unhover events

0 commit comments

Comments
 (0)
0