From 01b4836d37b07157872864f986afcb6cbadc5033 Mon Sep 17 00:00:00 2001 From: archmoj Date: Wed, 28 Jul 2021 20:00:19 +0200 Subject: [PATCH 01/14] clear special handling for bars and scatter --- src/components/fx/hover.js | 5 +---- src/traces/bar/hover.js | 3 --- src/traces/scatter/hover.js | 3 --- src/traces/scattergl/hover.js | 3 --- 4 files changed, 1 insertion(+), 13 deletions(-) diff --git a/src/components/fx/hover.js b/src/components/fx/hover.js index 7773787fc73..fb39f8b337a 100644 --- a/src/components/fx/hover.js +++ b/src/components/fx/hover.js @@ -1994,10 +1994,7 @@ function getCoord(axLetter, winningPoint, fullLayout) { var val = winningPoint[axLetter + 'Val']; if(ax.type === 'category') val = ax._categoriesMap[val]; - else if(ax.type === 'date') { - var period = winningPoint[axLetter + 'Period']; - val = ax.d2c(period !== undefined ? period : val); - } + else if(ax.type === 'date') val = ax.d2c(val); var cd0 = winningPoint.cd[winningPoint.index]; if(cd0 && cd0.t && cd0.t.posLetter === ax._id) { diff --git a/src/traces/bar/hover.js b/src/traces/bar/hover.js index 55605428ac0..2229c7e6d39 100644 --- a/src/traces/bar/hover.js +++ b/src/traces/bar/hover.js @@ -179,9 +179,6 @@ function hoverOnBars(pointData, xval, yval, hovermode, opts) { var hasPeriod = di.orig_p !== undefined; pointData[posLetter + 'LabelVal'] = hasPeriod ? di.orig_p : di.p; - if(hasPeriod) { - pointData[posLetter + 'Period'] = di.p; - } pointData.labelLabel = hoverLabelText(pa, pointData[posLetter + 'LabelVal'], trace[posLetter + 'hoverformat']); pointData.valueLabel = hoverLabelText(sa, pointData[sizeLetter + 'LabelVal'], trace[sizeLetter + 'hoverformat']); diff --git a/src/traces/scatter/hover.js b/src/traces/scatter/hover.js index 682d1a474d0..c86a5b902f8 100644 --- a/src/traces/scatter/hover.js +++ b/src/traces/scatter/hover.js @@ -112,9 +112,6 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) { hovertemplate: trace.hovertemplate }); - if(trace.xperiodalignment === 'end') pointData.xPeriod = di.x; - if(trace.yperiodalignment === 'end') pointData.yPeriod = di.y; - fillText(di, trace, pointData); Registry.getComponentMethod('errorbars', 'hoverInfo')(di, trace, pointData); diff --git a/src/traces/scattergl/hover.js b/src/traces/scattergl/hover.js index adf39744e01..41e25458f6f 100644 --- a/src/traces/scattergl/hover.js +++ b/src/traces/scattergl/hover.js @@ -202,9 +202,6 @@ function calcHover(pointData, x, y, trace) { hovertemplate: di.ht }); - if(trace.xperiodalignment === 'end') pointData2.xPeriod = di.x; - if(trace.yperiodalignment === 'end') pointData2.yPeriod = di.y; - if(di.htx) pointData2.text = di.htx; else if(di.tx) pointData2.text = di.tx; else if(trace.text) pointData2.text = trace.text; From 585ddbd31e238072225d9365f65fddedae88862b Mon Sep 17 00:00:00 2001 From: archmoj Date: Wed, 28 Jul 2021 14:43:48 -0400 Subject: [PATCH 02/14] new fix to work in different time zones --- src/components/fx/hover.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/components/fx/hover.js b/src/components/fx/hover.js index fb39f8b337a..c6ba6326760 100644 --- a/src/components/fx/hover.js +++ b/src/components/fx/hover.js @@ -1993,16 +1993,33 @@ function getCoord(axLetter, winningPoint, fullLayout) { var ax = winningPoint[axLetter + 'a']; var val = winningPoint[axLetter + 'Val']; + var trace = winningPoint.trace; + var cd = winningPoint.cd; + var d = cd[winningPoint.index]; + if(ax.type === 'category') val = ax._categoriesMap[val]; - else if(ax.type === 'date') val = ax.d2c(val); + else if(ax.type === 'date') { + var periodalignment = trace[axLetter + 'periodalignment']; + if(periodalignment) { + var start = d[axLetter + 'Start']; + var end = d[axLetter + 'End']; + var diff = end - start; + if(periodalignment === 'end') { + val += diff; + } else if(periodalignment === 'middle') { + val += diff / 2; + } + } + + val = ax.d2c(val); + } - var cd0 = winningPoint.cd[winningPoint.index]; - if(cd0 && cd0.t && cd0.t.posLetter === ax._id) { + if(d && d.t && d.t.posLetter === ax._id) { if( fullLayout.boxmode === 'group' || fullLayout.violinmode === 'group' ) { - val += cd0.t.dPos; + val += d.t.dPos; } } From 528801a95e3cc80b53c05791ec539a77d1037f71 Mon Sep 17 00:00:00 2001 From: archmoj Date: Wed, 28 Jul 2021 15:10:59 -0400 Subject: [PATCH 03/14] adjust test --- test/jasmine/tests/hover_label_test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/jasmine/tests/hover_label_test.js b/test/jasmine/tests/hover_label_test.js index d389e54eb92..a0ae645b5a2 100644 --- a/test/jasmine/tests/hover_label_test.js +++ b/test/jasmine/tests/hover_label_test.js @@ -5433,14 +5433,14 @@ describe('hovermode: (x|y)unified', function() { } }) .then(function(gd) { - _hover(gd, { xpx: 50, ypx: 200 }); + _hover(gd, { xpx: 100, ypx: 200 }); assertLabel({title: 'Jan', items: [ 'bar : 1', 'one : 1', 'two : 1', ]}); - _hover(gd, { xpx: 350, ypx: 200 }); + _hover(gd, { xpx: 300, ypx: 200 }); assertLabel({title: 'Feb', items: [ 'bar : 2', 'one : 2', From b40091713459919fdfe521f3c969146f1e9f4bf4 Mon Sep 17 00:00:00 2001 From: archmoj Date: Wed, 28 Jul 2021 17:38:23 -0400 Subject: [PATCH 04/14] run hover label tests in different time zones --- .circleci/config.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index b030543c473..95775e99323 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -31,6 +31,35 @@ jobs: paths: - plotly.js + timezone-jasmine: + docker: + # need '-browsers' version to test in real (xvfb-wrapped) browsers + - image: circleci/node:12.22.1-browsers + working_directory: ~/plotly.js + steps: + - attach_workspace: + at: ~/ + - run: + name: Run hover_label test in UTC timezone + environment: + TZ: "UTC" + command: date && npm run test-jasmine hover_label + - run: + name: Run hover_label test in Europe/Berlin timezone + environment: + TZ: "Europe/Berlin" + command: date && npm run test-jasmine hover_label + - run: + name: Run hover_label test in Asia/Tokyo timezone + environment: + TZ: "Asia/Tokyo" + command: date && npm run test-jasmine hover_label + - run: + name: Run hover_label test in America/Toronto timezone + environment: + TZ: "America/Toronto" + command: date && npm run test-jasmine hover_label + no-gl-jasmine: docker: # need '-browsers' version to test in real (xvfb-wrapped) browsers @@ -258,6 +287,9 @@ workflows: build-and-test: jobs: - install-and-cibuild + - timezone-jasmine: + requires: + - install-and-cibuild - bundle-jasmine: requires: - install-and-cibuild From 138707c11e5d5988e48ba1be6afe674912be16d3 Mon Sep 17 00:00:00 2001 From: archmoj Date: Wed, 28 Jul 2021 17:52:38 -0400 Subject: [PATCH 05/14] log for PR 5864 --- draftlogs/5864_fix.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 draftlogs/5864_fix.md diff --git a/draftlogs/5864_fix.md b/draftlogs/5864_fix.md new file mode 100644 index 00000000000..4cb13eec9f8 --- /dev/null +++ b/draftlogs/5864_fix.md @@ -0,0 +1 @@ + - Fix period positioned hover to work in different time zones [[#5864](https://github.com/plotly/plotly.js/pull/5864)] From 21fa9885c28cc22d57d136c21928ce65045973d9 Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 29 Jul 2021 09:56:40 -0400 Subject: [PATCH 06/14] do not redefine minPos and maxPos functions for bars with period --- src/traces/bar/hover.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/traces/bar/hover.js b/src/traces/bar/hover.js index 2229c7e6d39..36599f77384 100644 --- a/src/traces/bar/hover.js +++ b/src/traces/bar/hover.js @@ -156,7 +156,7 @@ function hoverOnBars(pointData, xval, yval, hovermode, opts) { // if we get here and we're not in 'closest' mode, push min/max pos back // onto the group - even though that means occasionally the mouse will be // over the hover label. - if(!isClosest) { + if(!isClosest && !period) { minPos = function(di) { return Math.min(thisBarMinPos(di), di.p - t.bargroupwidth / 2); }; From 3bdbedb057d4506a8e2a2ec31b6c6b685ea86c18 Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 29 Jul 2021 09:59:45 -0400 Subject: [PATCH 07/14] declare and reuse a variable for isClosest or period in bar hover --- src/traces/bar/hover.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/traces/bar/hover.js b/src/traces/bar/hover.js index 36599f77384..5731fca5178 100644 --- a/src/traces/bar/hover.js +++ b/src/traces/bar/hover.js @@ -52,6 +52,7 @@ function hoverOnBars(pointData, xval, yval, hovermode, opts) { } var period = trace[posLetter + 'period']; + var isClosestOrPeriod = isClosest || period; function thisBarMinPos(di) { return thisBarExtPos(di, -1); } function thisBarMaxPos(di) { return thisBarExtPos(di, 1); } @@ -62,7 +63,7 @@ function hoverOnBars(pointData, xval, yval, hovermode, opts) { return di[posLetter] + sgn * w / 2; } - var minPos = isClosest || period ? + var minPos = isClosestOrPeriod ? thisBarMinPos : function(di) { /* @@ -80,7 +81,7 @@ function hoverOnBars(pointData, xval, yval, hovermode, opts) { return Math.min(thisBarMinPos(di), di.p - t.bardelta / 2); }; - var maxPos = isClosest || period ? + var maxPos = isClosestOrPeriod ? thisBarMaxPos : function(di) { return Math.max(thisBarMaxPos(di), di.p + t.bardelta / 2); @@ -156,7 +157,7 @@ function hoverOnBars(pointData, xval, yval, hovermode, opts) { // if we get here and we're not in 'closest' mode, push min/max pos back // onto the group - even though that means occasionally the mouse will be // over the hover label. - if(!isClosest && !period) { + if(!isClosestOrPeriod) { minPos = function(di) { return Math.min(thisBarMinPos(di), di.p - t.bargroupwidth / 2); }; From 3ba7ec7628c8cc6babe5b277501075219eb474cf Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 29 Jul 2021 11:03:27 -0400 Subject: [PATCH 08/14] fixing hover for period group bars issue 5841 --- src/traces/bar/hover.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/traces/bar/hover.js b/src/traces/bar/hover.js index 5731fca5178..3d2e155ee96 100644 --- a/src/traces/bar/hover.js +++ b/src/traces/bar/hover.js @@ -58,13 +58,17 @@ function hoverOnBars(pointData, xval, yval, hovermode, opts) { function thisBarMaxPos(di) { return thisBarExtPos(di, 1); } function thisBarExtPos(di, sgn) { - var w = (period) ? di.wPeriod : di.w; + var w = di.w; return di[posLetter] + sgn * w / 2; } - var minPos = isClosestOrPeriod ? - thisBarMinPos : + var minPos = isClosest ? + thisBarMinPos : period ? + function(di) { + var diff = di.pEnd - di.pStart; + return di.p + diff / 2 - di.wPeriod; + } : function(di) { /* * In compare mode, accept a bar if you're on it *or* its group. @@ -81,8 +85,12 @@ function hoverOnBars(pointData, xval, yval, hovermode, opts) { return Math.min(thisBarMinPos(di), di.p - t.bardelta / 2); }; - var maxPos = isClosestOrPeriod ? - thisBarMaxPos : + var maxPos = isClosest ? + thisBarMaxPos : period ? + function(di) { + var diff = di.pEnd - di.pStart; + return di.p + diff / 2; + } : function(di) { return Math.max(thisBarMaxPos(di), di.p + t.bardelta / 2); }; From 3e52b941be9b9e384a9c345bc2ab6a16076926fe Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 29 Jul 2021 11:16:32 -0400 Subject: [PATCH 09/14] look into cd0 for the case of box and violin --- src/components/fx/hover.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/fx/hover.js b/src/components/fx/hover.js index c6ba6326760..6ee92afc56f 100644 --- a/src/components/fx/hover.js +++ b/src/components/fx/hover.js @@ -2014,12 +2014,13 @@ function getCoord(axLetter, winningPoint, fullLayout) { val = ax.d2c(val); } - if(d && d.t && d.t.posLetter === ax._id) { + var cd0 = cd[0]; + if(cd0 && cd0.t && cd0.t.posLetter === ax._id) { if( fullLayout.boxmode === 'group' || fullLayout.violinmode === 'group' ) { - val += d.t.dPos; + val += cd0.t.dPos; } } From bfed46b6ffa6ec7838c17cbd84c8c67f7212c01b Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 29 Jul 2021 11:27:31 -0400 Subject: [PATCH 10/14] more strict tests to lock issue 5841 --- test/jasmine/tests/hover_label_test.js | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/jasmine/tests/hover_label_test.js b/test/jasmine/tests/hover_label_test.js index a0ae645b5a2..9ceeba1bcb2 100644 --- a/test/jasmine/tests/hover_label_test.js +++ b/test/jasmine/tests/hover_label_test.js @@ -5581,12 +5581,48 @@ describe('hovermode: (x|y)unified', function() { Plotly.newPlot(gd, fig) .then(function(gd) { + _hover(gd, { xpx: 50, ypx: 200 }); + assertLabel({title: 'Jan 1, 1970', items: [ + 'trace 0 : 11', + 'trace 1 : 1' + ]}); + _hover(gd, { xpx: 100, ypx: 200 }); assertLabel({title: 'Jan 1, 1970', items: [ 'trace 0 : 11', 'trace 1 : 1' ]}); + _hover(gd, { xpx: 150, ypx: 200 }); + assertLabel({title: 'Jul 1, 1970', items: [ + 'trace 0 : 12', + 'trace 1 : 2' + ]}); + + _hover(gd, { xpx: 200, ypx: 200 }); + assertLabel({title: 'Jul 1, 1970', items: [ + 'trace 0 : 12', + 'trace 1 : 2' + ]}); + + _hover(gd, { xpx: 250, ypx: 200 }); + assertLabel({title: 'Jul 1, 1970', items: [ + 'trace 0 : 12', + 'trace 1 : 2' + ]}); + + _hover(gd, { xpx: 300, ypx: 200 }); + assertLabel({title: 'Jan 1, 1971', items: [ + 'trace 0 : 13', + 'trace 1 : 3' + ]}); + + _hover(gd, { xpx: 350, ypx: 200 }); + assertLabel({title: 'Jan 1, 1971', items: [ + 'trace 0 : 13', + 'trace 1 : 3' + ]}); + _hover(gd, { xpx: 400, ypx: 200 }); assertLabel({title: 'Jan 1, 1971', items: [ 'trace 0 : 13', From 2c07925f074476dbf46e09eeab6bb9cf8eb95548 Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 29 Jul 2021 11:32:58 -0400 Subject: [PATCH 11/14] update PR log --- draftlogs/5864_fix.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/draftlogs/5864_fix.md b/draftlogs/5864_fix.md index 4cb13eec9f8..9d67a23be90 100644 --- a/draftlogs/5864_fix.md +++ b/draftlogs/5864_fix.md @@ -1 +1 @@ - - Fix period positioned hover to work in different time zones [[#5864](https://github.com/plotly/plotly.js/pull/5864)] + - Fix period positioned hover to work in different time zones as well as on grouped bars [[#5864](https://github.com/plotly/plotly.js/pull/5864)] From 1b7fba1562fd74cb0db798a221b5448436fd0661 Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 29 Jul 2021 12:43:48 -0400 Subject: [PATCH 12/14] bring parts of the previous logic - use (x|y)End instead of pEnd etc. --- src/components/fx/hover.js | 8 +++----- src/traces/bar/calc.js | 8 +++++--- src/traces/bar/cross_trace_calc.js | 2 +- src/traces/bar/hover.js | 10 ++++++---- src/traces/funnel/calc.js | 8 +++++--- src/traces/waterfall/calc.js | 8 +++++--- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/components/fx/hover.js b/src/components/fx/hover.js index 6ee92afc56f..386c52e8518 100644 --- a/src/components/fx/hover.js +++ b/src/components/fx/hover.js @@ -1993,14 +1993,13 @@ function getCoord(axLetter, winningPoint, fullLayout) { var ax = winningPoint[axLetter + 'a']; var val = winningPoint[axLetter + 'Val']; - var trace = winningPoint.trace; - var cd = winningPoint.cd; - var d = cd[winningPoint.index]; + var cd0 = winningPoint.cd[0]; if(ax.type === 'category') val = ax._categoriesMap[val]; else if(ax.type === 'date') { - var periodalignment = trace[axLetter + 'periodalignment']; + var periodalignment = winningPoint.trace[axLetter + 'periodalignment']; if(periodalignment) { + var d = winningPoint.cd[winningPoint.index]; var start = d[axLetter + 'Start']; var end = d[axLetter + 'End']; var diff = end - start; @@ -2014,7 +2013,6 @@ function getCoord(axLetter, winningPoint, fullLayout) { val = ax.d2c(val); } - var cd0 = cd[0]; if(cd0 && cd0.t && cd0.t.posLetter === ax._id) { if( fullLayout.boxmode === 'group' || diff --git a/src/traces/bar/calc.js b/src/traces/bar/calc.js index 2216c2469db..a0ec292e0be 100644 --- a/src/traces/bar/calc.js +++ b/src/traces/bar/calc.js @@ -10,7 +10,7 @@ var calcSelection = require('../scatter/calc_selection'); module.exports = function calc(gd, trace) { var xa = Axes.getFromId(gd, trace.xaxis || 'x'); var ya = Axes.getFromId(gd, trace.yaxis || 'y'); - var size, pos, origPos, pObj, hasPeriod; + var size, pos, origPos, pObj, hasPeriod, pLetter; var sizeOpts = { msUTC: !!(trace.base || trace.base === 0) @@ -21,11 +21,13 @@ module.exports = function calc(gd, trace) { origPos = ya.makeCalcdata(trace, 'y'); pObj = alignPeriod(trace, ya, 'y', origPos); hasPeriod = !!trace.yperiodalignment; + pLetter = 'y'; } else { size = ya.makeCalcdata(trace, 'y', sizeOpts); origPos = xa.makeCalcdata(trace, 'x'); pObj = alignPeriod(trace, xa, 'x', origPos); hasPeriod = !!trace.xperiodalignment; + pLetter = 'x'; } pos = pObj.vals; @@ -39,8 +41,8 @@ module.exports = function calc(gd, trace) { if(hasPeriod) { cd[i].orig_p = origPos[i]; // used by hover - cd[i].pEnd = pObj.ends[i]; - cd[i].pStart = pObj.starts[i]; + cd[i][pLetter + 'End'] = pObj.ends[i]; + cd[i][pLetter + 'Start'] = pObj.starts[i]; } if(trace.ids) { diff --git a/src/traces/bar/cross_trace_calc.js b/src/traces/bar/cross_trace_calc.js index 72203d40318..90aa290536f 100644 --- a/src/traces/bar/cross_trace_calc.js +++ b/src/traces/bar/cross_trace_calc.js @@ -448,7 +448,7 @@ function setBarCenterAndWidth(pa, sieve) { if(isPeriod) { calcBar.wPeriod = - calcBar.pEnd - calcBar.pStart; + calcBar[pLetter + 'End'] - calcBar[pLetter + 'Start']; } } } diff --git a/src/traces/bar/hover.js b/src/traces/bar/hover.js index 3d2e155ee96..a526439131c 100644 --- a/src/traces/bar/hover.js +++ b/src/traces/bar/hover.js @@ -63,11 +63,14 @@ function hoverOnBars(pointData, xval, yval, hovermode, opts) { return di[posLetter] + sgn * w / 2; } + function periodLength(di) { + return di[posLetter + 'End'] - di[posLetter + 'Start']; + } + var minPos = isClosest ? thisBarMinPos : period ? function(di) { - var diff = di.pEnd - di.pStart; - return di.p + diff / 2 - di.wPeriod; + return di.p + periodLength(di) / 2 - di.wPeriod; } : function(di) { /* @@ -88,8 +91,7 @@ function hoverOnBars(pointData, xval, yval, hovermode, opts) { var maxPos = isClosest ? thisBarMaxPos : period ? function(di) { - var diff = di.pEnd - di.pStart; - return di.p + diff / 2; + return di.p + periodLength(di) / 2; } : function(di) { return Math.max(thisBarMaxPos(di), di.p + t.bardelta / 2); diff --git a/src/traces/funnel/calc.js b/src/traces/funnel/calc.js index 4a379289c93..efdf9e0d31d 100644 --- a/src/traces/funnel/calc.js +++ b/src/traces/funnel/calc.js @@ -9,18 +9,20 @@ var BADNUM = require('../../constants/numerical').BADNUM; module.exports = function calc(gd, trace) { var xa = Axes.getFromId(gd, trace.xaxis || 'x'); var ya = Axes.getFromId(gd, trace.yaxis || 'y'); - var size, pos, origPos, pObj, hasPeriod, i, cdi; + var size, pos, origPos, pObj, hasPeriod, pLetter, i, cdi; if(trace.orientation === 'h') { size = xa.makeCalcdata(trace, 'x'); origPos = ya.makeCalcdata(trace, 'y'); pObj = alignPeriod(trace, ya, 'y', origPos); hasPeriod = !!trace.yperiodalignment; + pLetter = 'y'; } else { size = ya.makeCalcdata(trace, 'y'); origPos = xa.makeCalcdata(trace, 'x'); pObj = alignPeriod(trace, xa, 'x', origPos); hasPeriod = !!trace.xperiodalignment; + pLetter = 'x'; } pos = pObj.vals; @@ -55,8 +57,8 @@ module.exports = function calc(gd, trace) { if(hasPeriod) { cd[i].orig_p = origPos[i]; // used by hover - cd[i].pEnd = pObj.ends[i]; - cd[i].pStart = pObj.starts[i]; + cd[i][pLetter + 'End'] = pObj.ends[i]; + cd[i][pLetter + 'Start'] = pObj.starts[i]; } if(trace.ids) { diff --git a/src/traces/waterfall/calc.js b/src/traces/waterfall/calc.js index 151c9c91683..11f9afa6da6 100644 --- a/src/traces/waterfall/calc.js +++ b/src/traces/waterfall/calc.js @@ -17,18 +17,20 @@ function isTotal(a) { module.exports = function calc(gd, trace) { var xa = Axes.getFromId(gd, trace.xaxis || 'x'); var ya = Axes.getFromId(gd, trace.yaxis || 'y'); - var size, pos, origPos, pObj, hasPeriod; + var size, pos, origPos, pObj, hasPeriod, pLetter; if(trace.orientation === 'h') { size = xa.makeCalcdata(trace, 'x'); origPos = ya.makeCalcdata(trace, 'y'); pObj = alignPeriod(trace, ya, 'y', origPos); hasPeriod = !!trace.yperiodalignment; + pLetter = 'y'; } else { size = ya.makeCalcdata(trace, 'y'); origPos = xa.makeCalcdata(trace, 'x'); pObj = alignPeriod(trace, xa, 'x', origPos); hasPeriod = !!trace.xperiodalignment; + pLetter = 'x'; } pos = pObj.vals; @@ -85,8 +87,8 @@ module.exports = function calc(gd, trace) { if(hasPeriod) { cd[i].orig_p = origPos[i]; // used by hover - cd[i].pEnd = pObj.ends[i]; - cd[i].pStart = pObj.starts[i]; + cd[i][pLetter + 'End'] = pObj.ends[i]; + cd[i][pLetter + 'Start'] = pObj.starts[i]; } if(trace.ids) { From 4d2961d5cc676ecb1628f5146659220517a2191e Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 29 Jul 2021 13:22:12 -0400 Subject: [PATCH 13/14] handle undefined start and end periods --- src/components/fx/hover.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/components/fx/hover.js b/src/components/fx/hover.js index 386c52e8518..cf4cd3f967e 100644 --- a/src/components/fx/hover.js +++ b/src/components/fx/hover.js @@ -2000,9 +2000,15 @@ function getCoord(axLetter, winningPoint, fullLayout) { var periodalignment = winningPoint.trace[axLetter + 'periodalignment']; if(periodalignment) { var d = winningPoint.cd[winningPoint.index]; + var start = d[axLetter + 'Start']; + if(start === undefined) start = d[axLetter]; + var end = d[axLetter + 'End']; + if(end === undefined) end = d[axLetter]; + var diff = end - start; + if(periodalignment === 'end') { val += diff; } else if(periodalignment === 'middle') { From 1890e772ff7c015b24376bebd13dffe01489c90e Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 29 Jul 2021 14:06:03 -0400 Subject: [PATCH 14/14] simplification for bar --- src/traces/bar/cross_trace_calc.js | 8 -------- src/traces/bar/hover.js | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/traces/bar/cross_trace_calc.js b/src/traces/bar/cross_trace_calc.js index 90aa290536f..f1cad80924d 100644 --- a/src/traces/bar/cross_trace_calc.js +++ b/src/traces/bar/cross_trace_calc.js @@ -436,20 +436,12 @@ function setBarCenterAndWidth(pa, sieve) { var barwidth = t.barwidth; var barwidthIsArray = Array.isArray(barwidth); - var trace = calcTrace[0].trace; - var isPeriod = !!trace[pLetter + 'periodalignment']; - for(var j = 0; j < calcTrace.length; j++) { var calcBar = calcTrace[j]; // store the actual bar width and position, for use by hover var width = calcBar.w = barwidthIsArray ? barwidth[j] : barwidth; calcBar[pLetter] = calcBar.p + (poffsetIsArray ? poffset[j] : poffset) + width / 2; - - if(isPeriod) { - calcBar.wPeriod = - calcBar[pLetter + 'End'] - calcBar[pLetter + 'Start']; - } } } } diff --git a/src/traces/bar/hover.js b/src/traces/bar/hover.js index a526439131c..e062c4b50af 100644 --- a/src/traces/bar/hover.js +++ b/src/traces/bar/hover.js @@ -70,7 +70,7 @@ function hoverOnBars(pointData, xval, yval, hovermode, opts) { var minPos = isClosest ? thisBarMinPos : period ? function(di) { - return di.p + periodLength(di) / 2 - di.wPeriod; + return di.p - periodLength(di) / 2; } : function(di) { /*