gka / chroma.js

JavaScript library for all kinds of color manipulations
https://gka.github.io/chroma.js/
Other
10.13k stars 545 forks source link

BUG: scale.colors() does not respect the change in domain #329

Open ClaytonSmith opened 7 months ago

ClaytonSmith commented 7 months ago

chroma.scale('Spectral').domain([1,0]) vs chroma.scale('Spectral').domain([1,0]).colors(12) do not match.

That is to say chroma.scale('Spectral').domain([1,0]).colors(12) === chroma.scale('Spectral').colors(12)

regorxxx commented 7 months ago

Not really sure it's a bug, but more your expectation about it (not saying its not a logical expectation).

Colors returns n equidistant colors, and the output is right in both cases. If you change the domain to any other value, not an inversion, the output is "right". You are expecting that inverting the domain equals to inverting the scale, but that's not the current design. The scale is set according to the original color array passed, and .colors() just creates a new array using that reference. The domain has nothing to do with it. If you want to invert the scale, invert the colors output.

In fact, if you try any other scale modification (like .mode), .colors is not affected by it. Whatever method you apply to the scale does not change the scale, just its representation. They are different things. colors() is only related to the scale, not its representation.

ClaytonSmith commented 6 months ago

idk, using padding and gamma do change the colors returned so I'm not sure why domain is any different.