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

feat(python): Add tooltip by default to charts #18625

Merged
merged 2 commits into from
Sep 11, 2024

Conversation

MarcoGorelli
Copy link
Collaborator

@MarcoGorelli MarcoGorelli commented Sep 9, 2024

I think this is quite nice as the plot is then more interactive by default (and something Altair might want to do anyway? vega/altair#3394)

cc @joelostblom fancy taking a look? does this make sense?

Demo (the tooltip appears where I had my pointer):

Animation


Separate PR incoming to improve docs

@MarcoGorelli MarcoGorelli changed the title feat(python): add tooltip by default to charts feat(python): dd tooltip by default to charts Sep 9, 2024
@MarcoGorelli MarcoGorelli changed the title feat(python): dd tooltip by default to charts feat(python): Add tooltip by default to charts Sep 9, 2024
@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars and removed title needs formatting labels Sep 9, 2024
Copy link

codecov bot commented Sep 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.90%. Comparing base (aa3b2c3) to head (d15c672).
Report is 27 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #18625      +/-   ##
==========================================
- Coverage   79.94%   79.90%   -0.05%     
==========================================
  Files        1505     1506       +1     
  Lines      202579   203219     +640     
  Branches     2873     2887      +14     
==========================================
+ Hits       161958   162383     +425     
- Misses      40073    40289     +216     
+ Partials      548      547       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 9 to 14
from altair.typing import ChannelColor as Color
from altair.typing import ChannelOrder as Order
from altair.typing import ChannelSize as Size
from altair.typing import ChannelX as X
from altair.typing import ChannelY as Y
from altair.typing import EncodeKwds
Copy link
Contributor

Choose a reason for hiding this comment

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

Just linking the context for this change #18609 (comment)

cc'ing @mattijn as this is a possible solution for vega/altair#3582 (comment)

tooltip
Columns to show values of when hovering over bars with pointer.
**kwargs
Additional keyword arguments passed to Altair.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

note that this is a backwards-compatible change, as anyone passing tooltip will still have their code work due to **kwargs

Copy link

@joelostblom joelostblom left a comment

Choose a reason for hiding this comment

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

I think tooltips by default is convenient and the approach here seems to make sense to me. Just one minor comment.

Comment on lines 33 to 35
def _add_tooltip(chart: alt.Chart) -> alt.Chart:
chart.mark = {"type": chart.mark, "tooltip": True}
return chart
Copy link

@joelostblom joelostblom Sep 9, 2024

Choose a reason for hiding this comment

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

Are marks guaranteed to be strings here? It seems like they are by default in polars, but I'm flagging just in case you want to do something like this to check that the mark is not a dict (which you might already have seen).

Copy link
Contributor

Choose a reason for hiding this comment

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

@joelostblom I'm pretty sure @MarcoGorelli has been peeking at that PR 😉

Maybe I'm being overly cautious here, but I'm not sure we've tested this thoroughly enough for it to be included in polars without any tests yet

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks both!

I've reworked this to create tooltip= explicitly, reckon this is more robust / robust-enough?

Choose a reason for hiding this comment

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

Looks good to me too

Copy link
Contributor

@dangotbanned dangotbanned left a comment

Choose a reason for hiding this comment

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

thanks both!

I've reworked this to create tooltip= explicitly, reckon this is more robust / robust-enough?

Yeah this is great d15c672 (#18625)

Thanks @MarcoGorelli

@ritchie46 ritchie46 merged commit 120a5e2 into pola-rs:main Sep 11, 2024
15 checks passed
@AdrienDart
Copy link

Hi, this is causing issues on my side with Schema validation error: try using df.plot.line(x=alt.X("date", axis=alt.Axis(labelAngle=-90), y='price', color='stock')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants