question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modifying Chroma value of colors returns `Color is not defined` console error

See original GitHub issue

Hello,

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.

Screenshot 2022-03-01 at 14 00 41@2x

I appreciate the help looking into this!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
facelessusercommented, Mar 1, 2022

@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:

let c = new Color('srgb', [1.0730488766504873,0.9307621541691187,0.8700802895891485]);
c.toString()

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:

Welcome to Node.js v17.6.0.
Type ".help" for more information.
> const { default: Color } = require("./dist/color.cjs");
undefined
> let c = new Color('srgb', [1.0730488766504873,0.9307621541691187,0.8700802895891485]);
undefined
> c
Color$1 {
  _spaceId: 'srgb',
  toString: [Function: toString],
  coords: [ 1.0730488766504873, 0.9307621541691187, 0.8700802895891485 ],
  alpha: 1
}
> c.toString()
'rgb(100% 94.65% 91.59%)'

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.

0reactions
facelessusercommented, Mar 3, 2022

Fix is linked

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found