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

x-unified hover tooltips overflow #5721

Closed
xenatisch opened this issue Jun 8, 2021 · 7 comments · Fixed by #5846
Closed

x-unified hover tooltips overflow #5721

xenatisch opened this issue Jun 8, 2021 · 7 comments · Fixed by #5846
Labels
bug something broken
Milestone

Comments

@xenatisch
Copy link

Synopsis

The hover tooltips in x-unified mode exceed max-width and therefore overflow. This happens when:

  • the chart is small and close to the sides
  • the chart is large (near width size) on a small screen - e.g. mobile
  • the tooltip is displayed for a point on the chart that falls near the mid-point of the x-axis

The issue persists in Plotly v2.0.0.

Example

You can see an example of the issue on our live service, provided that your browser width is smaller than ~580px.

Screenshot 2021-06-08 at 14 52 22

Expected behaviour

The hover tooltip x-extrema must always fall between x-extrema of the browser. An even better outcome would be for the tooltip to not spill out of the cartesian axes.

I don't think there's an easy / immediate solution to this, primarily because the tooltip position moves based on cursor position. I suppose one way to address it is to do what folks at Google Charts have done - i.e. move the tooltip until it hits one side, then stop moving horizontally.

Here's an example, which you've probably seen before:

google-sample
[Credit: Google]

Thanks again for all your efforts.

xenatisch referenced this issue in UKHSA-Internal/coronavirus-dashboard Jun 8, 2021
@nicolaskruchten
Copy link
Contributor

I actually think this is "just a bug" where the hoverlabel should be on the left-hand side if there is room there. If there not enough room on either side then yes, we will need some new behaviour.

@alexcjohnson
Copy link
Collaborator

Seems like in this plot we've set the figure width to a half-integer, and perhaps due to rounding that's allowing us to draw the hover label 1px beyond the true displayed edge of its container. If we keep all our hover labels 1px away from the edges no matter what (just change by 1px the condition for flipping the label to the left side), that should fix this.

@alexcjohnson alexcjohnson added the bug something broken label Jun 8, 2021
@nicolaskruchten
Copy link
Contributor

The hoverlabel looks like it's much more than 1px beyond the edge, though, no?

@nicolaskruchten
Copy link
Contributor

Ah I see, this is just a really wide hoverlabel and there is a zone where there is no room on either the left or the right :(

In this case @xenatisch I would recommend using newlines i.e. <br> in the hovertemplate if you can on narrow screens? Like before "daily" or something?

@alexcjohnson
Copy link
Collaborator

Ah right, x unified doesn't seem to have the centered fallback for when there isn't room on either side like closest and x modes have. We should add that. But I was definitely able to get a situation where there was plenty of room on the left for the whole label, yet it was shown on the right side with just 1px border cut off. So I think we should pad it 1px as well.

@xenatisch
Copy link
Author

So, there are two issues here - one is ours, the other is yours:

  • Some of our labels are just too long, and that needs to be fixed. This is something for our content team to think about as the labels are set dynamically.
  • Where the labels aren't toooo long, some of the tooltips still overflow, and that's the topic of this issue.

In the latter case, as you highlighted eloquently, there is indeed enough space on one side, but the tooltip still overflows without using the space that's available. This, however, tends to happen when we're near the mid-point. How close to the mid-point? That would depend on the width of the tooltip itself.

This clip shows the problem more clearly (I think / hope):

Here's the link to the graph in the clip in case you want to experiment with it yourself.

tooltip-thing.mov

@xenatisch
Copy link
Author

Hallelujah. Thanks @nicolaskruchten, @archmoj, and @alexcjohnson. Looking forward to 2.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
4 participants