Fork me on GitHub
#clojurescript
<
2023-09-08
>
simongray09:09:41

Does anyone have any experience dealing with colour scales? I have a theme of 5-6 colours that I prefer to use first, but I need to represent perhaps 20 more colours in certain cases in dynamically generated diagrams. Is there a way to generate these additional colours in such a way that they are evenly spaced out without resembling any of the preferred colours? I’m aware of both https://github.com/thi-ng/color and https://github.com/rm-hull/inkspot as potential libraries which may be of assistance.

p-himik09:09:38

If you have a maximum number of colors, I'd choose an appropriate color palette without any run-time scaling. E.g. D3 has "Category20" palette. You can probably find similar palettes that are large enough.

simongray09:09:01

I don’t have a theoretical maximum, though, that’s the issue.

simongray09:09:58

Thanks for the SE link, I’ll read it now 🙂

p-himik09:09:07

Ah. The problem with categories with no maximum is that at higher numbers the colors will invariably start to blend in. The problem becomes much worse if your product will be used by color-blind people. A solution that I used in one of the projects is to use a fixed palette of decent size suitable for color-blind people, and categories that wouldn't fit in there were represented with fill patterns. E.g. if the palette is of size 10 and the 1st color is red, then the 11th "color" would be red with black vertical stripes, 21st - horizontal, 31st - diagonal from top left to bottom right, 41st - from top right to bottom left, 51st - vertical and horizontal, and so on.

p-himik09:09:49

So the total size becomes 32 * color palette size, which was more than enough for my needs in that project.

simongray09:09:29

It’s for drawing thin lines, though :man-shrugging:

simongray09:09:43

I guess I’m gonna go with a fixed palette for now

simongray09:09:28

Not sure how I can deal with all cases of colour blindness without completely sacrificing legibility

simongray09:09:37

maybe dots and stripes will work, though!

simongray09:09:42

gonna try that for now!

simongray09:09:45

Thanks!

👍 2
simongray11:09:41

I think I'm gonna combine my 6 theme colours with a really long list of colours and filter away colours resembling the original theme using the colour distance function in thing/color.

simongray11:09:16

So technically a fixed size, but in practice it won't be an issue.

valtteri13:09:40

There are some goodies in goog.color https://google.github.io/closure-library/api/goog.color.html I’ve had success generating palettes with those functions + some simple heuristics

valtteri13:09:23

(I’m not an expert on this field though, but got the job done)

simongray13:09:58

Oh nice, another one!

simongray13:09:21

I got my implementation working using http://thi.ng/color in the meantime

👍 2
valtteri13:09:38

http://thi.ng/color looks quite nice and complete. 🙂 goog.color makes sense if you wish to avoid an extra dep

🙏 2
simongray13:09:25

oh yeah, I see that there is a distance function too now!

p-himik14:09:06

Also, just in case - there's this thing: https://www.npmjs.com/package/color-hash Doesn't guarantee absence of clashing or close colors but can provide stable colors for the same categories regardless of their order.