MCPcopy Create free account
hub / github.com/breck7/scroll / hslConvert

Function hslConvert

external/.d3.js:3208–3232  ·  view source on GitHub ↗
(o)

Source from the content-addressed store, hash-verified

3206}
3207
3208function hslConvert(o) {
3209 if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
3210 if (!(o instanceof Color)) o = color(o);
3211 if (!o) return new Hsl;
3212 if (o instanceof Hsl) return o;
3213 o = o.rgb();
3214 var r = o.r / 255,
3215 g = o.g / 255,
3216 b = o.b / 255,
3217 min = Math.min(r, g, b),
3218 max = Math.max(r, g, b),
3219 h = NaN,
3220 s = max - min,
3221 l = (max + min) / 2;
3222 if (s) {
3223 if (r === max) h = (g - b) / s + (g < b) * 6;
3224 else if (g === max) h = (b - r) / s + 2;
3225 else h = (r - g) / s + 4;
3226 s /= l < 0.5 ? max + min : 2 - max - min;
3227 h *= 60;
3228 } else {
3229 s = l > 0 && l < 1 ? 0 : h;
3230 }
3231 return new Hsl(h, s, l, o.opacity);
3232}
3233
3234function hsl$2(h, s, l, opacity) {
3235 return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);

Callers 2

color_formatHslFunction · 0.85
hsl$2Function · 0.85

Calls 3

colorFunction · 0.85
minMethod · 0.80
maxMethod · 0.80

Tested by

no test coverage detected