Skip to content

Commit 5e252a3

Browse files
committed
fix: correct date axis timezone in hoveranywhere/clickanywhere events
Fixes #7816.
1 parent 067ce36 commit 5e252a3

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

src/components/fx/hover.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,28 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) {
467467
evt.pointerY = ypx + yaArray[0]._offset;
468468

469469
if ('xval' in evt) xvalArray = helpers.flat(subplots, evt.xval);
470-
else xvalArray = helpers.p2c(xaArray, xpx);
470+
else {
471+
xvalArray = helpers.p2c(xaArray, xpx);
472+
// p2c on date axes returns a display-time value (local-time components
473+
// encoded as UTC ms), which differs from the true UTC coordinate used
474+
// by data points. Correct back to true UTC so event consumers receive
475+
// values consistent with trace data and axis range. See #7816.
476+
for(var i = 0; i < xaArray.length; i++) {
477+
if(xaArray[i].type === 'date' && isNumeric(xvalArray[i])) {
478+
xvalArray[i] = xvalArray[i] + new Date(xvalArray[i]).getTimezoneOffset() * 60000;
479+
}
480+
}
481+
}
471482

472483
if ('yval' in evt) yvalArray = helpers.flat(subplots, evt.yval);
473-
else yvalArray = helpers.p2c(yaArray, ypx);
484+
else {
485+
yvalArray = helpers.p2c(yaArray, ypx);
486+
for(var i = 0; i < yaArray.length; i++) {
487+
if(yaArray[i].type === 'date' && isNumeric(yvalArray[i])) {
488+
yvalArray[i] = yvalArray[i] + new Date(yvalArray[i]).getTimezoneOffset() * 60000;
489+
}
490+
}
491+
}
474492

475493
if (!isNumeric(xvalArray[0]) || !isNumeric(yvalArray[0])) {
476494
Lib.warn('Fx.hover failed', evt, gd);

0 commit comments

Comments
 (0)