Skip to content

Hovering for points on non-overlaying y-axes for same x-value (and same plot) #290

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

Closed
Abildtoft opened this issue Feb 28, 2016 · 9 comments

Comments

@Abildtoft
Copy link

Hi,

For a medical app, I have created a plot wherein i stack 4 y-axes (e.g., 'yaxis' has domain [0.00, 0.24], 'yaxis2' has [0.25, 0.48], ...), while they all share the same date x-axis. My reason for stacking them instead of overlaying them is not only that they each represent quite disparate ranges (each with their own unit), but also have quite different 'sub-ranges' (e.g., what range constitutes an 'acceptable' value).

Stacking instead of overlaying, however, breaks the 'x'-hovermode insofar as it limits itself to only look for points with the same x-value as the 'originally hovered'-point within overlaying subplots. When I tried to write my own "plotly_hover" event handler, I realized that Plotly.Fx.hover does not allow for the specification of a subplot per point (in the array one can supply in the 'evt' variable), but can only be specified generically for all points with the 'subplot' variable.

Am I missing a workaround that still allows me to use your awesome built-in hover functionality without attempting to rewrite it myself, or dropping it in favor of the dirtiness of dynamically adding and removing annotations?

In any case, thanks for an awesome library.

@etpinard
Copy link
Contributor

I realized that Plotly.Fx.hover does allow for the specification of a subplot per point

This example: https://plot.ly/javascript/hover-events/#triggering-hover-events should answer your question.

If not, could you please paste a link to a reproducible example on codepen / jsbin / jsFiddle as mentioned in our contributing guidelines ?

@Abildtoft
Copy link
Author

I'm so new to GitHub that I didn't even realize that there were contributing guidelines, my mistake for not checking before writing. As for your quote, I mistakenly left out a "not" as should be clear from the context. I apologize for the poor quality of my input.

As jsFiddle of my graph is available here.

The example you linked - which I used as my starting point - provides no 'subplot' variable to Plotly.Fx.hover which then defaults to 'xy' (and in the given example, that is the only x & y combination). As you can see in the code for Fx.hover (from line 66663 in plotly.js version 1,6.0), subplot is given not per point but generically for all points. And in my use case, this means that i cannot (to the best of my knowledge) trigger hovering for points on xy, xy1, etc. at the same time when using Fx.hover, being limited to one subplot at a time.

I hope this makes my issue more understandable and I do recognize that this is probably a (very) fringe use case.

Thank you for your time

@john-soklaski
Copy link
Contributor

I have a need for this as well. I've previously prototyped an implementation that allows fx.hover to take an array of subplots.

I've updated your jsFiddle with my forked version:
https://jsfiddle.net/2v2qp0hy/2/

You can see my changes here:
https://github.com/john-soklaski/plotly.js/tree/subplot_hover

@etpinard
Copy link
Contributor

@john-soklaski your patch is looking good. Would you mind making a PR to this repo?

@Abildtoft
Copy link
Author

@john-soklaski and @etpinard thanks for the help, this was exactly what I was looking for.

@john-soklaski
Copy link
Contributor

@etpinard Thanks! I intend to submit a PR, but hadn't had a chance to write unit tests or test with a graph with horizontal hovering. Would you prefer I send a PR now and those things can come after?

There is also this behavior if the points on the other plots don't share an x value, but are near-enough:

image

I'm not sure what the behavior should be here. Any thoughts?

@etpinard
Copy link
Contributor

etpinard commented Mar 1, 2016

Would you prefer I send a PR now and those things can come after?

Yes, please make a PR out of the patch you wrote already. We'll take the discussion from there.

There is also this behavior if the points on the other plots don't share an x value

Looks like what you have mimics what is displayed on a multi-trace / single-set-of-axes plot with layout.hovermode set to 'x'. I believe this is the behavior we want.

@john-soklaski
Copy link
Contributor

I've created PR #301 to add this feature

@etpinard
Copy link
Contributor

etpinard commented Mar 8, 2016

Closed via #301

@etpinard etpinard closed this as completed Mar 8, 2016
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

No branches or pull requests

3 participants