Skip to content
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

Fix avoid-overlap hover label algo when "too close" label get filtered out #3645

Merged
merged 1 commit into from
Mar 18, 2019

Conversation

etpinard
Copy link
Contributor

fixes #3603

before: https://codepen.io/antoinerg/pen/MxEjeo

Peek 2019-03-18 15-39

after: https://codepen.io/etpinard/pen/LaBpYm

Peek 2019-03-18 16-04

In this example, we enter this block:

// remove the "close but not quite" points
// because of error bars, only take up to a space
hoverData = hoverData.filter(function(d) {
return (d.zLabelVal !== undefined) ||
(d[commonAttr] || '').split(' ')[0] === t00;
});

where hoverData gets filtered down showing two visible hover labels, but isn't updated for the downstream hoverAvoidOverlaps call where the "old" (longer) hoverData array is used here:

var pointgroups = hoverData.map(function(d, i) {
var axis = d[ax];
var axIsX = axis._id.charAt(0) === 'x';
var rng = axis.range;
if(!i && rng && ((rng[0] > rng[1]) !== axIsX)) axSign = -1;
return [{
i: i,
traceIndex: d.trace.index,
dp: 0,
pos: d.pos,
posref: d.posref,
size: d.by * (axIsX ? YFACTOR : 1) / 2,
pmin: 0,
pmax: (axIsX ? fullLayout.width : fullLayout.height)
}];
})

cc @plotly/plotly_js

... that way when some hover data pts are filtered out (e.g. when they
    are too close together in compare mode), the fix-overlap algo
    still works.
@antoinerg
Copy link
Contributor

Thank you for the fix @etpinard ! It looks good to me 💃

@etpinard etpinard merged commit 0588483 into master Mar 18, 2019
@etpinard etpinard deleted the hover-label-overlap-filtered-out branch March 18, 2019 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hover Labels Overlap in 2d scatter plot
2 participants