chroma icon indicating copy to clipboard operation
chroma copied to clipboard

Generated palette sort order

Open eliduke opened this issue 6 years ago • 2 comments

I just came across this gem in an attempt to autogenerate some colors for chart.js. It's very cool and working quite well so far. Thank you for all the hard work!

The only problem I'm having is the sort order for a generated palette, specifically the first / last color in the array. It's possible that I'm missing some config option or something, but, lemme break it down for you

I'm using this code to create my monochromatic palette:

"#ff6384".paint.palette.monochromatic(size: 16, as: :hex)

Which is generating this array (I've truncated it for brevity):

["#ff6384", "#100608", "#200c11", "#301319", "#401921", "#501f29", "#602532" ... ]

Which produces this color palette in my chart:

screen shot 2018-01-25 at 1 23 41 pm

As you can see, it looks like the first color needs to go to the end or the rest of the array (except for the first one) needs to be reversed.

I even checked your examples in the README, and I'm seeing the same problem:

'red'.paint.palette.monochromatic(as: :hex)
#=> ['#ff0000', '#2a0000', '#550000', '#800000', '#aa0000', '#d40000']

That goes from red to (basically) black and then works its way back toward red.

Is there a way to specify "direction" in a palette? Like, to be able to pass in an argument to the palette to start with my seed color or end with my seed color.

Thoughts on this? Am I missing something?

eliduke avatar Jan 25 '18 21:01 eliduke

And here's that same chart with an analogous palette:

screen shot 2018-01-25 at 2 07 20 pm

That first red color still seems out of place.

eliduke avatar Jan 25 '18 22:01 eliduke

Hey @jfairbank!

So, I decided for the time being to fork the repo and just cowboy the changes that I want. You can see the specific changes that I made in my fork with this commit:

https://github.com/eliduke/chroma/commit/f7aa6eab5a70e8b46dfe51cd9befef2d1def57f9

I'm not totally sure if that's PR worthy (which would certainly require some specs), but, now I'm getting this array of colors for my chart:

screen shot 2018-01-26 at 2 15 11 pm

eliduke avatar Jan 26 '18 23:01 eliduke