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

Better hover for choropleth traces #1401

Merged
merged 6 commits into from
Feb 27, 2017
Merged

Better hover for choropleth traces #1401

merged 6 commits into from
Feb 27, 2017

Conversation

etpinard
Copy link
Contributor

@etpinard etpinard commented Feb 21, 2017

fixes #1333

and cleans up a bunch of geo-only code paths and logic.

- 🔪 geo container <div>
- 🔪 geoimages <g> and (now obsolete) toSVG method
- similar to 'extraText', to allow trace modules' hoverPoints
  methods to override the 'name' hover label content.
- only export one method (like all other trace plot method)
- add hoverPoints and eventData methods making choropleth hover
  user Fx.hover logic (just like scattergeo)
- set 'choroplethHoverPt' field on geo instance on mouseover
  choropleth location pt, use this to make hover info in hoverPoints
- now that choropleth hover geos through Fx.hover,
  `hovermode: false` for geo no longer needs a special handler.
@etpinard etpinard added status: reviewable bug something broken labels Feb 21, 2017
@etpinard etpinard added this to the 1.24.0 milestone Feb 21, 2017
@@ -2762,11 +2762,6 @@ function makePlotFramework(gd) {
fullLayout._glcontainer.enter().append('div')
.classed('gl-container', true);

fullLayout._geocontainer = fullLayout._paperdiv.selectAll('.geo-container')
.data([0]);
fullLayout._geocontainer.enter().append('div')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An artefact from the first iteration back in July 2015 - where I found that Fx.lonehover worked best off a plain <div> (fast-forward today, this not longer the case).

@@ -2810,6 +2805,9 @@ function makePlotFramework(gd) {
// single ternary layer for the whole plot
fullLayout._ternarylayer = fullLayout._paper.append('g').classed('ternarylayer', true);

// single geo layer for the whole plot
fullLayout._geolayer = fullLayout._paper.append('g').classed('geolayer', true);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now geo lies side-by-side with other SVG subplot types 🎉

// to simulate the 'zoomon' event
Fx.loneUnhover(geo.hoverContainer);
.on('mouseover', function(pt) {
geo.choroplethHoverPt = pt;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pt here is essentially the calcdata item corresponding to the feature under the mouse cursor. geo.choroplethHoverPt is then used in the hoverPoints method.

Alternatively, we could have looped over all the features and use something like turf-inside which is more similar to the hoveron: 'fills' algorithm, but I thought this here sufficed.

return Axes.tickText(axis, axis.c2l(val), 'hover').text;
}

if(hasIdAsNameLabel) pointData.nameOverride = pt.id;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see ec6c1b1

@etpinard
Copy link
Contributor Author

I can't notice any unwanted differences in the new baselines in c32d445

If anything, the new baselines appear to better clip the geo subplots:

gifrecord_2017-02-21_132722

I wouldn't mind having another set of 👀 taking a look at this.

@alexcjohnson
Copy link
Collaborator

Beautiful. Hover effects work better AND the code and svg structure is way simpler. 🌟 💯 🌟

I'm not worried about the baseline image differences - seems like just subpixel rounding differences based on the different nesting structure. There does seem to be a little bit of overflow in the clipping, may be worthwhile taking a 🔍 to it at some point but doesn't need to be now - I don't think the effect changed with this PR, it just got a subpixel shift.

💃

@etpinard etpinard merged commit 34eb326 into master Feb 27, 2017
@etpinard etpinard deleted the choropleth-hover-better branch February 27, 2017 15:01
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.

choropleth hover labels can get lost
2 participants