You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I have a plot with lots of traces (a few hundred) defined in non-server Bokeh, but only a few traces displayed at any given time based on some CDSView settings the user may select. I'd like to have a legend for the plot, but due to the number of underlying traces the legend becomes unusably large because legend entries for all of the filtered-out traces are still visible.
Describe the solution you'd like
I can think of two possible solutions:
The first would be to simply add a .visible property to LegendItems that could be toggled via CustomJS to disable rendering. The second would be to have some mechanic whereby legend items may auto-hide if no points from the given GlyphRenderer are visible (either due to hiding, filtering, or simply not being in the visible plot area).
Describe alternatives you've considered
I tried creating pre-computing each possible legend configuration and adding/removing legend items (or even whole legends) via CustomJS, but this gave me a lot of cryptic error messages and based on this other conversation, CustomJS that could modify the calculation graph is frowned upon: https://discourse.bokeh.org/t/updating-legend-when-using-bokeh-js/3947/3
cc @mattpap adding .visible to LegendItem and having non-visible items not participate in render/layout seems like it should not be too difficult, am I correct in that assumptions?
Automatically hiding legend items based on other criteria seems like an orthogonal concern, which would need to expose different policies regardless.
One thing people have asked for is to automatically hide legend items if associated glyphs are not visible. This seems reasonable mostly, but there are some UX interactions to consider. Specifically if "interactive legend" hiding is turned on and a user clicked a legend item, then the glyph is made invisible. If that in turn hides the legend item then there would be no way to reverse the operation to make things visible again.
Activity
bryevdv commentedon Oct 11, 2019
cc @mattpap adding
.visibletoLegendItemand having non-visible items not participate in render/layout seems like it should not be too difficult, am I correct in that assumptions?Automatically hiding legend items based on other criteria seems like an orthogonal concern, which would need to expose different policies regardless.
mattpap commentedon Oct 11, 2019
This would be trivial to implement if legend was a layout, but it shouldn't be too difficult to add this to the existing implementation.
bryevdv commentedon Mar 9, 2021
One thing people have asked for is to automatically hide legend items if associated glyphs are not visible. This seems reasonable mostly, but there are some UX interactions to consider. Specifically if "interactive legend" hiding is turned on and a user clicked a legend item, then the glyph is made invisible. If that in turn hides the legend item then there would be no way to reverse the operation to make things visible again.
ardimaunahan commentedon Apr 22, 2021
I recently posted a question that is related to this: https://stackoverflow.com/questions/67166599/bokeh-force-onclick-event-to-a-legend-via-js-callback. Please check if that is the case or should I file a separate enhancement.
Having a
toggle()method would be great.github-actions commentedon Oct 26, 2024
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.