Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE]Make LegendItems Hideable #9261

Closed
DataFramed opened this issue Oct 3, 2019 · 4 comments · Fixed by #11412 or #11421
Closed

[FEATURE]Make LegendItems Hideable #9261

DataFramed opened this issue Oct 3, 2019 · 4 comments · Fixed by #11412 or #11421

Comments

@DataFramed
Copy link

DataFramed commented Oct 3, 2019

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

Thanks!

@bryevdv
Copy link
Member

bryevdv commented Oct 11, 2019

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.

@mattpap
Copy link
Contributor

mattpap commented 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
Copy link
Member

bryevdv commented 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
Copy link

ardimaunahan commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment