Skip to content

Commit 282a227

Browse files
committed
align period for scattergl
1 parent 4f92ccf commit 282a227

File tree

2 files changed

+68
-64
lines changed

2 files changed

+68
-64
lines changed

src/traces/scattergl/hover.js

+2
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ 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);
5152
if(dx < minDist) {
5253
minDist = dx;
5354
dy = ya.c2p(y[ids[i]]) - ypx;
55+
if(trace._origY && trace._origY[i] !== undefined) dy += ya.c2p(trace._origY[i]) - ya.c2p(pty);
5456
dxy = Math.sqrt(dx * dx + dy * dy);
5557
id = ids[i];
5658
}

test/jasmine/tests/hover_label_test.js

+66-64
Original file line numberDiff line numberDiff line change
@@ -5266,73 +5266,75 @@ describe('hovermode: (x|y)unified', function() {
52665266
});
52675267
});
52685268

5269-
it('period points alignments', function(done) {
5270-
Plotly.newPlot(gd, {
5271-
data: [
5272-
{
5273-
name: 'bar',
5274-
type: 'bar',
5275-
x: ['2000-01', '2000-02'],
5276-
y: [1, 2],
5277-
xhoverfrmat: '%b',
5278-
xperiod: 'M1'
5279-
},
5280-
{
5281-
name: 'start',
5282-
type: 'scatter',
5283-
x: ['2000-01', '2000-02'],
5284-
y: [1, 2],
5285-
xhoverformat: '%b',
5286-
xperiod: 'M1',
5287-
xperiodalignment: 'start'
5288-
},
5289-
{
5290-
name: 'end',
5291-
type: 'scatter',
5292-
x: ['2000-01', '2000-02'],
5293-
y: [1, 2],
5294-
xhoverformat: '%b',
5295-
xperiod: 'M1',
5296-
xperiodalignment: 'end'
5297-
},
5298-
],
5299-
layout: {
5300-
showlegend: false,
5301-
width: 600,
5302-
height: 400,
5303-
hovermode: 'x unified'
5304-
}
5305-
})
5306-
.then(function(gd) {
5307-
_hover(gd, { xpx: 40, ypx: 200 });
5308-
assertLabel({title: 'Jan', items: [
5309-
'bar : (Jan 1, 2000, 1)',
5310-
'start : 1',
5311-
'end : 1'
5312-
]});
5269+
['scatter', 'scattergl'].forEach(function(scatterType) {
5270+
it(scatterType + ' period points alignments', function(done) {
5271+
Plotly.newPlot(gd, {
5272+
data: [
5273+
{
5274+
name: 'bar',
5275+
type: 'bar',
5276+
x: ['2000-01', '2000-02'],
5277+
y: [1, 2],
5278+
xhoverfrmat: '%b',
5279+
xperiod: 'M1'
5280+
},
5281+
{
5282+
name: 'start',
5283+
type: scatterType,
5284+
x: ['2000-01', '2000-02'],
5285+
y: [1, 2],
5286+
xhoverformat: '%b',
5287+
xperiod: 'M1',
5288+
xperiodalignment: 'start'
5289+
},
5290+
{
5291+
name: 'end',
5292+
type: 'scatter',
5293+
x: ['2000-01', '2000-02'],
5294+
y: [1, 2],
5295+
xhoverformat: '%b',
5296+
xperiod: 'M1',
5297+
xperiodalignment: 'end'
5298+
},
5299+
],
5300+
layout: {
5301+
showlegend: false,
5302+
width: 600,
5303+
height: 400,
5304+
hovermode: 'x unified'
5305+
}
5306+
})
5307+
.then(function(gd) {
5308+
_hover(gd, { xpx: 40, ypx: 200 });
5309+
assertLabel({title: 'Jan', items: [
5310+
'bar : (Jan 1, 2000, 1)',
5311+
'start : 1',
5312+
'end : 1'
5313+
]});
53135314

5314-
_hover(gd, { xpx: 100, ypx: 200 });
5315-
assertLabel({title: 'Jan', items: [
5316-
'bar : (Jan 1, 2000, 1)',
5317-
'start : 1',
5318-
'end : 1'
5319-
]});
5315+
_hover(gd, { xpx: 100, ypx: 200 });
5316+
assertLabel({title: 'Jan', items: [
5317+
'bar : (Jan 1, 2000, 1)',
5318+
'start : 1',
5319+
'end : 1'
5320+
]});
53205321

5321-
_hover(gd, { xpx: 360, ypx: 200 });
5322-
assertLabel({title: 'Feb', items: [
5323-
'bar : (Feb 1, 2000, 2)',
5324-
'start : 2',
5325-
'end : 2'
5326-
]});
5322+
_hover(gd, { xpx: 360, ypx: 200 });
5323+
assertLabel({title: 'Feb', items: [
5324+
'bar : (Feb 1, 2000, 2)',
5325+
'start : 2',
5326+
'end : 2'
5327+
]});
53275328

5328-
_hover(gd, { xpx: 400, ypx: 200 });
5329-
assertLabel({title: 'Feb', items: [
5330-
'bar : (Feb 1, 2000, 2)',
5331-
'start : 2',
5332-
'end : 2'
5333-
]});
5334-
})
5335-
.then(done, done.fail);
5329+
_hover(gd, { xpx: 400, ypx: 200 });
5330+
assertLabel({title: 'Feb', items: [
5331+
'bar : (Feb 1, 2000, 2)',
5332+
'start : 2',
5333+
'end : 2'
5334+
]});
5335+
})
5336+
.then(done, done.fail);
5337+
});
53365338
});
53375339

53385340
it('period with hover distance -1 include closest not farthest', function(done) {

0 commit comments

Comments
 (0)