-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Item toggle behavior when using multiple legends #6886
Comments
hi @NirRazor |
In my current setup, I have a graph that displays multiple time series, which are collectively represented under However the interactive behaviors like |
Thanks for the explanation @NirRazor . Do you mind speaking to the code you shared in the very first post. If you were able to accomplish what you're looking for, what would we see? What would happen if I clicked on legend 2 in your graph? |
Thank you for your response. To clarify, my goal is to have two legends with distinct interactive behaviors: Legend 1 (Time Series): Each item in this legend corresponds to a time series on the graph. The desired behavior here is standard – clicking on an item should toggle the visibility of its corresponding time series (individual trace toggling). Legend 2 (Historical Events): This legend relates to various shapes (like vertical lines) representing historical events. The key here is that I want to toggle groups of these shapes together. For example, if 'Legend2' contains categories A, B, and C, clicking on A should toggle the visibility of all shapes under category A, and similarly for B and C. In my example that I have provided I just try to explain the issue that is preventing me to do so. The issue is that all the legends are inheriting the behavior of the first legend. So, if I set itemclick: false in the first legend, the second legend also inherits this non-interactive behavior, which is not intended. Ideally, In my example above here's what should happen: If I click on a time series name in 'Legend 1', nothing should happen (as its toggle behavior is disabled) (Due to the unexpected behavior, both legends toggle behavior is disabled) I hope this better explains the specific functionality I'm trying to achieve. |
Thanks for the reminder @NirRazor . |
Thanks @NirRazor - confirmed, this is a bug, click behavior was never updated to support multiple legends. I'll move this to the plotly.js repo and comment on where the fix is needed. |
The problem is right here, click handler needs to refer to the specific legend being clicked, rather than plotly.js/src/components/legend/handle_click.js Lines 14 to 16 in 08e06bd
|
I’m facing an issue with Plotly where I’m trying to create a figure with two legends, each requiring different behavior. The first legend should have ‘toggle’ item behavior, allowing individual traces to be toggled on and off. The second legend should have ‘togglegroup’ item behavior, enabling the toggling of entire legend groups.
Problem:
The problem I’m encountering is that the second legend is inheriting the clicking behavior of the first legend, regardless of the configurations I’ve attempted (group / item).
Reproducible Example:
In the example above, I disabled the first legend itemclick behavior and set the second one to ‘toggle’ (regardless to the group). Unfortunately, both legends itemclick is disabled. 😦
Tested with latest Plotly version 5.18 (Plotly.js version is v2.27.0)
The text was updated successfully, but these errors were encountered: