holoviz / holoviews

With Holoviews, your data visualizes itself.
https://holoviews.org
BSD 3-Clause "New" or "Revised" License
2.69k stars 402 forks source link

Group or hide hover tools in Bokeh toolbar #6252

Open droumis opened 4 months ago

droumis commented 4 months ago

Is your feature request related to a problem? Please describe.

Too many hover tools when overlaying many elements with custom hover.

Describe the solution you'd like

Group or hide the hover tooltips

Additional context

Code ```python import numpy as np import pandas as pd from datetime import datetime, timedelta import holoviews as hv; hv.extension('bokeh') import panel as pn; pn.extension() amp_dim = hv.Dimension("amplitude", unit="µV") time_dim = hv.Dimension("time", unit="ms") n_channels = 10 n_seconds = 5 total_samples = 256*n_seconds start_datetime = datetime(2024, 1, 1) time = np.array([start_datetime + timedelta(seconds=t) for t in np.linspace(0, n_seconds, total_samples)]) data = np.random.randn(n_channels, total_samples).cumsum(axis=1) channels = [f"EEG {i}" for i in range(n_channels)] df = pd.DataFrame(data.T, index=time, columns=channels) df.index.name = 'time' hover_tooltips=[ ("type", "$group"), ("channel", "$label"), ("time", '@time{%H:%M:%S.%3N}'), ("amplitude"), ] curves = {} for channel_name, channel_data in df.items(): ds = hv.Dataset((channel_data.index, channel_data, channel), [time_dim, amp_dim, "channel"]) curve = hv.Curve(ds, time_dim, [amp_dim, "channel"], label=channel_name, group='EEG') curve.opts(color="black", line_width=1, subcoordinate_y=True, subcoordinate_scale=3, hover_tooltips = hover_tooltips) curves[channel_name] = curve curves_overlay = hv.Overlay(curves, kdims="channel").opts(padding=0, aspect=2, responsive=True,show_legend=False) curves_overlay ```

image

droumis commented 4 months ago

@mattpap , this could be solved with the ability to group tools which is sounds like you are working on.

mattpap commented 4 months ago

Yes. The relevant bokeh issue is https://github.com/bokeh/bokeh/issues/5497 (a very old one).

droumis commented 4 months ago

observation: if I create a custom bokeh HoverTool, and pass that in like .opts(tools=[HoverTool()] then the hover tools are combined in the toolbar.

droumis commented 4 months ago

observation: adding a plot with many hover tool icons into a layout container seems to group the tools...

image image
droumis commented 3 months ago

even just hv.Layout((overlay, hv.Empty())

philippjfr commented 3 months ago

Yeah, we should probably run the group_tools function even on a singular plot.

droumis commented 3 months ago

e.g. as we do here for a Layout toolbar