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 hover_tooltips, hover_mode, hover_formatters opts to easily modify hover #6180

Merged
merged 26 commits into from
Apr 16, 2024

Conversation

ahuang11
Copy link
Collaborator

@ahuang11 ahuang11 commented Apr 9, 2024

See discussion at #1816 (comment)

Screen.Recording.2024-04-09.at.3.29.35.PM.mov

resolves #1816

@ahuang11 ahuang11 added the type: enhancement Minor feature or improvement to an existing feature label Apr 9, 2024
@codecov-commenter
Copy link

codecov-commenter commented Apr 11, 2024

Codecov Report

Attention: Patch coverage is 31.71806% with 155 lines in your changes are missing coverage. Please review.

Project coverage is 88.28%. Comparing base (bf4592e) to head (fb07cf8).
Report is 6 commits behind head on main.

Files Patch % Lines
holoviews/tests/ui/bokeh/test_hover.py 20.93% 102 Missing ⚠️
holoviews/plotting/bokeh/element.py 45.91% 53 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6180      +/-   ##
==========================================
- Coverage   88.70%   88.28%   -0.42%     
==========================================
  Files         316      318       +2     
  Lines       66121    66416     +295     
==========================================
- Hits        58650    58636      -14     
- Misses       7471     7780     +309     
Flag Coverage Δ
ui-tests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@droumis
Copy link
Member

droumis commented Apr 11, 2024

Hey @ahuang11 , no problem for this time, but in the future would you mind pasting in your test code utilized in video demos?

@ahuang11
Copy link
Collaborator Author

Yeah I forgot to do so this time and I've already lost the code for that, but the edited notebook should have everything you need to try out all the functionality

@droumis
Copy link
Member

droumis commented Apr 11, 2024

Looks great with subcoordinate_y! Nice work. Not a big deal but the only thing I couldn't figure out yet is how to have the unit included in the tooltip when the unit is set in the hv.Dimension and a formatter is applied in hover_tooltips, like {0.2f} (see 'amplitude' vs 'time'). It's not a big deal to add the unit it manually though.

Code
import numpy as np
import holoviews as hv; hv.extension('bokeh')

n_channels = 4
n_seconds = 300
fs = 256
init_freq = .01  # Initial sine wave frequency in Hz
freq_inc = 2/n_channels  # Frequency increment
total_samples = n_seconds * fs
time = np.linspace(0, n_seconds, total_samples)
channels = [f'CH {i}' for i in range(n_channels)]

data = np.array([np.sin(2 * np.pi * (init_freq + i * freq_inc) * time)
                 for i in range(n_channels)])
# print(f'shape: {data.shape} (n_channels, samples) ')

time_dim = hv.Dimension('Time', unit='s')
amplitude_dim = hv.Dimension('Amplitude', unit='µV')

curves = []
for channel, channel_data in zip(channels, data):
    ds = Dataset((time, channel_data), [time_dim, amplitude_dim])
    curve = hv.Curve(ds, time_dim, amplitude_dim, group='EEG', label=f'{channel}')
    curve.opts(
        subcoordinate_y=True,
        subcoordinate_scale=.75,
        color="black",
        line_width=1,
        tools=['hover'],
        hover_tooltips=[
            ("Group", "$group"),
            ("Channel", "$label"),
            "Time",
            ("Amplitude", "@Amplitude{0.2f}")],
        # hover_mode = 'vline',
        )
    curves.append(curve)

curves_overlay = hv.Overlay(curves, kdims="Channel")
curves_overlay = curves_overlay.opts(
    ylabel="Channel",
    show_legend=False,
    aspect=3.5,
    responsive=True,
    shared_axes=False,
    xlim=(50,150),
    title='Multi-Channel Timeseries',
)

curves_overlay

image

and some fun with hover_mode = 'vline':

Screen.Recording.2024-04-11.at.1.19.59.PM.mov

@ahuang11
Copy link
Collaborator Author

ahuang11 commented Apr 11, 2024

Ah, right as you commented, I just finished all the unit tests, and I think I fixed it in the newest push. Let me also try...

@ahuang11 ahuang11 marked this pull request as ready for review April 11, 2024 20:31
@ahuang11 ahuang11 requested a review from droumis April 11, 2024 20:31
@ahuang11
Copy link
Collaborator Author

Oh I guess it's not yet supported. I can add a if unit, then add it as ()

@ahuang11
Copy link
Collaborator Author

ahuang11 commented Apr 11, 2024

Okay it should work with your code now; tests also added!

image

@ahuang11 ahuang11 changed the title Start implementing hover tooltips Add hover_tooltips, hover_mode, hover_formatters opts to easily modify hover Apr 11, 2024
@ahuang11
Copy link
Collaborator Author

ahuang11 commented Apr 11, 2024

and some fun with hover_mode = 'vline':

Would be a nice Bokeh feature to have to have like hover_align="left", "center", "right"

Interestingly, it does seem to be automatic on bokeh
image

image

@ahuang11 ahuang11 requested a review from hoxbro April 12, 2024 20:13
examples/user_guide/Plotting_with_Bokeh.ipynb Outdated Show resolved Hide resolved
holoviews/plotting/bokeh/element.py Outdated Show resolved Hide resolved
holoviews/plotting/bokeh/element.py Outdated Show resolved Hide resolved
holoviews/plotting/bokeh/element.py Outdated Show resolved Hide resolved
@ahuang11
Copy link
Collaborator Author

Should be ready for re-review if needed.

The UI tests passes in my local machine, but I noticed it failed here. I added flaky markers.

@ahuang11 ahuang11 requested a review from hoxbro April 15, 2024 15:51
@hoxbro
Copy link
Member

hoxbro commented Apr 15, 2024

For the flaky tests, try using wait_until.

@ahuang11
Copy link
Collaborator Author

Eh the test just refuses to pass...

holoviews/plotting/bokeh/element.py Outdated Show resolved Hide resolved
examples/user_guide/Plotting_with_Bokeh.ipynb Outdated Show resolved Hide resolved
examples/user_guide/Plotting_with_Bokeh.ipynb Outdated Show resolved Hide resolved
examples/user_guide/Plotting_with_Bokeh.ipynb Outdated Show resolved Hide resolved
@ahuang11 ahuang11 requested a review from hoxbro April 16, 2024 15:33
@hoxbro hoxbro enabled auto-merge (squash) April 16, 2024 15:53
@hoxbro hoxbro merged commit 97d648b into main Apr 16, 2024
12 checks passed
@hoxbro hoxbro deleted the hover_tooltips branch April 16, 2024 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Minor feature or improvement to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Easy specification of dimensions for hover tool
4 participants