susielu / d3-legend

A reusable d3 legend component.
http://d3-legend.susielu.com/
Apache License 2.0
727 stars 104 forks source link

Bug in legendColor() updating? #69

Closed king612 closed 6 years ago

king612 commented 7 years ago

I believe there is a bug in legendColor when passing it updated scales. If I start with scale data like so (omitting quotes):

domain = [a, b, c] and range = [green, blue, gold]

The initial legend renders fine. But if I then call it again with:

domain = [b, c] and range = [blue, gold]

then the first two cells are both blue.

Likewise, updating by progressively dropping the last cell and adding it back with subsequent calls causes the last cell color to repeat.

I am using D3 v4. Looking at the source code, legendColor appears to be updating, exiting, and entering, but it is not updating correctly on the screen, and I can't see where the issue is. I noted though that it does not appear to be using a key function.

This is being done on a closed system, so unfortunately I cannot post the code.

susielu commented 7 years ago

Would you be able to make a scaled down example in codepen?

king612 commented 7 years ago

I just ended up doing it by hand. But thank for following up. I also switched to one of the built in color scales versus a manual one I was using.

I was doing all this in an angular 4 app so TypeScript. Maybe that was a factor?

Thanks, John

Sent from my iPhone

On Nov 12, 2017, at 3:39 PM, Susie notifications@github.com wrote:

Would you be able to make a scaled down example in codepen?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

susielu commented 7 years ago

I'll see if I can replicate it in an example, thanks!