Skip to content

Commit 89f7f13

Browse files
committed
fix 5822 - period scatter hover positions
1 parent db5c563 commit 89f7f13

File tree

5 files changed

+312
-148
lines changed

5 files changed

+312
-148
lines changed

src/traces/scatter/calc.js

-10
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,13 @@ function calc(gd, trace) {
5151
calcAxisExpansion(gd, trace, xa, ya, x, y, ppad);
5252
}
5353

54-
var hasPeriodX = !!trace.xperiodalignment;
55-
var hasPeriodY = !!trace.yperiodalignment;
56-
5754
for(i = 0; i < serieslen; i++) {
5855
var cdi = cd[i] = {};
5956
var xValid = isNumeric(x[i]);
6057
var yValid = isNumeric(y[i]);
6158
if(xValid && yValid) {
6259
cdi[xAttr] = x[i];
6360
cdi[yAttr] = y[i];
64-
65-
if(hasPeriodX) {
66-
cdi.orig_x = origX[i]; // used by hover
67-
}
68-
if(hasPeriodY) {
69-
cdi.orig_y = origY[i]; // used by hover
70-
}
7161
} else if(stackGroupOpts && (isV ? xValid : yValid)) {
7262
// if we're stacking we need to hold on to all valid positions
7363
// even with invalid sizes

src/traces/scatter/hover.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
2828
var rad = Math.max(3, di.mrc || 0);
2929
var kink = 1 - 1 / rad;
3030
var dxRaw = Math.abs(xa.c2p(di.x) - xpx);
31-
if(di.orig_x !== undefined) dxRaw += xa.c2p(di.orig_x) - xa.c2p(di.x);
3231
return (dxRaw < rad) ? (kink * dxRaw / rad) : (dxRaw - rad + kink);
3332
};
3433
var dy = function(di) {
3534
var rad = Math.max(3, di.mrc || 0);
3635
var kink = 1 - 1 / rad;
3736
var dyRaw = Math.abs(ya.c2p(di.y) - ypx);
38-
if(di.orig_y !== undefined) dyRaw += ya.c2p(di.orig_y) - ya.c2p(di.y);
3937
return (dyRaw < rad) ? (kink * dyRaw / rad) : (dyRaw - rad + kink);
4038
};
4139
var dxy = function(di) {
@@ -71,8 +69,8 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
7169
// the normalized individual sizes, so that's what I'm doing here
7270
// for now.
7371
var sizeVal = orientation && (di.sNorm || di.s);
74-
var xLabelVal = (orientation === 'h') ? sizeVal : di.orig_x !== undefined ? di.orig_x : di.x;
75-
var yLabelVal = (orientation === 'v') ? sizeVal : di.orig_y !== undefined ? di.orig_y : di.y;
72+
var xLabelVal = (orientation === 'h') ? sizeVal : di.x;
73+
var yLabelVal = (orientation === 'v') ? sizeVal : di.y;
7674

7775
Lib.extendFlat(pointData, {
7876
color: getTraceColor(trace, di),

src/traces/scattergl/hover.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,9 @@ function hoverPoints(pointData, xval, yval, hovermode) {
4848
for(i = 0; i < ids.length; i++) {
4949
ptx = x[ids[i]];
5050
dx = Math.abs(xa.c2p(ptx) - xpx);
51-
if(trace._origX && trace._origX[i] !== undefined) dx += xa.c2p(trace._origX[i]) - xa.c2p(ptx);
5251
if(dx < minDist) {
5352
minDist = dx;
5453
dy = ya.c2p(y[ids[i]]) - ypx;
55-
if(trace._origY && trace._origY[i] !== undefined) dy += ya.c2p(trace._origY[i]) - ya.c2p(pty);
5654
dxy = Math.sqrt(dx * dx + dy * dy);
5755
id = ids[i];
5856
}
@@ -155,19 +153,16 @@ function calcHover(pointData, x, y, trace) {
155153
var fakeCd = {};
156154
fakeCd[pointData.index] = di;
157155

158-
var origX = trace._origX;
159-
var origY = trace._origY;
160-
161156
var pointData2 = Lib.extendFlat({}, pointData, {
162157
color: getTraceColor(trace, di),
163158

164159
x0: xp - rad,
165160
x1: xp + rad,
166-
xLabelVal: origX ? origX[id] : di.x,
161+
xLabelVal: di.x,
167162

168163
y0: yp - rad,
169164
y1: yp + rad,
170-
yLabelVal: origY ? origY[id] : di.y,
165+
yLabelVal: di.y,
171166

172167
cd: fakeCd,
173168
distance: minDist,

test/jasmine/tests/gl2d_click_test.js

+40
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,9 @@ describe('hover with (x|y)period positioning', function() {
627627

628628
it('@gl shows hover info for scattergl', function(done) {
629629
Plotly.newPlot(gd, require('@mocks/gl2d_period_positioning.json'))
630+
.then(function() { return Plotly.restyle(gd, 'xperiodalignment', 'start'); })
631+
.then(function() { return Plotly.restyle(gd, 'yperiodalignment', 'start'); })
632+
630633
.then(function() { _hover(100, 255); })
631634
.then(function() {
632635
assertHoverLabelContent({
@@ -641,6 +644,43 @@ describe('hover with (x|y)period positioning', function() {
641644
nums: '(Jan 2006, Jun 1, 1970)'
642645
});
643646
})
647+
648+
.then(function() { return Plotly.restyle(gd, 'xperiodalignment', 'middle'); })
649+
.then(function() { return Plotly.restyle(gd, 'yperiodalignment', 'middle'); })
650+
.then(function() { _hover(100, 255); })
651+
.then(function() { _hover(100, 255); })
652+
.then(function() {
653+
assertHoverLabelContent({
654+
name: '',
655+
nums: '(Jul 2001, Jan 16, 1970)'
656+
});
657+
})
658+
.then(function() { _hover(470, 45); })
659+
.then(function() {
660+
assertHoverLabelContent({
661+
name: '',
662+
nums: '(Jul 2006, Jun 16, 1970)'
663+
});
664+
})
665+
666+
.then(function() { return Plotly.restyle(gd, 'xperiodalignment', 'end'); })
667+
.then(function() { return Plotly.restyle(gd, 'yperiodalignment', 'end'); })
668+
669+
.then(function() { _hover(100, 255); })
670+
.then(function() {
671+
assertHoverLabelContent({
672+
name: '',
673+
nums: '(Jan 2002, Feb 1, 1970)'
674+
});
675+
})
676+
.then(function() { _hover(470, 45); })
677+
.then(function() {
678+
assertHoverLabelContent({
679+
name: '',
680+
nums: '(Jan 2007, Jul 1, 1970)'
681+
});
682+
})
683+
644684
.then(done, done.fail);
645685
});
646686
});

0 commit comments

Comments
 (0)