d3 / d3-color

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

clamp HSL format #101

Closed mbostock closed 2 years ago

mbostock commented 2 years ago

Fixes #83.

Note that you don’t get an equivalent color with formatHsl and formatRgb, though, because they clamp in the HSL and RGB colorspaces, respectively. If you want to clamp in RGB colorspace and format in HSL, you have to first format as RGB, then re-parse, then format as HSL:

d3.color(color.formatRgb()).formatHsl()

It’d probably be nice if we had an explicit color.clamp option for RGB and HSL so that you could avoid reparsing. Then you could say:

color.rgb().clamp().formatHsl()
Fil commented 2 years ago

Is it only rgb and hsl colors that can be clamped? In that case, should we have a default method for the other color types, for API consistence (i.e. an alias of color.copy)?