Skip to content

Legendrank attribute in traces #5501

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

Closed
nicolaskruchten opened this issue Feb 13, 2021 · 3 comments · Fixed by #5591
Closed

Legendrank attribute in traces #5501

nicolaskruchten opened this issue Feb 13, 2021 · 3 comments · Fixed by #5591
Labels
feature something new
Milestone

Comments

@nicolaskruchten
Copy link
Contributor

nicolaskruchten commented Feb 13, 2021

A new attribute in all traces called legendrank which defaults to the index of the trace in the data array. The legend items will then be sorted by legendrank (ties broken by index in the data array) before being laid out.

As an example for:

data = [
{name: "A", legendrank: 2}
{name: "D", legendrank: 4, legendgroup: "G2"}
{name: "E", legendrank: 4, legendgroup: "G2"}
{name: "B", legendrank: 1, legendgroup: "G1"}
{name: "C", legendrank: 3, legendgroup: "G1"}
]

then I would expect the legend order to be: G1(B,C), A, G2(D,E).

Note that the group order matters in the example above, when this will be coupled with #5260 and/or legendgroupgap.

@nicolaskruchten
Copy link
Contributor Author

Notes:

  • should be a number (floats and negatives OK)
  • default should be 1000
  • tie breaker is trace order as modulated by legend.traceorder i.e. 'reverse' reverses the tie-break

@archmoj archmoj added the feature something new label Apr 16, 2021
@nicolaskruchten nicolaskruchten linked a pull request May 1, 2021 that will close this issue
@archmoj archmoj added this to the NEXT milestone Jun 15, 2021
@ryan-williams
Copy link

For future searchers: I couldn't get legendrank to work; turns out I was inadvertently using plotly.js 1.x. This feature landed somewhere in the 2.x line.

@gonthalo
Copy link

gonthalo commented Jan 7, 2023

For future searchers: I couldn't get legendrank to work; turns out I was inadvertently using plotly.js 1.x. This feature landed somewhere in the 2.x line.

This worked for me, thanks!

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.

4 participants