d3 / d3-color

Color spaces! RGB, HSL, Cubehelix, CIELAB, and more.
https://d3js.org/d3-color
ISC License
400 stars 91 forks source link

Incorrect conversion from HCL / LCH to hex or rgb #85

Closed neil-oliver closed 3 years ago

neil-oliver commented 3 years ago

Firstly, thank you @mbostock for all of your incredible work, every time i have no clue how i am going to achieve something, it seems that d3 has already created a solution.

One small issue i have spotted is that when creating a d3.hcl object (example used is d3.hcl(15,100,65)) and converting to either rgb or hex (using both .rgb or d3.rgb()), it provides the wrong values. Output from this conversion is #FF0077 and it should be #F8766D.

Tested with d3 5.9.2 & 6.2.0

Edit: The conversion seems to be the same as Chroma.js so maybe this isn't a d3 issue? The output varies massively to this http://hclwizard.org/hclcolorpicker/ which i think is using R to generate the colors / graphics

danburzo commented 3 years ago

Hi @neil-oliver, it's just a confusion of terms. In the Color space R package, HCL refers to the polar form of the CIELUV color space, while in D3 (and Chroma) HCL refers to the the polar form of the CIELAB color space. See also #64.

neil-oliver commented 3 years ago

Excellent, thanks for the clear explanation. I will wait for d3.luv to be implemented.