Skip to content

Commit b4bda4e

Browse files
committed
also look for other alignment periods when a period point wins
1 parent e15da90 commit b4bda4e

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

src/components/fx/hover.js

+42-4
Original file line numberDiff line numberDiff line change
@@ -651,10 +651,48 @@ function _hover(gd, evt, subplot, noHoverEvent) {
651651
) {
652652
var winningPoint = hoverData[0];
653653

654-
findHoverPoints(
655-
customVal('x', winningPoint, fullLayout),
656-
customVal('y', winningPoint, fullLayout)
657-
);
654+
var customXVal = customVal('x', winningPoint, fullLayout);
655+
var customYVal = customVal('y', winningPoint, fullLayout);
656+
657+
findHoverPoints(customXVal, customYVal);
658+
659+
// also find start, middle and end point for period
660+
var axLetter = hovermode.charAt(0);
661+
if(winningPoint.trace[axLetter + 'period']) {
662+
var initLen = hoverData.length;
663+
664+
var v = winningPoint[axLetter + 'LabelVal'];
665+
var ax = winningPoint[axLetter + 'a'];
666+
var T = {};
667+
T[axLetter + 'period'] = winningPoint.trace[axLetter + 'period'];
668+
T[axLetter + 'period0'] = winningPoint.trace[axLetter + 'period0'];
669+
670+
T[axLetter + 'periodalignment'] = 'start';
671+
var start = alignPeriod(T, ax, axLetter, [v])[0];
672+
673+
T[axLetter + 'periodalignment'] = 'middle';
674+
var middle = alignPeriod(T, ax, axLetter, [v])[0];
675+
676+
T[axLetter + 'periodalignment'] = 'end';
677+
var end = alignPeriod(T, ax, axLetter, [v])[0];
678+
679+
if(axLetter === 'x') {
680+
findHoverPoints(start, customYVal);
681+
findHoverPoints(middle, customYVal);
682+
findHoverPoints(end, customYVal);
683+
} else {
684+
findHoverPoints(customXVal, start);
685+
findHoverPoints(customXVal, middle);
686+
findHoverPoints(customXVal, end);
687+
}
688+
689+
// remove non-period aditions
690+
for(var k = hoverData.length - 1; k >= initLen; k--) {
691+
if(!hoverData[k].trace[axLetter + 'period']) {
692+
hoverData.splice(k, 1);
693+
}
694+
}
695+
}
658696

659697
// Remove duplicated hoverData points
660698
// note that d3 also filters identical points in the rendering steps

0 commit comments

Comments
 (0)