Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected conversion to HSL #83

Closed
denis-sokolov opened this issue Oct 10, 2020 · 0 comments · Fixed by #101
Closed

Unexpected conversion to HSL #83

denis-sokolov opened this issue Oct 10, 2020 · 0 comments · Fixed by #101
Labels
bug Something isn't working

Comments

@denis-sokolov
Copy link

denis-sokolov commented Oct 10, 2020

Convertion to HSL gives unexpected results. Consider:

import { hcl } from "d3-color";
const c = hcl(200, 100, 150);
console.log(c.formatHex());
console.log(c.formatRgb());
console.log(c.formatHsl());

Actual output in Chrome 86 on Mac:

#00ffff
rgb(0, 255, 255)
hsl(180.380573958081, -163.7644455443205%, -293.13231330226415%)

The hex and rgb notations are the same color: bright cyan. The HSL notation is different. The documentation also says the saturation and lightness values are clamped to the interval of 0-100, but they are not. Do I misunderstand how non-displayable colors are converted or is there a bug in the hsl converstion here?

Here’s another way to look at this:

const a = rgb(0, 255, 255);
const b = rgb(hcl(200, 100, 150));
a.formatRgb(); // rgb(0, 255, 255)
b.formatRgb(); // rgb(0, 255, 255)
a.formatHsl(); // hsl(180, 100%, 50%)
b.formatHsl(); // hsl(180.380573958081, -163.7644455443205%, -293.13231330226415%)
@denis-sokolov denis-sokolov changed the title HSL convertation suspect HSL convertation suspicion Oct 10, 2020
@denis-sokolov denis-sokolov changed the title HSL convertation suspicion HSL conversion suspicion Oct 10, 2020
@denis-sokolov denis-sokolov changed the title HSL conversion suspicion Unexpected conversion to HSL Oct 10, 2020
@mbostock mbostock added the bug Something isn't working label Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants