Skip to content

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

Merged
etpinard merged 1 commit into
masterfrom
hover-label-overlap-filtered-out
Mar 18, 2019
Merged

Fix avoid-overlap hover label algo when "too close" label get filtered out#3645
etpinard merged 1 commit into
masterfrom
hover-label-overlap-filtered-out

Conversation

@etpinard

Copy link
Copy Markdown
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.
@etpinard etpinard added bug something broken status: reviewable labels Mar 18, 2019
@antoinerg

Copy link
Copy Markdown
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

Labels

bug something broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hover Labels Overlap in 2d scatter plot

2 participants