Hide tooltips from linked plots

Hi all,

I have several plots that share a ColumnDataSource and each use a different CDSView. The problem I’m having is that when you hover over one plot, the tooltips show for every plot instead of just for the plot you’re hovering over. I’ve attached the code below that creates the plots and hovertools (normally part of a function that’s called as needed). Any help would be greatly appreciated, thanks!

TOOLS = 'hover,crosshair'

p = figure(tools=TOOLS, plot_width=plot_width, plot_height=plot_height, toolbar_location=None,
           x_axis_type='datetime', sizing_mode='scale_width', css_classes=['plot'])

# historical
g = p.line('date_time', 'speed_past', color='#000000', source=source, view=CDSView(source=source, filters=filters))

# live
p.line('date_time', 'speed', color='#ffffff', source=source, view=CDSView(source=source, filters=filters))

# HoverTool
hover = p.select(dict(type=HoverTool))
hover.renderers = [g]
hover.mode = 'vline'
hover.show_arrow = False
hover.point_policy = 'follow_mouse'
hover.tooltips = [
    ('Route', '@name'),
    ('Time', '@date_time{%H:%M}'),
    ('Speed (actual)', '@speed_str'),
    ('Speed (historical)', '@speed_past{0f}mph')
]
hover.formatters = {'date_time': 'datetime'}

Hi Evan_Nowak,

The way things are right now, your best solution to avoid this HoverTool behavior is probably to not share data sources. Inspection events, which drive HoverTools, are based on the ColumnDataSource, so your CDSView isn’t taken into account; this aligns with the behavior you describe.

I don’t know all the details of your scenario, but for today, you may want to just create separate versions of your ColumnDataSource for each plot based on whatever your CDSView filtering criteria are. You could also open a GitHub issue to describe your use case and requirements, and discuss proposed new behavior with inspection events and CDSViews.

Hi Carolyn,

Thanks for replying (again). I was hoping I wouldn’t have to create separate ColumnDataSources, but that’s what I’ll do if necessary. Maybe there’s a CustomJS workaround?

It might be possible to use CustomJS with mouse enter/leave events, toggle the visibility of tooltips on plots based on whether the cursor is over the plot or not.

Thanks for the suggestion Bryan, I’ll give it a try.