Skip to content

Commit 4f92ccf

Browse files
committed
align period scatter points - improve tests
1 parent f8b584e commit 4f92ccf

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

src/traces/scatter/hover.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ 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-
var d = (dxRaw < rad) ? (kink * dxRaw / rad) : (dxRaw - rad + kink);
32-
return d;
31+
if(di.orig_x !== undefined) dxRaw += xa.c2p(di.orig_x) - xa.c2p(di.x);
32+
return (dxRaw < rad) ? (kink * dxRaw / rad) : (dxRaw - rad + kink);
3333
};
3434
var dy = function(di) {
3535
var rad = Math.max(3, di.mrc || 0);
3636
var kink = 1 - 1 / rad;
3737
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);
3839
return (dyRaw < rad) ? (kink * dyRaw / rad) : (dyRaw - rad + kink);
3940
};
4041
var dxy = function(di) {

test/jasmine/tests/hover_label_test.js

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5154,7 +5154,7 @@ describe('hovermode: (x|y)unified', function() {
51545154
xperiod: 0,
51555155
desc: 'non-period scatter points and period bars'
51565156
}, {
5157-
xperiod: 24 * 3600 * 1000,
5157+
xperiod: 5 * 24 * 3600 * 1000,
51585158
desc: 'period scatter points and period bars'
51595159
}].forEach(function(t) {
51605160
it(t.desc, function(done) {
@@ -5199,12 +5199,23 @@ describe('hovermode: (x|y)unified', function() {
51995199
'bar : 2'
52005200
]});
52015201

5202+
_hover(gd, { xpx: 75, ypx: 200 });
5203+
assertLabel({title: 'Dec', items: [
5204+
'bar : 2'
5205+
]});
5206+
52025207
_hover(gd, { xpx: 100, ypx: 200 });
52035208
assertLabel({title: 'Jan 1, 2000', items: [
52045209
'bar : (Jan, 1)',
52055210
'scatter : 1.1'
52065211
]});
52075212

5213+
_hover(gd, { xpx: 125, ypx: 200 });
5214+
assertLabel({title: 'Jan 6, 2000', items: [
5215+
'bar : (Jan, 1)',
5216+
'scatter : 1.2'
5217+
]});
5218+
52085219
_hover(gd, { xpx: 150, ypx: 200 });
52095220
assertLabel({title: 'Jan 11, 2000', items: [
52105221
'bar : (Jan, 1)',
@@ -5217,18 +5228,35 @@ describe('hovermode: (x|y)unified', function() {
52175228
'scatter : 1.6'
52185229
]});
52195230

5231+
_hover(gd, { xpx: 225, ypx: 200 });
5232+
assertLabel({title: 'Feb 1, 2000', items: [
5233+
'bar : (Feb, 3)',
5234+
'scatter : 2.1'
5235+
]});
5236+
52205237
_hover(gd, { xpx: 250, ypx: 200 });
52215238
assertLabel({title: 'Feb 11, 2000', items: [
52225239
'bar : (Feb, 3)',
52235240
'scatter : 2.3'
52245241
]});
52255242

5243+
_hover(gd, { xpx: 275, ypx: 200 });
5244+
assertLabel({title: 'Feb 16, 2000', items: [
5245+
'bar : (Feb, 3)',
5246+
'scatter : 2.4'
5247+
]});
5248+
52265249
_hover(gd, { xpx: 300, ypx: 200 });
52275250
assertLabel({title: 'Feb 21, 2000', items: [
52285251
'bar : (Feb, 3)',
52295252
'scatter : 2.5'
52305253
]});
52315254

5255+
_hover(gd, { xpx: 325, ypx: 200 });
5256+
assertLabel({title: 'Mar 1, 2000', items: [
5257+
'scatter : 3.1'
5258+
]});
5259+
52325260
_hover(gd, { xpx: 350, ypx: 200 });
52335261
assertLabel({title: 'Mar 6, 2000', items: [
52345262
'scatter : 3.2'
@@ -5279,20 +5307,22 @@ describe('hovermode: (x|y)unified', function() {
52795307
_hover(gd, { xpx: 40, ypx: 200 });
52805308
assertLabel({title: 'Jan', items: [
52815309
'bar : (Jan 1, 2000, 1)',
5282-
'start : 1'
5310+
'start : 1',
5311+
'end : 1'
52835312
]});
52845313

52855314
_hover(gd, { xpx: 100, ypx: 200 });
52865315
assertLabel({title: 'Jan', items: [
52875316
'bar : (Jan 1, 2000, 1)',
5288-
'start : 1'
5317+
'start : 1',
5318+
'end : 1'
52895319
]});
52905320

52915321
_hover(gd, { xpx: 360, ypx: 200 });
5292-
assertLabel({title: 'Jan', items: [
5322+
assertLabel({title: 'Feb', items: [
52935323
'bar : (Feb 1, 2000, 2)',
5294-
'start : (Feb, 2)',
5295-
'end : 1'
5324+
'start : 2',
5325+
'end : 2'
52965326
]});
52975327

52985328
_hover(gd, { xpx: 400, ypx: 200 });

0 commit comments

Comments
 (0)