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

Add layout.subplots to enable (x|y) hover effects across multiple cartesian and splom suplots sharing one axis #6947

Merged
merged 17 commits into from
Apr 9, 2024

Conversation

archmoj
Copy link
Contributor

@archmoj archmoj commented Apr 3, 2024

Resolves #4755 and resolves #2114.

@plotly/plotly_js

TODO:

  • Handle splom
  • Should it be new hovermode options e.g. 'x all', x all unified, y all and y all unified instead? --> No.
  • Improve positioning of unified hover to be closer to initial hovered subplot

@archmoj archmoj changed the title Add option to enable hover effects across multiple cartesian suplots sharing one axis Add layout.hoversameaxis to enable hover effects across multiple cartesian suplots sharing one axis Apr 4, 2024
@emilykl
Copy link
Contributor

emilykl commented Apr 4, 2024

LGTM @archmoj .

Re: API design -- I do think this should be its own property, the way you have it, rather than adding more hovermodes, since adding so many keywords in the hovermode starts to get pretty unwieldy. I'm not sure the name hoversameaxis captures what this feature actually does though. Thinking on it.

Maybe something like hoverthrough?

@archmoj
Copy link
Contributor Author

archmoj commented Apr 5, 2024

LGTM @archmoj .

Re: API design -- I do think this should be its own property, the way you have it, rather than adding more hovermodes, since adding so many keywords in the hovermode starts to get pretty unwieldy. I'm not sure the name hoversameaxis captures what this feature actually does though. Thinking on it.

Maybe something like hoverthrough?

Thanks @emilykl for the feedback.
I was thinking of a separate case that we may want to support in future i.e. something like hovermode: 'xy' or '+' it could display effect on subplots on both x and y directions.

Also it may be possible to add another option to this feature so that the hover show points in suplots above & below (or left & right) even if they are NOT linked to the same axis.

Perhaps instead of the *true* option we should have a string option so that it could be developed further.
Something like: hoverthrough: 'axis'?

cc: @alexcjohnson

@archmoj archmoj changed the title Add layout.hoversameaxis to enable hover effects across multiple cartesian suplots sharing one axis Add layout.hoverthrough to enable hover effects across multiple cartesian suplots sharing one axis Apr 5, 2024
@archmoj archmoj changed the title Add layout.hoverthrough to enable hover effects across multiple cartesian suplots sharing one axis Add layout.hoverthrough to enable hover effects across multiple cartesian and splom suplots sharing one axis Apr 5, 2024
@alexcjohnson
Copy link
Collaborator

How about layout.hoversubplots with values (eventually, wouldn’t need to implement all of these now) single (just the axis pair of the primary point), overlaying (all subplots using the main axis and occupying the same space), axis (also include stacked subplots using the same axis) and matching (also include other axes matching the main axis)

@archmoj archmoj changed the title Add layout.hoverthrough to enable hover effects across multiple cartesian and splom suplots sharing one axis Add layout.subplots to enable (x|y) hover effects across multiple cartesian and splom suplots sharing one axis Apr 8, 2024
@emilykl
Copy link
Contributor

emilykl commented Apr 8, 2024

How about layout.hoversubplots

I like this.


afterEach(destroyGraphDiv);

it('splom hoversubplots: *axis*', function() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Splom has an additional constraint that I don't believe is tested here, and I suspect is broken: If the main hovered point has the same coordinate as some other points, every point we show on other axes should be the same item on other axes. For example, let's say we have this data:

dimensions: [{
  values: [1, 1, 1, 1]  // hover on a subplot where this is the x axis, so all points are in a vertical line
}, {
  values: [1, 2, 3, 4]  // put the mouse at y=2 on this subplot
}, {
  values: [1, 2, 3, 4]  // we should see y=2 hovered in this subplot as well
}, {
  values: [1, null, 3, 4]  // no hover points should be displayed on this subplot
}]

Copy link
Collaborator

Choose a reason for hiding this comment

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

This actually makes me wonder if we should use pointNumber as a tiebreaker (and possible performance improvement) for generic multi-trace hover, either same or different subplots: After we've found the primary hovered point, for each additional trace we examine, see if (a) the data arrays have the same length as those for the primary point, (b) the data point with the same index satisfies the criteria to be another point in the hover set (ie the x value matches, for x or x unified modes). If so, use it and don't bother searching the whole trace. If either of those conditions is not met, assume the points in these traces aren't supposed to correspond 1:1 to each other and continue with the way we do this today.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch for splom.
It is addressed in d9aea4b.

Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

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

💃 lovely!

@wuyuanyi135
Copy link

would typescript stubs get updated for this?

Current latest:

"@types/plotly.js": "^2.33.3",
"@types/plotly.js-dist-min": "^2.3.4",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT] "x unified" hover mode working across subplots Hover labels across shared axes
4 participants