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

Incomplete legend for multiple colored bars in one trace #1560

Closed
hy9be opened this issue Apr 6, 2017 · 5 comments
Closed

Incomplete legend for multiple colored bars in one trace #1560

hy9be opened this issue Apr 6, 2017 · 5 comments

Comments

@hy9be
Copy link
Contributor

hy9be commented Apr 6, 2017

I noticed that Plotly.js construct legend item per trace rather than per color: https://github.com/plotly/plotly.js/blob/master/src/components/legend/get_legend_data.js#L43-L71. Thus if markers in a trace are colored differently, the legend could only show the color of the first item.

Here is an example:
image

I tried to make some changes to draw the legend items correctly. But the filtering functionality breaks. And I failed to find a way to fix the filter as the current implementation is based on the concept of "trace".

@etpinard
Copy link
Contributor

etpinard commented Apr 7, 2017

You're correct. The current behavior isn't great and is far from perfect in every situation. But, can I ask, what's the desired behavior in your mind? I don't think we should try plotting a rainbow-like legend item with the colors of all the trace's points. Maybe we could hash the legend item? Something else?

@alexcjohnson
Copy link
Collaborator

from @r1z1a in #1634 - there the use case was a trace that started all one color but during interactions one or another point (bars in that case too, though this applies to at least scatter as well) would change. @r1z1a 's suggestion:

An Ideal would be to store legend color when you first time plot it and pass data in, and after that the restyle shouldn't take effect if you are re-styling just single bars.

It's important that whatever solution we end up with depend only on the current state, not on its history, so while this suggestion is tempting as it produces the "right" result in that specific case, it's not viable in general.

One way we could solve this would be to explicitly specify legend styling. In principle this would need to be fairly involved, replicating all the marker, marker.line, and (for scatter) line attributes, but of course as a user you would only need to specify those attributes for which we get the default wrong.

@r1z1a
Copy link

r1z1a commented May 4, 2017

@alexcjohnson
Another suggestion would be to have some sort of Boolean when you are creating a trace to have something like "legendlock" - if set true this will prevent the legend from being altered.

From my perspective the legend color should stay the original color plotted and only if you re-style whole trace it should then be changed.

You say you want to depend on current state of the trace, so whats the current state of a trace with 100 scatter markers that are colored red and green for instance. Should a trace legend be an Array of colors used for the plot? Should it be the First color? Maybe the color that appears the most in the trace.

I personally think this is the whole restyle() issue. Its great when you want to change whole trace, but when it comes to single points in a trace, it can become very hard, and fair few issues are coming from that.

@marcinwojciechowski
Copy link

Another example (If I understand the problem here) is that I would like to compare 2 properties: temperature and pressure. Each property should be assigned to its own axis (because of the property unit - tempearature unit (Celsius) and pressure unit (Pascal)).
So the data is:
tempearature: source A values is 32, source B value is 35
pressure: source A value is 1014, source B value is 996

So how can I show barchart with legend groupped by sources (A and B)? Each source should have its own color and every property that comes from that source should have the color of its own source.

Like in this example: https://codepen.io/morris4life/pen/eepZNV?editors=0010
But the legend instead of showing every trace it should show just 2 items: "Source A" and "Source B"

@etpinard
Copy link
Contributor

etpinard commented Apr 5, 2019

Now in #3735

@etpinard etpinard closed this as completed Apr 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants