Skip to content

pie legends with conflicting colors #2858

Closed
@alexcjohnson

Description

@alexcjohnson
Collaborator

Pointed out by @nicolaskruchten

If you make several pie charts that share one or more labels but give them different colors, you get one legend entry per label, using the first color only:
https://codepen.io/alexcjohnson/pen/Zjvqee?editors=0010
screen shot 2018-07-30 at 4 09 30 pm
and clicking the legend entry for a label makes all copies - even the ones with a different color - disappear. This is confusing, but it's not 100% clear what the right fix is. The case I'm imagining is pies representing distinct data but expressed with the same labels. Like two survey questions, "How many scoops of ice cream do you want" and "How many cherries should there be on top", each with answers "0", "1", "2", "3 or more"

The two options that come to mind for how to resolve this:

  • Make one legend entry per label/color combination. This seems the most flexible, as you could for example show/hide each slice independently. But it could be confusing, especially since we don't have a way to split up the legend or to interleave subheadings, to have multiple entries with matching labels.
  • Show all of the colors next to each other in a single legend entry, kind of like we do for candlestick (though that's just 2 colors, this could be arbitrarily many). This would be more compact, could avoid the confusion ^^ (though could add more confusion if there are too many colors), and if the pies were related enough in meaning you might want to analyze them together - for example, yes/no/maybe questions, you want to hide all the maybes and just compare yes and no for all of them.

Activity

etpinard

etpinard commented on Jul 30, 2018

@etpinard
Contributor

What if we added a piegroup attribute?

  • Traces with different or unset piegroup would (like the 1st bullet pt) have one legend entry per label+color combination.
  • Traces with the same piegroup value would behave the second bullet pt by showing all colors (maybe cap that at 4) associated with traces of the same piegroup
alexcjohnson

alexcjohnson commented on Jul 30, 2018

@alexcjohnson
CollaboratorAuthor

What if we added a piegroup attribute?

We already have a scalegroup attribute so would this need to be colorgroup? Or perhaps we can reuse legendgroup for this purpose? Anyway seems like the two issues are distinct, so it's not simply a matter of renaming scalegroup, we need both to exist (though I suppose we could discuss whether their defaults should be linked)

etpinard

etpinard commented on Jul 30, 2018

@etpinard
Contributor

Oh right I forgot that scalegroup got implemented (proof -> here),.

so would this need to be colorgroup
we need both to exist (though I suppose we could discuss whether their defaults should be linked)

This sounds like a solid proposition 👌


But, just to think out loud ⤵️

Or perhaps we can reuse legendgroup for this purpose?

Interesting, perhaps legendgroup should lead to a single legend item per legendgroup value not just for pies, but for all trace types that support legend items? Perhaps this could be a new mode e.g. layout.legendgroupmode with values 'single item' or 'multi item'. But, would other trace other than pies really benefit from grouping their legend items together?

added a commit that references this issue on Oct 10, 2018
etpinard

etpinard commented on May 23, 2019

@etpinard
Contributor

Merging in #3885


See https://codepen.io/etpinard/pen/arVVpg

image

for pie traces, funnelarea traces behave similarly.

Potential solution:

  • split the legend item square into two halves (in general into N parts), one half with the pie color, the other with funnelarea color

More info: #3876 (comment)

gvwilson

gvwilson commented on Jun 11, 2024

@gvwilson
Contributor

Hi - this issue has been sitting for a while, so as part of our effort to tidy up our public repositories I'm going to close it. If it's still a concern, we'd be grateful if you could open a new issue (with a short reproducible example if appropriate) so that we can add it to our stack. Cheers - @gvwilson

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @gvwilson@alexcjohnson@etpinard

        Issue actions

          pie legends with conflicting colors · Issue #2858 · plotly/plotly.js