Modifying Chroma value of colors returns `Color is not defined` console error
See original GitHub issueHello,
I started running into an error once I started trying to manipulate the chroma values of an array of colors. Depending on the value I add to each chroma, some or all of the colors break the code and return a Color is not defined
error, Color referring to the export from Color.js.
I recorded a short screencast showing the situation: https://cln.sh/IDmWv3 and copied the code into a codepen. You can see the line I wrote a comment on saying if you uncomment that line, by applying a transformation to the chroma values, you can see that some of the colors disappear in the HTML.

I appreciate the help looking into this!
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
google chrome - Colors in JavaScript console - Stack Overflow
The default color is black and you don't have to pass any keyword as parameter in that case. In other cases, you should...
Read more >Why is an error thrown, color is not defined? - Treehouse
The color variable is defined for the scope of the example function. It does not exist outside of the function, so that's why...
Read more >chroma.js api docs!
#ff3399. You can construct colors from different color spaces by passing the name of color space as the last argument. Here we define...
Read more >CSS Color Module Level 4 - W3C
This module describes CSS properties which allow authors to specify the foreground color and opacity of the text content of an element. This ......
Read more >Customize
The colors are generated with the base R hcl() function, which has three ... all default colors generated by getColors() are based on...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@doistephen The issue is related to the gamut mapping. I believe there is something wrong with the js package you are importing. The reason why it breaks when you use chroma of
15
is simply that the package is corrupted in some way and your code exercises that path.In a color space like Lch, theoretically, you can keep raising the chroma, at some point the values you get are not practical as the human eyes have a limit of colors they can see. The sRGB color space, the color space to which you are printing your hex values, does have a limit though.
At some point, you increased your chroma such that it caused your sRGB color to slip out of gamut. This is the minimum reproducible case:
Now, this isn’t a big deal normally as Colorjs.io will gamut map the color back to a suitable color so that it can print the hex values you are requesting.
Normally this works fine, for instance, try entering that code into the Colorjs.io notebook: https://colorjs.io/notebook/. You’ll see it works fine. I tried the latest tip in node, and it works fine:
But whatever you are importing via Codepen, that instance seems corrupted because trying to print the out of bound color causes the undefined reference.
So, yes, there appears to be a bug in the package you are pulling in. I’m no JavaScript expert, so I’ll let those who are dig a little deeper.
Fix is linked