8000 Pick closest points to the winning point in compare mode and position unified hover box in front of winning point by archmoj · Pull Request #5683 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Pick closest points to the winning point in compare mode and position unified hover box in front of winning point #5683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 28, 2021
Prev Previous commit
align period for scattergl
  • Loading branch information
archmoj committed May 26, 2021
commit 282a2279c1e1d67bc54bb09c8c8d93713f3f72ea
2 changes: 2 additions & 0 deletions src/traces/scattergl/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ function hoverPoints(pointData, xval, yval, hovermode) {
for(i = 0; i < ids.length; i++) {
ptx = x[ids[i]];
dx = Math.abs(xa.c2p(ptx) - xpx);
if(trace._origX && trace._origX[i] !== undefined) dx += xa.c2p(trace._origX[i]) - xa.c2p(ptx);
if(dx < minDist) {
minDist = dx;
dy = ya.c2p(y[ids[i]]) - ypx;
if(trace._origY && trace._origY[i] !== undefined) dy += ya.c2p(trace._origY[i]) - ya.c2p(pty);
dxy = Math.sqrt(dx * dx + dy * dy);
id = ids[i];
}
Expand Down
130 changes: 66 additions & 64 deletions test/jasmine/tests/hover_label_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5266,73 +5266,75 @@ describe('hovermode: (x|y)unified', function() {
});
});

it('period points alignments', function(done) {
Plotly.newPlot(gd, {
data: [
{
name: 'bar',
type: 'bar',
x: ['2000-01', '2000-02'],
y: [1, 2],
xhoverfrmat: '%b',
xperiod: 'M1'
},
{
name: 'start',
type: 'scatter',
x: ['2000-01', '2000-02'],
y: [1, 2],
xhoverformat: '%b',
xperiod: 'M1',
xperiodalignment: 'start'
},
{
name: 'end',
type: 'scatter',
x: ['2000-01', '2000-02'],
y: [1, 2],
xhoverformat: '%b',
xperiod: 'M1',
xperiodalignment: 'end'
},
],
layout: {
showlegend: false,
width: 600,
height: 400,
hovermode: 'x unified'
}
})
.then(function(gd) {
_hover(gd, { xpx: 40, ypx: 200 });
assertLabel({title: 'Jan', items: [
'bar : (Jan 1, 2000, 1)',
'start : 1',
'end : 1'
]});
['scatter', 'scattergl'].forEach(function(scatterType) {
it(scatterType + ' period points alignments', function(done) {
Plotly.newPlot(gd, {
data: [
{
name: 'bar',
type: 'bar',
x: ['2000-01', '2000-02'],
y: [1, 2],
xhoverfrmat: '%b',
xperiod: 'M1'
},
{
name: 'start',
type: scatterType,
x: ['2000-01', '2000-02'],
y: [1, 2],
xhoverformat: '%b',
xperiod: 'M1',
xperiodalignment: 'start'
},
{
name: 'end',
type: 'scatter',
x: ['2000-01', '2000-02'],
y: [1, 2],
xhoverformat: '%b',
xperiod: 'M1',
xperiodalignment: 'end'
},
],
layout: {
showlegend: false,
width: 600,
height: 400,
hovermode: 'x unified'
}
})
.then(function(gd) {
_hover(gd, { xpx: 40, ypx: 200 });
assertLabel({title: 'Jan', items: [
'bar : (Jan 1, 2000, 1)',
'start : 1',
'end : 1'
]});

_hover(gd, { xpx: 100, ypx: 200 });
assertLabel({title: 'Jan', items: [
'bar : (Jan 1, 2000, 1)',
'start : 1',
'end : 1'
]});
_hover(gd, { xpx: 100, ypx: 200 });
assertLabel({title: 'Jan', items: [
'bar : (Jan 1, 2000, 1)',
'start : 1',
'end : 1'
]});

_hover(gd, { xpx: 360, ypx: 200 });
assertLabel({title: 'Feb', items: [
'bar : (Feb 1, 2000, 2)',
'start : 2',
'end : 2'
]});
_hover(gd, { xpx: 360, ypx: 200 });
assertLabel({title: 'Feb', items: [
'bar : (Feb 1, 2000, 2)',
'start : 2',
'end : 2'
]});

_hover(gd, { xpx: 400, ypx: 200 });
assertLabel({title: 'Feb', items: [
'bar : (Feb 1, 2000, 2)',
'start : 2',
'end : 2'
]});
})
.then(done, done.fail);
_hover(gd, { xpx: 400, ypx: 200 });
assertLabel({title: 'Feb', items: [
'bar : (Feb 1, 2000, 2)',
'start : 2',
'end : 2'
]});
})
.then(done, done.fail);
});
});

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