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

Single-toggle of grouped traces in legend #3135

Closed
mojoaxel opened this issue Oct 22, 2018 · 13 comments
Closed

Single-toggle of grouped traces in legend #3135

mojoaxel opened this issue Oct 22, 2018 · 13 comments
Labels
feature something new
Milestone

Comments

@mojoaxel
Copy link
Contributor

This is a feature request.

Please see default "Grouped Legend" example: https://codepen.io/plotly/pen/qjmNXa

Current behavior

It is possible to toggle single traces by clicking on them in the legend. If traces are grouped using legendgroup (like in the example above) not the single traces but the whole group is toggled.

Future behavior

It should be possible to disable the toggling of the whole group and instead toggle the single traces like in no-grouped legends. This would make it possible in the example above to only disable the "points" and only show the "avarage line" of this group.

This should be done by a new option in the legend-settings.

Related: #65, #665, #674

@antoinerg antoinerg added the feature something new label Oct 22, 2018
@etpinard
Copy link
Contributor

Can I ask why are you using legend groups if you don't want group toggling? I suspect you like the legend group aesthetics, but I'd like to confirm.

Thank you!

@mojoaxel
Copy link
Contributor Author

@etpinard I have a quiet complex use case, with multiple sub-charts. Each sub-chart has its own legend-group. I'm using sub-charts because I need a common spike-line and synchronized zooming/panning.
Here is a prototype: https://jsbin.com/davagaz/22/edit?js,output

It is amazing, what is possible with plotly.js already, but I could write small bug-reports and feature requests daily if I had the time... That's the price of using every cutting-edge feature that exists, I guess 😏

@etpinard
Copy link
Contributor

Thanks!

but I could write small bug-reports and feature requests daily if I had the time..

Please don't hesitate, if you have the time of course 😉

@datid
Copy link

datid commented Jan 16, 2019

This seems like a good idea for what I am doing too, but it is possible there is another way to approach my use case that I haven't seen.
So I am using subplots in order to have common x or y axis, what I would then like is for the legend to be aligned with the subplot rather than the whole group. I can split the legend up by using legend groups, but it is tricky to perfectly align them ( I can get close with judicious use of tracegroupgap ), butthen I run into the problems mojoaxel had.
Maybe there is a way of having common axis between plots rather than subplots, or some other option I haven't noticed.

@Codermar
Copy link

I have the same issue. To me, the group legend should honor the individual toggling or make it a configurable thing. Without grouping the legend it is difficult to visually make sense of some use cases of combination such as this https://codepen.io/Codermar/pen/NWWrqRB?editors=0010

Is there any workaround alternative at this time otherwise?

Thanks.

@OlderSchool
Copy link

I have the same issue too, as I suspect anyone serious about plotting data is having.
Need subplots to have common zooming, panning, etc
Therefore need legendgroup to separate legends on subplots.
Need individual toggling to identify "stuff"

The current state of play does not permit all three.
Probably easiest fix is to permit separate legends per subplot.
All should fall into place from there.

@JeroneGagliano
Copy link

Agree with @mojoaxel, the user needs to be able to toggle on/off an individual trace in a subplot. Maybe the solution will come from first having separate legends per sublot, @OlderSchool suggests. BTW, the separate legends per subplot is an issue that can be tracked here:
[plotly/plotly.js] Support for multiple legends (#1668)

@mcstarioni
Copy link

mcstarioni commented May 6, 2020

I would suggest a following behaviour: legend group would become an independent toggle with a name of a legendgroup, which would activate/deactivate all contained traces. Yet if someone needs to toggle some particular trace, he can add showlegend=True, and displayed legend for this trace would toggle only this trace.

@rithwikjc
Copy link

rithwikjc commented Jun 9, 2021

I would summarize the suggestions as follows.

  • It would help to have a legend group title for each legend group. Clicking on it can act as toggle for all scatters of that legend group. This also takes care of Ability to Provide Title to Legend/ Legend Groups #689.
  • Each individual scatter is grouped under it's respective legend group title, and the toggle for each scatter works as it usually does for the individual scatters.
  • Legend groups can be toggled by something like legend_legendgrouptitles in layout (this is global, meaning all legend group names are displayed or hidden for the particular plot), and each scatter is handled already as done by showlegend parameter of the scatter.

This solution should take care of most use cases and issues relating to legend group title and (scatter/group) toggles, except for the very particular use cases like selectively displaying legend group titles for certain legend groups.

The legend would look like this after such a change:
NewLegend

@nicolaskruchten
Copy link
Contributor

I certainly understand the desires here but I'll just add a couple of other points of view:

  1. if folks want per-subplot legends, there is another issue explicitly tracking that: Multiple legends: trace.legend and layout.legend<N> #5098
  2. if folks want titles for legend groups, there is another issue explicitly tracking that, which we are working on right now: Ability to Provide Title to Legend/ Legend Groups #689 (duplicated in legendgroup titles #5260 apparently)

This leaves the actual legend-item click behaviour :) Right now we're not working on any changes, but we would certainly accept a pull-request to control whether or not clicking on an item in a group toggles only that item or the whole group. This could be a global attribute under layout.legend for example.

The idea of having the legend group title be clickable is not something I'd thought of but is a good one, and would be a good candidate for implementation, and for having a non-changeable behaviour of "clicking on it toggles the whole group".

@nicolaskruchten
Copy link
Contributor

We implemented legend group titles in #5752 (to be released in v2.2). Clickable legend group titles are now tracked separately here: #5765

@nicolaskruchten nicolaskruchten added this to the NEXT milestone Jun 29, 2021
@archmoj archmoj added bug something broken feature something new and removed feature something new bug something broken labels Jul 17, 2021
@archmoj archmoj removed this from the NEXT milestone Jul 19, 2021
@brussee
Copy link
Contributor

brussee commented Jul 20, 2021

Our use case could utilize the legendgroup to group traces for organizational purposes, not for the feature to enable the whole group at once, but rather to show a title above the group for a human-readable logical grouping. The feature to toggle individual traces like normal, as in: not in a legendgroup, would be highly appreciated. Right now we add a dummy trace (with some extra spacing in the name) to show a title above this logical group, since we have to be able to toggle individual traces like normal.
Thanks a lot for your great effort in this useful lib!

@nicolaskruchten
Copy link
Contributor

Yes, the use-case here is pretty clear, but I'm not sure when someone from our team will be able to take this on. We'd love a pull request that implements this in a backwards-compatible way i.e. with a new attribute in layout.legend to control this thad defaults to the current behaviour :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new
Projects
None yet
Development

Successfully merging a pull request may close this issue.