Unexpected Behaviour - CDSView Plot displays HoverTool tips for all data in ColumnDataSource

Hi all,

I have recently been working on an application creating interactive line plots in Bokeh, using a GroupFilter and CDSView to filter a large ColumnDataSource and plot multiple lines, using CustomJS callbacks to update the filter based off the value of a widget to switch the data being plotted by year. However, I am also trying to get a HoverTool in hit-test mode ‘vline’ to display tooltips for the plot, and here I run into some unexpected (to me at least) behaviour: the tooltips seem to appear for all data points in the ColumnDataSource, including those not currently being displayed on the plot, not just for the filtered glyphs in the view that are being displayed. I’ve created a simple example below that mirrors the sort of functionality I want for the larger scale use-case and replicates the problem:

import numpy as np
from bokeh.models import ColumnDataSource, CustomJS, CDSView, GroupFilter, HoverTool, Select
from bokeh.plotting import figure
from bokeh.layouts import layout
from bokeh.io import show

years = [‘2018’, ‘2018’, ‘2018’, ‘2018’, ‘2019’, ‘2019’, ‘2019’, ‘2019’]
X = [1, 2, 3, 4, 1, 2, 3, 4]

data = {‘year’: years, ‘x’: X, ‘y1’: np.arange(1, 9), ‘y2’: np.arange(11, 19)}
source = ColumnDataSource(data)

year_filter = GroupFilter(column_name=‘year’, group=‘2018’)
view = CDSView(source=source, filters=[year_filter])

plot = figure(title=‘testing_hover_cdsview_plot’)
plot.line(x=‘x’, y=‘y1’, source=source, view=view, color=‘blue’)

get only one tooltip box to appear per plot

plot.line(x=‘x’, y=‘y2’, source=source, view=view, name=‘hover’, color=‘red’)

tool_list = [(“y1”, “@y1”), (“y2”, “@y2”)]
hover = HoverTool(tooltips=tool_list, names=[‘hover’], mode=‘vline’)

select = Select(title=‘switch’, options=[‘2018’, ‘2019’], value=‘2018’)
code = “”"
year_filter.group = select.value;

js_dict = {‘year_filter’: year_filter, ‘select’: select, ‘view’: view}
callback = CustomJS(args=js_dict, code=code)
select.js_on_change(‘value’, callback)

layout = layout([select, plot])

The behaviour I would like is for the HoverTool to only displays tooltips for the glyphs currently being shown (i.e. in the active view), but I haven’t been able to find a way to do this - ideally I would like to do something similar to the way the tooltips only appear for the top line in the code above, e.g. attach a name to a CDSView and a HoverTool so tooltips only appear for that named View, but that doesn’t seem to work.

I have tried rewriting the whole logic a) using Python callbacks in the Bokeh server and b) so the JS callback switches the entire ColumnDataSource, which does allow me to get the behaviour I want, but for various reasons aren’t approaches I can use with my larger scale use-case so I would ideally like to be able to solve in a similar way to above.

Any help would be much appreciated; running on python 3.6.0 bokeh 0.12.15.