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

✨ (grapher) pin tooltips to the bottom on mobile / TAS-664 #4082

Merged
merged 9 commits into from
Nov 14, 2024

Conversation

sophiamersmann
Copy link
Member

@sophiamersmann sophiamersmann commented Oct 25, 2024

Pin tooltips to the bottom of the screen on mobile for a more pleasant UX. When pinned to the bottom, the tooltip hides less of the chart area and isn't "in the way" when interacting with a chart. This also fixes several overflow issues for very tall tooltips.

Summary

  • If the tooltip content is very tall, then the tooltip content becomes scrollable
    • This is also the reason why the tooltip stays on screen even after an interaction has ended
  • A tooltip can be dismissed by clicking anywhere on the screen
  • A tooltip is automatically dismissed when Grapher is scrolled out of view
  • For tooltips that have a "Total" row (e.g. for stacked area charts), the total row is moved to the top, so that it's visible by default even if the tooltip is scrollable

Notes

  • To detect when Grapher is scrolled out of view, we keep Grapher's intersection observer around (we used to disconnect it after Grapher has been first scrolled to). That might have a perf impact? I can't imagine the perf impact being too bad since we very rarely have more than 10 rendered Graphers on a site.
  • After making these changes, map charts errored when trying to render a map tooltip with a MobX issue like "Dynamic observables can't be frozen". I didn't manage to understand what the problem was, but the MapTooltip/MapSparkline refactor resolves the issue 🤷🏻‍♀️
  • An event handler is registered on the document to dismiss the tooltip when clicking outside of the chart area. This doesn't work if propagation is stopped. This is the case for the the entity selector toggle and the timeline. That's why the tooltip is explicitly dismissed when clicking on the timeline or the entity selector toggle

Caveats

  • If a tooltip is open and then gets dismissed because the entity selector is opened, for example, we ideally want the tooltip to disappear immediately. But for some chart types, tooltips fade out with some delay (e.g. scatter plots).

Example charts

Testing

This behaviour only kicks in for touchscreen devices, so it's best to look at these changes on an actual phone.

Drive-by changes

  • I removed the computed properties for frame padding – all that passing around wasn't really necessary for a couple of constants

Screenshot

Screenshot 2024-06-05 at 14 54 46

Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @sophiamersmann and the rest of your teammates on Graphite Graphite

@owidbot
Copy link
Contributor

owidbot commented Oct 25, 2024

Quick links (staging server):

Site Admin Wizard

Login: ssh owid@staging-site-mobile-tooltips-fixed-bottom

SVG tester:

Number of differences (default views): 0 ✅
Number of differences (all views): 5 (d3dfed) ❌

Edited: 2024-11-14 17:01:06 UTC
Execution time: 1.46 seconds

@sophiamersmann sophiamersmann force-pushed the mobile-tooltips-fixed-bottom branch 2 times, most recently from 7221299 to 2f83f44 Compare October 28, 2024 11:42
@sophiamersmann sophiamersmann changed the title ✨ (grapher) show tooltip at the bottom on mobile ✨ (grapher) pin tooltips to the bottom on mobile Oct 28, 2024
@sophiamersmann sophiamersmann force-pushed the mobile-tooltips-fixed-bottom branch 3 times, most recently from d68a5c5 to bae4058 Compare October 30, 2024 16:30
@sophiamersmann sophiamersmann marked this pull request as ready for review October 30, 2024 16:55
Copy link
Member

@marcelgerber marcelgerber left a comment

Choose a reason for hiding this comment

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

Really nice work here, I like the new behavior.

I tested this on desktop and mobile. On desktop I didn't notice any issues. On mobile I noticed two:

  • When clicking on "Learn more about this data" on a data page (which scrolls down), the tooltip stays visible even though the chart itself leaves the viewport. Maybe the IntersectionObserver doesn't fire for programmatic scrolls?
  • The tooltip also stays visible when clicking the download button and the share button

I'm wondering if there is a better way to register click events - maybe use a {capture: true} event handler to catch them all??

@sophiamersmann
Copy link
Member Author

Ah, damn it. I've thought about using a capture event but I don't think that works because interacting with the chart shouldn't dismiss the tooltip. If we wanted to use a capture event for the document, we would also need to use capture events for chart event handlers, which I thought was too much of a weird constraint.

@marcelgerber
Copy link
Member

I think a capturing event handler would work?

I agree about that clicking inside the chart area should not dismiss the tooltip, but that we can handle inside the event handler.

When searching through the code just now, I saw that SettingsMenu and SlideInDrawer are, in fact, already using capturing event handlers.

See SettingsMenu here - inside the handler, it checks whether the click target is inside the settings menu. We can do a similar thing for the charting area also.

@sophiamersmann
Copy link
Member Author

Ah, that's not something I considered. Yes, that should work!

@sophiamersmann sophiamersmann force-pushed the mobile-tooltips-fixed-bottom branch 2 times, most recently from 9a86490 to 1e82efa Compare November 7, 2024 13:57
@marcelgerber
Copy link
Member

I'm currently confused how dismissing the tooltip works for chart types other than line & stacked? How does it work for maps, for example - they don't seem to have a handler inside MapChart.tsx?

@sophiamersmann
Copy link
Member Author

Line charts and stacked area charts are special because they implement touch events so you can hold your thumb down, and on movement, the tooltip gets updated. Other chart types don't do this. They only register mouse enter and leave events. So, if you press down on an element on mobile, then the mouse enter event is fired (showing the tooltip), and if you click anywhere else, then the mouse leave event is fired (dismissing the tooltip).

@sophiamersmann sophiamersmann force-pushed the mobile-tooltips-fixed-bottom branch 3 times, most recently from 014a681 to f7a54a5 Compare November 8, 2024 09:51
@sophiamersmann
Copy link
Member Author

The code is now using a capture event handler, but for some reason it doesn't get fired when interacting with the timeline. I'm not sure why – that's why, when interacting with the timeline, the tooltip still gets dismissed explicitly.

@sophiamersmann sophiamersmann changed the title ✨ (grapher) pin tooltips to the bottom on mobile ✨ (grapher) pin tooltips to the bottom on mobile / TAS-664 Nov 11, 2024
Copy link

@sophiamersmann
Copy link
Member Author

@marcelgerber this is good to go from my side. Do you think we can get this over the finish line? No worries if you would need too much to finish the review though :)

Copy link
Member

@marcelgerber marcelgerber left a comment

Choose a reason for hiding this comment

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

Yes, good to go now! 🚀

@sophiamersmann sophiamersmann force-pushed the mobile-tooltips-fixed-bottom branch from 0822d26 to 9bd1fae Compare November 14, 2024 13:53
@sophiamersmann sophiamersmann force-pushed the mobile-tooltips-fixed-bottom branch from 0804147 to 613742d Compare November 14, 2024 16:43
@sophiamersmann sophiamersmann merged commit d1926da into master Nov 14, 2024
19 of 21 checks passed
@sophiamersmann sophiamersmann deleted the mobile-tooltips-fixed-bottom branch November 14, 2024 17:15
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.

Grapher should fix the position of tooltips to the bottom on mobile
3 participants