Skip to content

Trace legend error on Bar chart when updating color of first bar #1634

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
r1z1a opened this issue Apr 28, 2017 · 3 comments
Closed

Trace legend error on Bar chart when updating color of first bar #1634

r1z1a opened this issue Apr 28, 2017 · 3 comments

Comments

@r1z1a
Copy link

r1z1a commented Apr 28, 2017

I have hit an issue, I can recolor a single bar for multiple traces, the problem arises when you recolor the first bar, it seems to make whole legend that one color.
EDIT: Added Some code to show, the variable is passed in which corresponds to single x value, colors sets new array of color for each trace.

Feels like the legend is working of the color for first element in the trace, in my case in first element there is '0' value bars, but I made a test with 0 on second bar, and tested a bar that is not part of all traces, (where some trace value for bar is null) Show here
plotlybar1
plotlybar3
plotlybar2

     for (var j = 0; j < plotDiv.data.length; j++) {
        var colors = plotDiv.data[j].marker.color;
        for (var i = 0; i < plotDiv.data[j].x.length; i++) {
          if (plotDiv.data[j].x[i].indexOf(variable)===1) {
            colors[i]='red';
          }
        }
        Plotly.restyle(plotDiv, {'marker':{color: colors}}, [j]);
      }
@etpinard
Copy link
Contributor

I think this is a duplicate of #1560

Can you share a fully reproducible example, with data array and all to help us confirm? Thanks.

@r1z1a
Copy link
Author

r1z1a commented Apr 28, 2017

Here is simplified example that i just made for you, wrote it real quick, but i think the idea should be the same :)

@etpinard
EDIT: fixed the Codepen, now fully show the issue. try clicking bars 2,3,4 it changes bars and legend stays same. hit bar 1, and legend changes color as well as the bar.

Codepen

The issue here is not that it makes a legend per trace, that's exactly what I expect and need.

It feels like the colors of the legend traces are derived from the first bar per each trace, so when I restyle them, the legend gets re-styled too
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.

Although I can see an issue that if some one needs to re-style whole trace then it wouldn't update that trace legend color. This is possibly the problem since there seems to be a lot of issues to just change color of one element in a trace, you have to update whole trace, which can be rather hard process when you have like 10+ traces each with 100+ bars.

@alexcjohnson
Copy link
Collaborator

Yes, definitely duplicate of #1560 - lets continue this discussion over there.

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

3 participants