Skip to content

DRY loneHover routine #3764

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 2 commits into from
Apr 11, 2019
Merged

DRY loneHover routine #3764

merged 2 commits into from
Apr 11, 2019

Conversation

antoinerg
Copy link
Contributor

Fx.loneHover logic is already contained in Fx.multiHover so I remove the duplication here.

@antoinerg antoinerg changed the title 🌴 loneHover routine DRY loneHover routine Apr 11, 2019
@etpinard
Copy link
Contributor

etpinard commented Apr 11, 2019

Brilliant!

I'm a little worried about this block:

// Fix vertical overlap
var tooltipSpacing = 5;
var lastBottomY = 0;
var anchor = 0;
hoverLabel
.sort(function(a, b) {return a.y0 - b.y0;})
.each(function(d, i) {
var topY = d.y0 - d.by / 2;
if((topY - tooltipSpacing) < lastBottomY) {
d.offset = (lastBottomY - topY) + tooltipSpacing;
} else {
d.offset = 0;
}
lastBottomY = topY + d.by + d.offset;
if(i === opts.anchorIndex || 0) anchor = d.offset;
})
.each(function(d) {
d.offset -= anchor;
});

affecting traces that use Fx.loneHover in bad ways. Could you manually check that pie, gl3d, sunburst and sankey traces look the same?


Moreover, maybe we could go one step further by merging multiHovers with loneHover completely. Looks like all you need is something like:

return Array.isArray(hoverItems) ? hoverLabel : hoverLabel.node(); 

at the end.

@antoinerg
Copy link
Contributor Author

Could you manually check that pie, gl3d, sunburst and sankey traces look the same?

I added a console.log(d.offset) after L188 and made sure d.offset is zero for all the traces you mentioned. In the future, if we support different alignment schemes for hover labels, we should definitely add test this in jasmine.

Moreover, maybe we could go one step further by merging multiHovers with loneHover completely.

Do you mean that I should remove all occurrences of Fx.loneHover in our codebase? I guess it would make sense to do so.

@etpinard
Copy link
Contributor

Do you mean that I should remove all occurrences of Fx.loneHover in our codebase?

I would do opposite. Keep loneHover and merge multiHovers into loneHover. loneHover has more history in the repo (it's been there ever since gl3d got its hover labels).

@etpinard
Copy link
Contributor

Awesome 💃

@antoinerg antoinerg merged commit 74e8bb9 into master Apr 11, 2019
@antoinerg antoinerg deleted the dry-hover branch April 11, 2019 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants