Skip to content

Implement legendrank attribute in traces #5591

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

Merged
merged 20 commits into from
Jun 16, 2021
Merged

Implement legendrank attribute in traces #5591

merged 20 commits into from
Jun 16, 2021

Conversation

archmoj
Copy link
Contributor

@archmoj archmoj commented Apr 16, 2021

Addressing #5501.

@plotly/plotly_js

@archmoj archmoj added this to the NEXT milestone Apr 16, 2021
var B = b[0].trace;
var delta = A.legendrank - B.legendrank;
if(!delta) delta = A.index - B.index;
if(!delta) delta = a[0]._initID - b[0]._initID;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming _initID is important for pie traces? Anything else? OK, so the code below implies (and I just tested to confirm) that legend.traceorder flips the order of pie entries in the legend, not just the order individual traces get added to the legend.

Based on that, I'd say the correct behavior of traceorder once we add legendrank is to simply flip the whole thing. That's not what I thought we concluded on the call yesterday but it's what you've implemented and with the pie complication I think it's the simplest thing to explain :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming _initID is important for pie traces? Anything else? OK, so the code below implies (and I just tested to confirm) that legend.traceorder flips the order of pie entries in the legend, not just the order individual traces get added to the legend.

I noticed some older version of Chrome (including our image test) sort the items differently.
So _initID was added in a60a382 to address that issue.

As you mentioned pie-like traces appear to behave differently.
In 598d60c
I was expecting that by using a higher value of legendrankon the first pie trace the slice legends come next.
However it is the opposite and it is rather confusing.

@alexcjohnson
Copy link
Collaborator

Looks good! Probably wants a mock (or just adding legendranks to some existing mock) and the description addition I commented on, then it'll be ready to go!

@archmoj archmoj removed this from the NEXT milestone Apr 22, 2021
@nicolaskruchten nicolaskruchten linked an issue May 1, 2021 that may be closed by this pull request
@archmoj
Copy link
Contributor Author

archmoj commented Jun 14, 2021

This PR was blocked by the old baseline system using old Chrome.
Once #5724 merged we could simply update legendrank baseline and it would be ready.

Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃 Great!

@archmoj
Copy link
Contributor Author

archmoj commented Jun 15, 2021

@nicolaskruchten please review and possibly give me a 🌟 to merge this feature.

@archmoj archmoj requested a review from nicolaskruchten June 15, 2021 21:17
@archmoj archmoj added this to the NEXT milestone Jun 15, 2021
editType: 'style',
description: [
'Sets the legend rank for this trace.',
'Items and groups with smaller ranks would be presented on top/left side while',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace "would be" with "are" please, throughout :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in a1f87b9

@nicolaskruchten
Copy link
Contributor

As far as I can tell, the specific case outlined in #5501 is not well-handled... B's legendrank of 1 should pull its entire group into the first position:

image

@nicolaskruchten
Copy link
Contributor

Here's the Pen: https://codepen.io/nicolaskruchten/pen/wvJROor

@archmoj
Copy link
Contributor Author

archmoj commented Jun 16, 2021

@nicolaskruchten good catch. It is now fixed by 32a890c and tested by a1abb19.

@nicolaskruchten
Copy link
Contributor

Behaviour looks good!

@archmoj archmoj merged commit 235e967 into master Jun 16, 2021
@archmoj archmoj deleted the legendrank branch June 16, 2021 16:47
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 this pull request may close these issues.

Legendrank attribute in traces
3 participants