I have some code where I am using CustomJS code to control the visibility state of glyphs in a plot instead of the standard click_policy=“hide”, and while my code is able to hide the glyphs just fine, the glyph and label text in the legend does not change to a muted state like it does when using click_policy. Is there any way I can implement this to happen manually with CustomJS?
Here is a minimal example that reproduces the behaviour (I am running Bokeh version 3.9.1):
from bokeh.models import CustomJS, Legend, LegendItem
from bokeh.plotting import figure, show
p = figure()
line = p.line([0, 3], [0, 3], color='red')
legend = Legend(
items=[LegendItem(label='line', renderers=[line], name='line')]
)
p.add_layout(legend, 'right')
code = """
let name = this.item.name;
if (name === "line") {
if (line.visible) {
line.visible = false;
} else {
line.visible = true;
}
}
"""
callback = CustomJS(args=dict(line=line), code=code)
legend.js_on_click(callback)
show(p)

