-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Multiple scattergeo improvement #1004
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
Conversation
- which is consistent with mapbox subplot, and comptabitible with Fx.hover
- to be reuse in 'scattergeo'
- which skips and cast lon/lat values - fixes #963 - note that 'locations[i]' -> feature must still be done at the plot (after the topojson is loaded)
- traces with no data points are given a place-holder calc trace to retatin fullData.length === gd.calcdata.length, and make some component (e.g. legend) logic easier - tag these place-holder traces so that the plot modules can easily skip over them
- so plotting that data-pt less traces do result in mapbox errors.
- add support for 'connectgaps' - add support for 'fill: 'toself' - remove all traces of hover / click handlers
- make Fx.hover pass subplot info to hoverPoints module - add scattergeo hoverPoints and eventData modules - mock xaxis and yaxis in geo instances - factor out is-over-edge logic to use it in hoverPoints - use 'mousemove' instead of 'mouseover' in test to trigger hover
- until we make choropleth use fullLayout._hoverlayer for its hover labels.
- the first legend item is now correct!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ok to me but I didn't get right into the details for all these changes. If I didn't understand what the code was doing fairly quickly I made a comment about improving the naming or comments.
ya = pointData.ya, | ||
geo = pointData.subplot; | ||
|
||
if(cd[0].placeholder) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a little mysterious, at least as someone who doesn't look at Plotly.js code daily. Maybe a comment here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the comment you're looking for: https://github.com/plotly/plotly.js/pull/1004/files#diff-ad4f76ccd6044ed16514297078e13b84R1672
Putting comment about something where it is set is probably more robust than putting it where it is used.
var lonlat = d.lonlat; | ||
|
||
// this handles the not-found location feature case | ||
if(lonlat[0] === null || lonlat[1] === null) return Infinity; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why return Infinity and not say, null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because this function returns a distance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have expected NaN
I think.
var di = cd[pointData.index], | ||
lonlat = di.lonlat, | ||
pos = c2p(lonlat), | ||
rad = di.mrc || 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is di.mrc undefined or 0? Or could be both and we want it to be 1 regardless. Also why 1? Maybe some comments here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
di.mrc
is set only when there mode
includes 'markers'
, so we need a fallback for mode 'line'
and 'text'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish I could gather that from that line of code ;)
|
||
var dx = Math.abs(xPx - pos[0]), | ||
dy = Math.abs(yPx - pos[1]), | ||
rad = Math.max(3, d.mrc || 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are the constraints on radius here for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
marker pt radii are taken into consideration in the picking routine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it will be obvious to someone who is maintaining this code what the 3
and 0
are doing? I didn't get it right away which is usually a sign that a comment may be helpful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but perhaps it is obvious ;/
|
||
if(!lonlat) continue; // filter the blank points here | ||
// skip over placeholder traces | ||
if(calcTrace[0].placeholder) s.remove(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are placeholder traces?
@@ -19,6 +19,8 @@ module.exports = function hoverPoints(pointData, xval, yval) { | |||
xa = pointData.xa, | |||
ya = pointData.ya; | |||
|
|||
if(cd[0].placeholder) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there another name we can use beside placeholder
, a placeholder
for _____
? How about emptytrace
?.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could.
Not sure emptytrace
is better though. traceWithNoVisibleDataPoint
would be the most verbose. But I think placeholder
does the trick as discussed in https://github.com/plotly/plotly.js/pull/1004/files#diff-ad4f76ccd6044ed16514297078e13b84R1672
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep placeholder is ok. Perhaps we can expand a little in that original placeholder comment. I still didn't quite understand when they would be necessary
Aighty all the comments are nonblocking! There are nice tests and this PR looks like a huge win Nice work! |
💃 |
fixes #963
and supersedes #964
In brief, this PR brings several ideas from
scattermapbox
over toscattergeo
- while reusing some parts of logic (namely regarding GeoJSON) keeping things 🌴In details, this PR:
scattergeo
use a proper calc stepscattergeo
useFx.hover
to pick (using calcdata) and draw its hover labelsmode: 'lines'
now (I mean finally) has a hover handlers!connecgaps
to scattergeofill: 'toself'
to scattergeo (similar to howscattermapbox
implementfill
)🎉 Yay geo line hover text: