Extend Legend Class


Hi, I’m trying to build a timeline plot which currently looks like the graph

I plot the lines, circles and the slanting text as separate glyphs.

The mute policy on the Legend works for the vertical lines, but I would like it work for the dot and text related to the line (they’re one group really) so that when I mute one of the groups, the corresponding line, dot and text are muted.

Can I extend the Legend class in some way to allow me to do this? I’ve not seen any examples around.

Regards, Roger.

@Roger most of the actual work for Bokeh is done in the runtime BokehJS library in the browser, so extending Bokeh in this case would mean developing Typescript components, which I am guessing is not what you have in mind.

That said, I don’t think you’d need to extend anything. I can think of a couple of ways this might be accomplished. Without a complete Minimal Reproducible Example, it’s hard to know which might be most applicable to your code, so I’ll just lead with the simplest option. If you give all the glyphs the same legend_label option, Bokeh will group them all (i.e. for muting and hiding) automatically in the legend:

p.segment(..., legend_label="Group A", muted_alpha=0.15)
p.scatter(..., legend_label="Group A", muted_alpha=0.15)
p.text(..., legend_label="Group A", muted_alpha=0.15)

p.legend.click_policy = "mute"

If this is not suitable, then please provide more context about your situation, i.e. actual code that is representative of your use case.