Skip to content

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

Merged
merged 14 commits into from
Oct 6, 2016
Merged

Multiple scattergeo improvement #1004

merged 14 commits into from
Oct 6, 2016

Conversation

etpinard
Copy link
Contributor

@etpinard etpinard commented Oct 4, 2016

fixes #963

and supersedes #964

In brief, this PR brings several ideas from scattermapbox over to scattergeo - while reusing some parts of logic (namely regarding GeoJSON) keeping things 🌴

In details, this PR:

  • fixes Strange behavior with missing values in scattergeo  #963 (thanks again @cpsievert for letting me know)
  • scattergeo traces with non-circle markers now get the correct legend item
  • make scattergeo use a proper calc step
  • make scattergeo use Fx.hover to pick (using calcdata) and draw its hover labels
    • this means that user no longer have to hover over scattergeo data points to trigger hover event / draw labels
    • this means that scattergeo mode: 'lines' now (I mean finally) has a hover handlers!
  • adds support for connecgaps to scattergeo
  • adds support for fill: 'toself' to scattergeo (similar to how scattermapbox implement fill)

🎉 Yay geo line hover text:

gifrecord_2016-10-03_180302

- which is consistent with mapbox subplot,
  and comptabitible with Fx.hover
- 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!
@etpinard etpinard added bug something broken feature something new status: reviewable labels Oct 4, 2016
@etpinard etpinard added this to the v1.18.0 milestone Oct 4, 2016
Copy link
Member

@bpostlethwaite bpostlethwaite left a 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;
Copy link
Member

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?

Copy link
Contributor Author

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;
Copy link
Member

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

Copy link
Contributor Author

@etpinard etpinard Oct 5, 2016

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.

Copy link
Member

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;
Copy link
Member

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

Copy link
Contributor Author

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'

Copy link
Member

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);
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

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();
Copy link
Member

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;
Copy link
Member

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?.

Copy link
Contributor Author

@etpinard etpinard Oct 5, 2016

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

Copy link
Member

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

@bpostlethwaite
Copy link
Member

Aighty all the comments are nonblocking! There are nice tests and this PR looks like a huge win

Nice work!

@bpostlethwaite
Copy link
Member

💃

@etpinard etpinard merged commit f058e8b into master Oct 6, 2016
@etpinard etpinard deleted the geo-line-picking branch October 6, 2016 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken feature something new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Strange behavior with missing values in scattergeo
2 participants