Skip to content

Generalize hover picking routine #575

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 6 commits into from
May 31, 2016
Merged

Generalize hover picking routine #575

merged 6 commits into from
May 31, 2016

Conversation

etpinard
Copy link
Contributor

Another PR in preparation for our mapbox-gl integration.

In brief, this PR generalizes the Fx.hover in graph_interact.js, so that it can use xaxis and yaxis from arbitrary subplot instance.

At the moment, only cartesian and ternary subplots use Fx.hover to handle their hover labels. But with after this PR, making geo and mapbox subplots use Fx.hover will be a piece of 🍰 .

etpinard added 6 commits May 25, 2016 19:24
- don't assume that fullLayout._plots is defined
- don't assume that fullLayout._plots[''] is defined
- use fullLayout[spId]._subplot.{x,y}axis as subplot x/y axes
  in non-cartesian cases
- perf: replace two .map calls with one for loop
return Axes.getFromId(gd, spId, 'y');
}),
hovermode = evt.hovermode || fullLayout.hovermode;
plots = fullLayout._plots || [],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMPORTANT keep fullLayout._plots for cartesian subplots (and gl2d although I'm having second doubt about this) only.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to keep them separate? In my mind, this seems like it will just introduce more surface area for inconsistent state bugs.

Copy link
Contributor Author

@etpinard etpinard May 30, 2016

Choose a reason for hiding this comment

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

Mostly for convenience.

Most of our per-subplot code post-supply-defaults is designed as:

  1. loop over all subplots of a given type found fullLayout
  2. create a subplot object or update an existing subplot object in fullLayout[/* name of subplot */]._subplot

So, it becomes convenient to store a ref to the subplot object in its corresponding fullLayout attribute container.

Moreover, as finding all xy subplots in a given figure is somewhat expensive (see Axes.getSubplots), it becomes advantages to look for them in fullLayout._plots directly instead of calling Axes.getSubplots every time we need to loop over all the x/y subplots.

@mdtusz
Copy link
Contributor

mdtusz commented May 30, 2016

Looks good to me. 💃

@etpinard etpinard merged commit 923871a into master May 31, 2016
@etpinard etpinard deleted the general-subplot-hover branch May 31, 2016 15:05
etpinard added a commit that referenced this pull request Jun 13, 2016
- looks like fullLayout._plots does not get updated properly
  on resize. Fixing that deserves a PR of its own.
- this commit reverts to the pre-#575 behavior
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