Socket
Socket
Sign inDemoInstall

d3-color

Package Overview
Dependencies
0
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.1 to 0.2.2

src/interpolateCubehelixGamma.js

458

build/color.js
if (typeof Map === "undefined") {
Map = function() {};
Map = function() { this.clear(); };
Map.prototype = {
set: function(k, v) { this["$" + k] = v; return this; },
get: function(k) { return this["$" + k]; },
has: function(k) { return "$" + k in this; }
set: function(k, v) { this._[k] = v; return this; },
get: function(k) { return this._[k]; },
has: function(k) { return k in this._; },
delete: function(k) { return k in this._ && delete this._[k]; },
clear: function() { this._ = Object.create(null); },
get size() { var n = 0; for (var k in this._) ++n; return n; },
forEach: function(c) { for (var k in this._) c(this._[k], k, this); }
};
}
} else (function() {
var m = new Map;
if (m.set(0, 0) !== m) {
m = m.set;
Map.prototype.set = function() { m.apply(this, arguments); return this; };
}
})();

@@ -16,5 +26,21 @@ (function (global, factory) {

function deltaHue(h1, h0) {
var delta = h1 - h0;
return delta > 180 || delta < -180
? delta - 360 * Math.round(delta / 360)
: delta;
}
function Cubehelix(h, s, l) {
this.h = +h;
this.s = +s;
this.l = +l;
}
function Color() {}
Color.prototype = {
displayable: function() {
return this.rgb().displayable();
},
toString: function() {

@@ -25,2 +51,93 @@ return this.rgb() + "";

var _prototype = Cubehelix.prototype = new Color;
var darker = .7;
function Rgb(r, g, b) {
this.r = Math.round(r);
this.g = Math.round(g);
this.b = Math.round(b);
}
var __prototype = Rgb.prototype = new Color;
__prototype.brighter = function(k) {
k = k == null ? brighter : Math.pow(brighter, k);
return new Rgb(this.r * k, this.g * k, this.b * k);
};
__prototype.rgb = function() {
return this;
};
__prototype.displayable = function() {
return (0 <= this.r && this.r <= 255)
&& (0 <= this.g && this.g <= 255)
&& (0 <= this.b && this.b <= 255);
};
function format(r, g, b) {
if (isNaN(r)) r = 0;
if (isNaN(g)) g = 0;
if (isNaN(b)) b = 0;
return "#"
+ (r < 16 ? "0" + Math.max(0, r).toString(16) : Math.min(255, r).toString(16))
+ (g < 16 ? "0" + Math.max(0, g).toString(16) : Math.min(255, g).toString(16))
+ (b < 16 ? "0" + Math.max(0, b).toString(16) : Math.min(255, b).toString(16));
}
__prototype.toString = function() {
return format(this.r, this.g, this.b);
};
__prototype.darker = function(k) {
k = k == null ? darker : Math.pow(darker, k);
return new Rgb(this.r * k, this.g * k, this.b * k);
};
var brighter = 1 / darker;
_prototype.brighter = function(k) {
k = k == null ? brighter : Math.pow(brighter, k);
return new Cubehelix(this.h, this.s, this.l * k);
};
_prototype.darker = function(k) {
k = k == null ? darker : Math.pow(darker, k);
return new Cubehelix(this.h, this.s, this.l * k);
};
var E = +1.97294;
var D = -0.90649;
var C = -0.29227;
var B = +1.78277;
var A = -0.14861;
var deg2rad = Math.PI / 180;
_prototype.rgb = function() {
var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
l = +this.l,
a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
cosh = Math.cos(h),
sinh = Math.sin(h);
return new Rgb(
255 * (l + a * (A * cosh + B * sinh)),
255 * (l + a * (C * cosh + D * sinh)),
255 * (l + a * (E * cosh))
);
};
var rad2deg = 180 / Math.PI;
var EB = E * B;
var ED = E * D;
var BC_DA = B * C - D * A;
var named = (new Map)

@@ -176,57 +293,2 @@ .set("aliceblue", 0xf0f8ff)

function Rgb(r, g, b) {
this.r = Math.max(0, Math.min(255, Math.round(r)));
this.g = Math.max(0, Math.min(255, Math.round(g)));
this.b = Math.max(0, Math.min(255, Math.round(b)));
}
var _prototype = Rgb.prototype = new Color;
var darker = .7;
_prototype.darker = function(k) {
k = k == null ? darker : Math.pow(darker, k);
return new Rgb(this.r * k, this.g * k, this.b * k);
};
var brighter = 1 / darker;
_prototype.brighter = function(k) {
k = k == null ? brighter : Math.pow(brighter, k);
return new Rgb(this.r * k, this.g * k, this.b * k);
};
_prototype.rgb = function() {
return this;
};
function format(r, g, b) {
if (isNaN(r)) r = 0;
if (isNaN(g)) g = 0;
if (isNaN(b)) b = 0;
return "#"
+ (r < 16 ? "0" + r.toString(16) : r.toString(16))
+ (g < 16 ? "0" + g.toString(16) : g.toString(16))
+ (b < 16 ? "0" + b.toString(16) : b.toString(16));
}
_prototype.toString = function() {
return format(this.r, this.g, this.b);
};
var rgb = function(r, g, b) {
if (arguments.length === 1) {
if (!(r instanceof Color)) r = color(r);
if (r) {
r = r.rgb();
b = r.b;
g = r.g;
r = r.r;
} else {
r = g = b = NaN;
}
}
return new Rgb(r, g, b);
}
function rgbn(n) {

@@ -238,9 +300,9 @@ return rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff);

this.h = +h;
this.s = Math.max(0, Math.min(1, +s));
this.l = Math.max(0, Math.min(1, +l));
this.s = +s;
this.l = +l;
}
var __prototype = Hsl.prototype = new Color;
var ___prototype = Hsl.prototype = new Color;
__prototype.brighter = function(k) {
___prototype.brighter = function(k) {
k = k == null ? brighter : Math.pow(brighter, k);

@@ -250,7 +312,9 @@ return new Hsl(this.h, this.s, this.l * k);

__prototype.darker = function(k) {
___prototype.darker = function(k) {
k = k == null ? darker : Math.pow(darker, k);
return new Hsl(this.h, this.s, this.l * k);
};/* From FvD 13.37, CSS Color Module Level 3 */
};
/* From FvD 13.37, CSS Color Module Level 3 */
function hsl2rgb(h, m1, m2) {

@@ -263,7 +327,7 @@ return (h < 60 ? m1 + (m2 - m1) * h / 60

__prototype.rgb = function() {
___prototype.rgb = function() {
var h = this.h % 360 + (this.h < 0) * 360,
s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
l = this.l,
m2 = l <= .5 ? l * (1 + s) : l + s - l * s,
m2 = l + (l < .5 ? l : 1 - l) * s,
m1 = 2 * l - m2;

@@ -277,3 +341,8 @@ return new Rgb(

var hsl = function(h, s, l) {
___prototype.displayable = function() {
return (0 <= this.s && this.s <= 1 || isNaN(this.s))
&& (0 <= this.l && this.l <= 1);
};
function hsl(h, s, l) {
if (arguments.length === 1) {

@@ -314,9 +383,13 @@ if (h instanceof Hsl) {

var reHex3 = /^#([0-9a-f]{3})$/,
reHex6 = /^#([0-9a-f]{6})$/,
reRgbInteger = /^rgb\(\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*\)$/,
reRgbPercent = /^rgb\(\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/,
reHslPercent = /^hsl\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/;
var reHslPercent = /^hsl\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/;
var color = function(format) {
var reRgbPercent = /^rgb\(\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/;
var reRgbInteger = /^rgb\(\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*\)$/;
var reHex6 = /^#([0-9a-f]{6})$/;
var reHex3 = /^#([0-9a-f]{3})$/;
function color(format) {
var m;

@@ -331,4 +404,81 @@ format = (format + "").trim().toLowerCase();

: null;
}// Done lazily to avoid circular dependency between Color, Rgb and Hsl.
}
function rgb(r, g, b) {
if (arguments.length === 1) {
if (!(r instanceof Color)) r = color(r);
if (r) {
r = r.rgb();
b = r.b;
g = r.g;
r = r.r;
} else {
r = g = b = NaN;
}
}
return new Rgb(r, g, b);
}
function cubehelix(h, s, l) {
if (arguments.length === 1) {
if (h instanceof Cubehelix) {
l = h.l;
s = h.s;
h = h.h;
} else {
if (!(h instanceof Rgb)) h = rgb(h);
var r = h.r / 255, g = h.g / 255, b = h.b / 255;
l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB);
var bl = b - l, k = (E * (g - l) - C * bl) / D;
s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)); // NaN if l=0 or l=1
h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
if (h < 0) h += 360;
}
}
return new Cubehelix(h, s, l);
}
function interpolateCubehelixGamma(gamma) {
return function(a, b) {
a = cubehelix(a);
b = cubehelix(b);
var ah = isNaN(a.h) ? b.h : a.h,
as = isNaN(a.s) ? b.s : a.s,
al = a.l,
bh = isNaN(b.h) ? 0 : deltaHue(b.h, ah),
bs = isNaN(b.s) ? 0 : b.s - as,
bl = b.l - al;
return function(t) {
a.h = ah + bh * t;
a.s = as + bs * t;
a.l = al + bl * Math.pow(t, gamma);
return a + "";
};
};
}
exports.interpolateCubehelix = interpolateCubehelixGamma(1);
function interpolateCubehelixGammaLong(gamma) {
return function(a, b) {
a = cubehelix(a);
b = cubehelix(b);
var ah = isNaN(a.h) ? b.h : a.h,
as = isNaN(a.s) ? b.s : a.s,
al = a.l,
bh = isNaN(b.h) ? 0 : b.h - ah,
bs = isNaN(b.s) ? 0 : b.s - as,
bl = b.l - al;
return function(t) {
a.h = ah + bh * t;
a.s = as + bs * t;
a.l = al + bl * Math.pow(t, gamma);
return a + "";
};
};
}
exports.interpolateCubehelixLong = interpolateCubehelixGammaLong(1);
// Done lazily to avoid circular dependency between Color, Rgb and Hsl.
color.prototype = Color.prototype;

@@ -344,11 +494,11 @@ rgb.prototype = Rgb.prototype;

var ___prototype = Lab.prototype = new Color;
var ____prototype = Lab.prototype = new Color;
var Kn = 18;
___prototype.brighter = function(k) {
____prototype.brighter = function(k) {
return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b);
};
___prototype.darker = function(k) {
____prototype.darker = function(k) {
return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b);

@@ -361,9 +511,5 @@ };

var Xn = 0.950470, // D65 standard referent
Yn = 1,
Zn = 1.088830,
t0 = 4 / 29,
t1 = 6 / 29,
t2 = 3 * t1 * t1,
t3 = t1 * t1 * t1;
var t0 = 4 / 29;
var t1 = 6 / 29;
var t2 = 3 * t1 * t1;

@@ -374,3 +520,8 @@ function lab2xyz(t) {

___prototype.rgb = function() {
var Zn = 1.088830;
var Xn = 0.950470;
var Yn = 1;
____prototype.rgb = function() {
var y = (this.l + 16) / 116,

@@ -389,2 +540,4 @@ x = isNaN(this.a) ? y : y + this.a / 500,

var t3 = t1 * t1 * t1;
function xyz2lab(t) {

@@ -398,4 +551,2 @@ return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;

var deg2rad = Math.PI / 180;
function Hcl(h, c, l) {

@@ -407,17 +558,17 @@ this.h = +h;

var ____prototype = Hcl.prototype = new Color;
var prototype = Hcl.prototype = new Color;
____prototype.brighter = function(k) {
prototype.brighter = function(k) {
return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k));
};
____prototype.darker = function(k) {
prototype.darker = function(k) {
return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k));
};
____prototype.rgb = function() {
prototype.rgb = function() {
return lab(this).rgb();
};
var lab = function(l, a, b) {
function lab(l, a, b) {
if (arguments.length === 1) {

@@ -448,6 +599,6 @@ if (l instanceof Lab) {

}
lab.prototype = Lab.prototype;
var rad2deg = 180 / Math.PI;
var hcl = function(h, c, l) {
function hcl(h, c, l) {
if (arguments.length === 1) {

@@ -468,104 +619,7 @@ if (h instanceof Hcl) {

}
hcl.prototype = Hcl.prototype;
function Cubehelix(h, s, l) {
this.h = +h;
this.s = +s;
this.l = +l;
}
var prototype = Cubehelix.prototype = new Color;
prototype.brighter = function(k) {
k = k == null ? brighter : Math.pow(brighter, k);
return new Cubehelix(this.h, this.s, this.l * k);
};
prototype.darker = function(k) {
k = k == null ? darker : Math.pow(darker, k);
return new Cubehelix(this.h, this.s, this.l * k);
};
var gamma = 1, // Default gamma. TODO Customize.
A = -0.14861,
B = +1.78277,
C = -0.29227,
D = -0.90649,
E = +1.97294,
ED = E * D,
EB = E * B,
BC_DA = B * C - D * A;
var cubehelix = function(h, s, l) {
if (arguments.length === 1) {
if (h instanceof Cubehelix) {
l = h.l;
s = h.s;
h = h.h;
} else {
if (!(h instanceof Rgb)) h = rgb(h);
var r = h.r / 255, g = h.g / 255, b = h.b / 255;
l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB);
var bl = b - l, k = (E * (g - l) - C * bl) / D, lgamma = Math.pow(l, gamma);
s = Math.sqrt(k * k + bl * bl) / (E * lgamma * (1 - lgamma)); // NaN if lgamma=0 or lgamma=1
h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
if (h < 0) h += 360;
}
}
return new Cubehelix(h, s, l);
}
prototype.rgb = function() {
var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
l = Math.pow(this.l, gamma),
a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
cosh = Math.cos(h),
sinh = Math.sin(h);
return new Rgb(
255 * (l + a * (A * cosh + B * sinh)),
255 * (l + a * (C * cosh + D * sinh)),
255 * (l + a * (E * cosh))
);
};
cubehelix.prototype = Cubehelix.prototype;
var interpolateCubehelixLong = function(a, b) {
a = cubehelix(a);
b = cubehelix(b);
var ah = isNaN(a.h) ? b.h : a.h,
as = isNaN(a.s) ? b.s : a.s,
al = a.l,
bh = isNaN(b.h) ? 0 : b.h - ah,
bs = isNaN(b.s) ? 0 : b.s - as,
bl = b.l - al;
return function(t) {
a.h = ah + bh * t;
a.s = as + bs * t;
a.l = al + bl * t;
return a + "";
};
}
var deltaHue = function(h, h0) {
var delta = (h - h0) % 360;
return delta + (delta > 180 ? -360 : delta < -180 ? 360 : 0);
}
var interpolateCubehelix = function(a, b) {
a = cubehelix(a);
b = cubehelix(b);
var ah = isNaN(a.h) ? b.h : a.h,
as = isNaN(a.s) ? b.s : a.s,
al = a.l,
bh = isNaN(b.h) ? 0 : deltaHue(b.h, ah),
bs = isNaN(b.s) ? 0 : b.s - as,
bl = b.l - al;
return function(t) {
a.h = ah + bh * t;
a.s = as + bs * t;
a.l = al + bl * t;
return a + "";
};
}
var interpolateHclLong = function(a, b) {
function interpolateHclLong(a, b) {
a = hcl(a);

@@ -587,3 +641,3 @@ b = hcl(b);

var interpolateHcl = function(a, b) {
function interpolateHcl(a, b) {
a = hcl(a);

@@ -605,3 +659,3 @@ b = hcl(b);

var interpolateLab = function(a, b) {
function interpolateLab(a, b) {
a = lab(a);

@@ -623,3 +677,3 @@ b = lab(b);

var interpolateHslLong = function(a, b) {
function interpolateHslLong(a, b) {
a = hsl(a);

@@ -641,3 +695,3 @@ b = hsl(b);

var interpolateHsl = function(a, b) {
function interpolateHsl(a, b) {
a = hsl(a);

@@ -659,3 +713,3 @@ b = hsl(b);

var interpolateRgb = function(a, b) {
function interpolateRgb(a, b) {
a = rgb(a);

@@ -686,5 +740,5 @@ b = rgb(b);

exports.interpolateHclLong = interpolateHclLong;
exports.interpolateCubehelix = interpolateCubehelix;
exports.interpolateCubehelixLong = interpolateCubehelixLong;
exports.interpolateCubehelixGamma = interpolateCubehelixGamma;
exports.interpolateCubehelixGammaLong = interpolateCubehelixGammaLong;
}));

@@ -1,1 +0,1 @@

"undefined"==typeof Map&&(Map=function(){},Map.prototype={set:function(t,e){return this["$"+t]=e,this},get:function(t){return this["$"+t]},has:function(t){return"$"+t in this}}),function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.color={})}(this,function(t){"use strict";function e(){}function s(t,e,s){this.r=Math.max(0,Math.min(255,Math.round(t))),this.g=Math.max(0,Math.min(255,Math.round(e))),this.b=Math.max(0,Math.min(255,Math.round(s)))}function n(t,e,s){return isNaN(t)&&(t=0),isNaN(e)&&(e=0),isNaN(s)&&(s=0),"#"+(16>t?"0"+t.toString(16):t.toString(16))+(16>e?"0"+e.toString(16):e.toString(16))+(16>s?"0"+s.toString(16):s.toString(16))}function r(t){return m(t>>16&255,t>>8&255,255&t)}function i(t,e,s){this.h=+t,this.s=Math.max(0,Math.min(1,+e)),this.l=Math.max(0,Math.min(1,+s))}function a(t,e,s){return 255*(60>t?e+(s-e)*t/60:180>t?s:240>t?e+(s-e)*(240-t)/60:e)}function o(t,e,s){this.l=+t,this.a=+e,this.b=+s}function h(t){return 255*(.0031308>=t?12.92*t:1.055*Math.pow(t,1/2.4)-.055)}function l(t){return t>P?t*t*t:z*(t-j)}function u(t){return t>R?Math.pow(t,1/3):t/z+j}function c(t){return(t/=255)<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function g(t,e,s){this.h=+t,this.c=+e,this.l=+s}function d(t,e,s){this.h=+t,this.s=+e,this.l=+s}e.prototype={toString:function(){return this.rgb()+""}};var f=(new Map).set("aliceblue",15792383).set("antiquewhite",16444375).set("aqua",65535).set("aquamarine",8388564).set("azure",15794175).set("beige",16119260).set("bisque",16770244).set("black",0).set("blanchedalmond",16772045).set("blue",255).set("blueviolet",9055202).set("brown",10824234).set("burlywood",14596231).set("cadetblue",6266528).set("chartreuse",8388352).set("chocolate",13789470).set("coral",16744272).set("cornflowerblue",6591981).set("cornsilk",16775388).set("crimson",14423100).set("cyan",65535).set("darkblue",139).set("darkcyan",35723).set("darkgoldenrod",12092939).set("darkgray",11119017).set("darkgreen",25600).set("darkgrey",11119017).set("darkkhaki",12433259).set("darkmagenta",9109643).set("darkolivegreen",5597999).set("darkorange",16747520).set("darkorchid",10040012).set("darkred",9109504).set("darksalmon",15308410).set("darkseagreen",9419919).set("darkslateblue",4734347).set("darkslategray",3100495).set("darkslategrey",3100495).set("darkturquoise",52945).set("darkviolet",9699539).set("deeppink",16716947).set("deepskyblue",49151).set("dimgray",6908265).set("dimgrey",6908265).set("dodgerblue",2003199).set("firebrick",11674146).set("floralwhite",16775920).set("forestgreen",2263842).set("fuchsia",16711935).set("gainsboro",14474460).set("ghostwhite",16316671).set("gold",16766720).set("goldenrod",14329120).set("gray",8421504).set("green",32768).set("greenyellow",11403055).set("grey",8421504).set("honeydew",15794160).set("hotpink",16738740).set("indianred",13458524).set("indigo",4915330).set("ivory",16777200).set("khaki",15787660).set("lavender",15132410).set("lavenderblush",16773365).set("lawngreen",8190976).set("lemonchiffon",16775885).set("lightblue",11393254).set("lightcoral",15761536).set("lightcyan",14745599).set("lightgoldenrodyellow",16448210).set("lightgray",13882323).set("lightgreen",9498256).set("lightgrey",13882323).set("lightpink",16758465).set("lightsalmon",16752762).set("lightseagreen",2142890).set("lightskyblue",8900346).set("lightslategray",7833753).set("lightslategrey",7833753).set("lightsteelblue",11584734).set("lightyellow",16777184).set("lime",65280).set("limegreen",3329330).set("linen",16445670).set("magenta",16711935).set("maroon",8388608).set("mediumaquamarine",6737322).set("mediumblue",205).set("mediumorchid",12211667).set("mediumpurple",9662683).set("mediumseagreen",3978097).set("mediumslateblue",8087790).set("mediumspringgreen",64154).set("mediumturquoise",4772300).set("mediumvioletred",13047173).set("midnightblue",1644912).set("mintcream",16121850).set("mistyrose",16770273).set("moccasin",16770229).set("navajowhite",16768685).set("navy",128).set("oldlace",16643558).set("olive",8421376).set("olivedrab",7048739).set("orange",16753920).set("orangered",16729344).set("orchid",14315734).set("palegoldenrod",15657130).set("palegreen",10025880).set("paleturquoise",11529966).set("palevioletred",14381203).set("papayawhip",16773077).set("peachpuff",16767673).set("peru",13468991).set("pink",16761035).set("plum",14524637).set("powderblue",11591910).set("purple",8388736).set("rebeccapurple",6697881).set("red",16711680).set("rosybrown",12357519).set("royalblue",4286945).set("saddlebrown",9127187).set("salmon",16416882).set("sandybrown",16032864).set("seagreen",3050327).set("seashell",16774638).set("sienna",10506797).set("silver",12632256).set("skyblue",8900331).set("slateblue",6970061).set("slategray",7372944).set("slategrey",7372944).set("snow",16775930).set("springgreen",65407).set("steelblue",4620980).set("tan",13808780).set("teal",32896).set("thistle",14204888).set("tomato",16737095).set("turquoise",4251856).set("violet",15631086).set("wheat",16113331).set("white",16777215).set("whitesmoke",16119285).set("yellow",16776960).set("yellowgreen",10145074),p=s.prototype=new e,b=.7;p.darker=function(t){return t=null==t?b:Math.pow(b,t),new s(this.r*t,this.g*t,this.b*t)};var N=1/b;p.brighter=function(t){return t=null==t?N:Math.pow(N,t),new s(this.r*t,this.g*t,this.b*t)},p.rgb=function(){return this},p.toString=function(){return n(this.r,this.g,this.b)};var m=function(t,n,r){return 1===arguments.length&&(t instanceof e||(t=S(t)),t?(t=t.rgb(),r=t.b,n=t.g,t=t.r):t=n=r=0/0),new s(t,n,r)},w=i.prototype=new e;w.brighter=function(t){return t=null==t?N:Math.pow(N,t),new i(this.h,this.s,this.l*t)},w.darker=function(t){return t=null==t?b:Math.pow(b,t),new i(this.h,this.s,this.l*t)},w.rgb=function(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,r=.5>=n?n*(1+e):n+e-n*e,i=2*n-r;return new s(a(t>=240?t-240:t+120,i,r),a(t,i,r),a(120>t?t+240:t-120,i,r))};var y=function(t,s,n){if(1===arguments.length)if(t instanceof i)n=t.l,s=t.s,t=t.h;else if(t instanceof e||(t=S(t)),t){if(t instanceof i)return t;t=t.rgb();var r=t.r/255,a=t.g/255,o=t.b/255,h=Math.min(r,a,o),l=Math.max(r,a,o),u=l-h;n=(l+h)/2,u?(s=.5>n?u/(l+h):u/(2-l-h),t=r===l?(a-o)/u+6*(o>a):a===l?(o-r)/u+2:(r-a)/u+4,t*=60):(t=0/0,s=n>0&&1>n?0:t)}else t=s=n=0/0;return new i(t,s,n)},v=/^#([0-9a-f]{3})$/,M=/^#([0-9a-f]{6})$/,k=/^rgb\(\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*\)$/,x=/^rgb\(\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/,q=/^hsl\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/,S=function(t){var e;return t=(t+"").trim().toLowerCase(),(e=v.exec(t))?(e=parseInt(e[1],16),m(e>>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e)):(e=M.exec(t))?r(parseInt(e[1],16)):(e=k.exec(t))?m(e[1],e[2],e[3]):(e=x.exec(t))?m(2.55*e[1],2.55*e[2],2.55*e[3]):(e=q.exec(t))?y(e[1],.01*e[2],.01*e[3]):f.has(t)?r(f.get(t)):null};S.prototype=e.prototype,m.prototype=s.prototype,y.prototype=i.prototype;var $=o.prototype=new e,L=18;$.brighter=function(t){return new o(this.l+L*(null==t?1:t),this.a,this.b)},$.darker=function(t){return new o(this.l-L*(null==t?1:t),this.a,this.b)};var H=.95047,I=1,C=1.08883,j=4/29,P=6/29,z=3*P*P,R=P*P*P;$.rgb=function(){var t=(this.l+16)/116,e=isNaN(this.a)?t:t+this.a/500,n=isNaN(this.b)?t:t-this.b/200;return t=I*l(t),e=H*l(e),n=C*l(n),new s(h(3.2404542*e-1.5371385*t-.4985314*n),h(-.969266*e+1.8760108*t+.041556*n),h(.0556434*e-.2040259*t+1.0572252*n))};var A=Math.PI/180,B=g.prototype=new e;B.brighter=function(t){return new g(this.h,this.c,this.l+L*(null==t?1:t))},B.darker=function(t){return new g(this.h,this.c,this.l-L*(null==t?1:t))},B.rgb=function(){return D(this).rgb()};var D=function(t,e,n){if(1===arguments.length)if(t instanceof o)n=t.b,e=t.a,t=t.l;else if(t instanceof g){var r=t.h*A;n=Math.sin(r)*t.c,e=Math.cos(r)*t.c,t=t.l}else{t instanceof s||(t=m(t));var i=c(t.r),a=c(t.g),n=c(t.b),h=u((.4124564*i+.3575761*a+.1804375*n)/H),l=u((.2126729*i+.7151522*a+.072175*n)/I),d=u((.0193339*i+.119192*a+.9503041*n)/C);n=200*(l-d),e=500*(h-l),t=116*l-16}return new o(t,e,n)};D.prototype=o.prototype;var E=180/Math.PI,F=function(t,e,s){return 1===arguments.length&&(t instanceof g?(s=t.l,e=t.c,t=t.h):(t instanceof o||(t=D(t)),s=t.l,e=Math.sqrt(t.a*t.a+t.b*t.b),t=Math.atan2(t.b,t.a)*E,0>t&&(t+=360))),new g(t,e,s)};F.prototype=g.prototype;var G=d.prototype=new e;G.brighter=function(t){return t=null==t?N:Math.pow(N,t),new d(this.h,this.s,this.l*t)},G.darker=function(t){return t=null==t?b:Math.pow(b,t),new d(this.h,this.s,this.l*t)};var J=1,K=-.14861,O=1.78277,Q=-.29227,T=-.90649,U=1.97294,V=U*T,W=U*O,X=O*Q-T*K,Y=function(t,e,n){if(1===arguments.length)if(t instanceof d)n=t.l,e=t.s,t=t.h;else{t instanceof s||(t=m(t));var r=t.r/255,i=t.g/255,a=t.b/255;n=(X*a+V*r-W*i)/(X+V-W);var o=a-n,h=(U*(i-n)-Q*o)/T,l=Math.pow(n,J);e=Math.sqrt(h*h+o*o)/(U*l*(1-l)),t=e?Math.atan2(h,o)*E-120:0/0,0>t&&(t+=360)}return new d(t,e,n)};G.rgb=function(){var t=isNaN(this.h)?0:(this.h+120)*A,e=Math.pow(this.l,J),n=isNaN(this.s)?0:this.s*e*(1-e),r=Math.cos(t),i=Math.sin(t);return new s(255*(e+n*(K*r+O*i)),255*(e+n*(Q*r+T*i)),255*(e+n*U*r))},Y.prototype=d.prototype;var Z=function(t,e){t=Y(t),e=Y(e);var s=isNaN(t.h)?e.h:t.h,n=isNaN(t.s)?e.s:t.s,r=t.l,i=isNaN(e.h)?0:e.h-s,a=isNaN(e.s)?0:e.s-n,o=e.l-r;return function(e){return t.h=s+i*e,t.s=n+a*e,t.l=r+o*e,t+""}},_=function(t,e){var s=(t-e)%360;return s+(s>180?-360:-180>s?360:0)},tt=function(t,e){t=Y(t),e=Y(e);var s=isNaN(t.h)?e.h:t.h,n=isNaN(t.s)?e.s:t.s,r=t.l,i=isNaN(e.h)?0:_(e.h,s),a=isNaN(e.s)?0:e.s-n,o=e.l-r;return function(e){return t.h=s+i*e,t.s=n+a*e,t.l=r+o*e,t+""}},et=function(t,e){t=F(t),e=F(e);var s=isNaN(t.h)?e.h:t.h,n=isNaN(t.c)?e.c:t.c,r=t.l,i=isNaN(e.h)?0:e.h-s,a=isNaN(e.c)?0:e.c-n,o=e.l-r;return function(e){return t.h=s+i*e,t.c=n+a*e,t.l=r+o*e,t+""}},st=function(t,e){t=F(t),e=F(e);var s=isNaN(t.h)?e.h:t.h,n=isNaN(t.c)?e.c:t.c,r=t.l,i=isNaN(e.h)?0:_(e.h,s),a=isNaN(e.c)?0:e.c-n,o=e.l-r;return function(e){return t.h=s+i*e,t.c=n+a*e,t.l=r+o*e,t+""}},nt=function(t,e){t=D(t),e=D(e);var s=t.l,n=t.a,r=t.b,i=e.l-s,a=e.a-n,o=e.b-r;return function(e){return t.l=s+i*e,t.a=n+a*e,t.b=r+o*e,t+""}},rt=function(t,e){t=y(t),e=y(e);var s=isNaN(t.h)?e.h:t.h,n=isNaN(t.s)?e.s:t.s,r=t.l,i=isNaN(e.h)?0:e.h-s,a=isNaN(e.s)?0:e.s-n,o=e.l-r;return function(e){return t.h=s+i*e,t.s=n+a*e,t.l=r+o*e,t+""}},it=function(t,e){t=y(t),e=y(e);var s=isNaN(t.h)?e.h:t.h,n=isNaN(t.s)?e.s:t.s,r=t.l,i=isNaN(e.h)?0:_(e.h,s),a=isNaN(e.s)?0:e.s-n,o=e.l-r;return function(e){return t.h=s+i*e,t.s=n+a*e,t.l=r+o*e,t+""}},at=function(t,e){t=m(t),e=m(e);var s=t.r,r=t.g,i=t.b,a=e.r-s,o=e.g-r,h=e.b-i;return function(t){return n(Math.round(s+a*t),Math.round(r+o*t),Math.round(i+h*t))}};t.color=S,t.rgb=m,t.hsl=y,t.lab=D,t.hcl=F,t.cubehelix=Y,t.interpolateRgb=at,t.interpolateHsl=it,t.interpolateHslLong=rt,t.interpolateLab=nt,t.interpolateHcl=st,t.interpolateHclLong=et,t.interpolateCubehelix=tt,t.interpolateCubehelixLong=Z});
"undefined"==typeof Map?(Map=function(){this.clear()},Map.prototype={set:function(t,e){return this._[t]=e,this},get:function(t){return this._[t]},has:function(t){return t in this._},"delete":function(t){return t in this._&&delete this._[t]},clear:function(){this._=Object.create(null)},get size(){var t=0;for(var e in this._)++t;return t},forEach:function(t){for(var e in this._)t(this._[e],e,this)}}):function(){var t=new Map;t.set(0,0)!==t&&(t=t.set,Map.prototype.set=function(){return t.apply(this,arguments),this})}(),function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.color={})}(this,function(t){"use strict";function e(t,e){var s=t-e;return s>180||-180>s?s-360*Math.round(s/360):s}function s(t,e,s){this.h=+t,this.s=+e,this.l=+s}function n(){}function r(t,e,s){this.r=Math.round(t),this.g=Math.round(e),this.b=Math.round(s)}function i(t,e,s){return isNaN(t)&&(t=0),isNaN(e)&&(e=0),isNaN(s)&&(s=0),"#"+(16>t?"0"+Math.max(0,t).toString(16):Math.min(255,t).toString(16))+(16>e?"0"+Math.max(0,e).toString(16):Math.min(255,e).toString(16))+(16>s?"0"+Math.max(0,s).toString(16):Math.min(255,s).toString(16))}function a(t){return c(t>>16&255,t>>8&255,255&t)}function o(t,e,s){this.h=+t,this.s=+e,this.l=+s}function h(t,e,s){return 255*(60>t?e+(s-e)*t/60:180>t?s:240>t?e+(s-e)*(240-t)/60:e)}function l(t,e,s){if(1===arguments.length)if(t instanceof o)s=t.l,e=t.s,t=t.h;else if(t instanceof n||(t=u(t)),t){if(t instanceof o)return t;t=t.rgb();var r=t.r/255,i=t.g/255,a=t.b/255,h=Math.min(r,i,a),l=Math.max(r,i,a),c=l-h;s=(l+h)/2,c?(e=.5>s?c/(l+h):c/(2-l-h),t=r===l?(i-a)/c+6*(a>i):i===l?(a-r)/c+2:(r-i)/c+4,t*=60):(t=NaN,e=s>0&&1>s?0:t)}else t=e=s=NaN;return new o(t,e,s)}function u(t){var e;return t=(t+"").trim().toLowerCase(),(e=V.exec(t))?(e=parseInt(e[1],16),c(e>>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e)):(e=U.exec(t))?a(parseInt(e[1],16)):(e=T.exec(t))?c(e[1],e[2],e[3]):(e=Q.exec(t))?c(2.55*e[1],2.55*e[2],2.55*e[3]):(e=K.exec(t))?l(e[1],.01*e[2],.01*e[3]):F.has(t)?a(F.get(t)):null}function c(t,e,s){return 1===arguments.length&&(t instanceof n||(t=u(t)),t?(t=t.rgb(),s=t.b,e=t.g,t=t.r):t=e=s=NaN),new r(t,e,s)}function g(t,e,n){if(1===arguments.length)if(t instanceof s)n=t.l,e=t.s,t=t.h;else{t instanceof r||(t=c(t));var i=t.r/255,a=t.g/255,o=t.b/255;n=(D*o+B*i-A*a)/(D+B-A);var h=o-n,l=(I*(a-n)-O*h)/G;e=Math.sqrt(l*l+h*h)/(I*n*(1-n)),t=e?Math.atan2(l,h)*R-120:NaN,0>t&&(t+=360)}return new s(t,e,n)}function f(t){return function(s,n){s=g(s),n=g(n);var r=isNaN(s.h)?n.h:s.h,i=isNaN(s.s)?n.s:s.s,a=s.l,o=isNaN(n.h)?0:e(n.h,r),h=isNaN(n.s)?0:n.s-i,l=n.l-a;return function(e){return s.h=r+o*e,s.s=i+h*e,s.l=a+l*Math.pow(e,t),s+""}}}function d(t){return function(e,s){e=g(e),s=g(s);var n=isNaN(e.h)?s.h:e.h,r=isNaN(e.s)?s.s:e.s,i=e.l,a=isNaN(s.h)?0:s.h-n,o=isNaN(s.s)?0:s.s-r,h=s.l-i;return function(s){return e.h=n+a*s,e.s=r+o*s,e.l=i+h*Math.pow(s,t),e+""}}}function p(t,e,s){this.l=+t,this.a=+e,this.b=+s}function b(t){return 255*(.0031308>=t?12.92*t:1.055*Math.pow(t,1/2.4)-.055)}function N(t){return t>Z?t*t*t:tt*(t-Y)}function y(t){return t>rt?Math.pow(t,1/3):t/tt+Y}function m(t){return(t/=255)<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function w(t,e,s){this.h=+t,this.c=+e,this.l=+s}function v(t,e,s){if(1===arguments.length)if(t instanceof p)s=t.b,e=t.a,t=t.l;else if(t instanceof w){var n=t.h*E;s=Math.sin(n)*t.c,e=Math.cos(n)*t.c,t=t.l}else{t instanceof r||(t=c(t));var i=m(t.r),a=m(t.g),s=m(t.b),o=y((.4124564*i+.3575761*a+.1804375*s)/st),h=y((.2126729*i+.7151522*a+.072175*s)/nt),l=y((.0193339*i+.119192*a+.9503041*s)/et);s=200*(h-l),e=500*(o-h),t=116*h-16}return new p(t,e,s)}function M(t,e,s){return 1===arguments.length&&(t instanceof w?(s=t.l,e=t.c,t=t.h):(t instanceof p||(t=v(t)),s=t.l,e=Math.sqrt(t.a*t.a+t.b*t.b),t=Math.atan2(t.b,t.a)*R,0>t&&(t+=360))),new w(t,e,s)}function k(t,e){t=M(t),e=M(e);var s=isNaN(t.h)?e.h:t.h,n=isNaN(t.c)?e.c:t.c,r=t.l,i=isNaN(e.h)?0:e.h-s,a=isNaN(e.c)?0:e.c-n,o=e.l-r;return function(e){return t.h=s+i*e,t.c=n+a*e,t.l=r+o*e,t+""}}function x(t,s){t=M(t),s=M(s);var n=isNaN(t.h)?s.h:t.h,r=isNaN(t.c)?s.c:t.c,i=t.l,a=isNaN(s.h)?0:e(s.h,n),o=isNaN(s.c)?0:s.c-r,h=s.l-i;return function(e){return t.h=n+a*e,t.c=r+o*e,t.l=i+h*e,t+""}}function q(t,e){t=v(t),e=v(e);var s=t.l,n=t.a,r=t.b,i=e.l-s,a=e.a-n,o=e.b-r;return function(e){return t.l=s+i*e,t.a=n+a*e,t.b=r+o*e,t+""}}function _(t,e){t=l(t),e=l(e);var s=isNaN(t.h)?e.h:t.h,n=isNaN(t.s)?e.s:t.s,r=t.l,i=isNaN(e.h)?0:e.h-s,a=isNaN(e.s)?0:e.s-n,o=e.l-r;return function(e){return t.h=s+i*e,t.s=n+a*e,t.l=r+o*e,t+""}}function S(t,s){t=l(t),s=l(s);var n=isNaN(t.h)?s.h:t.h,r=isNaN(t.s)?s.s:t.s,i=t.l,a=isNaN(s.h)?0:e(s.h,n),o=isNaN(s.s)?0:s.s-r,h=s.l-i;return function(e){return t.h=n+a*e,t.s=r+o*e,t.l=i+h*e,t+""}}function L(t,e){t=c(t),e=c(e);var s=t.r,n=t.g,r=t.b,a=e.r-s,o=e.g-n,h=e.b-r;return function(t){return i(Math.round(s+a*t),Math.round(n+o*t),Math.round(r+h*t))}}n.prototype={displayable:function(){return this.rgb().displayable()},toString:function(){return this.rgb()+""}};var j=s.prototype=new n,C=.7,$=r.prototype=new n;$.brighter=function(t){return t=null==t?H:Math.pow(H,t),new r(this.r*t,this.g*t,this.b*t)},$.rgb=function(){return this},$.displayable=function(){return 0<=this.r&&this.r<=255&&0<=this.g&&this.g<=255&&0<=this.b&&this.b<=255},$.toString=function(){return i(this.r,this.g,this.b)},$.darker=function(t){return t=null==t?C:Math.pow(C,t),new r(this.r*t,this.g*t,this.b*t)};var H=1/C;j.brighter=function(t){return t=null==t?H:Math.pow(H,t),new s(this.h,this.s,this.l*t)},j.darker=function(t){return t=null==t?C:Math.pow(C,t),new s(this.h,this.s,this.l*t)};var I=1.97294,G=-.90649,O=-.29227,P=1.78277,z=-.14861,E=Math.PI/180;j.rgb=function(){var t=isNaN(this.h)?0:(this.h+120)*E,e=+this.l,s=isNaN(this.s)?0:this.s*e*(1-e),n=Math.cos(t),i=Math.sin(t);return new r(255*(e+s*(z*n+P*i)),255*(e+s*(O*n+G*i)),255*(e+s*I*n))};var R=180/Math.PI,A=I*P,B=I*G,D=P*O-G*z,F=(new Map).set("aliceblue",15792383).set("antiquewhite",16444375).set("aqua",65535).set("aquamarine",8388564).set("azure",15794175).set("beige",16119260).set("bisque",16770244).set("black",0).set("blanchedalmond",16772045).set("blue",255).set("blueviolet",9055202).set("brown",10824234).set("burlywood",14596231).set("cadetblue",6266528).set("chartreuse",8388352).set("chocolate",13789470).set("coral",16744272).set("cornflowerblue",6591981).set("cornsilk",16775388).set("crimson",14423100).set("cyan",65535).set("darkblue",139).set("darkcyan",35723).set("darkgoldenrod",12092939).set("darkgray",11119017).set("darkgreen",25600).set("darkgrey",11119017).set("darkkhaki",12433259).set("darkmagenta",9109643).set("darkolivegreen",5597999).set("darkorange",16747520).set("darkorchid",10040012).set("darkred",9109504).set("darksalmon",15308410).set("darkseagreen",9419919).set("darkslateblue",4734347).set("darkslategray",3100495).set("darkslategrey",3100495).set("darkturquoise",52945).set("darkviolet",9699539).set("deeppink",16716947).set("deepskyblue",49151).set("dimgray",6908265).set("dimgrey",6908265).set("dodgerblue",2003199).set("firebrick",11674146).set("floralwhite",16775920).set("forestgreen",2263842).set("fuchsia",16711935).set("gainsboro",14474460).set("ghostwhite",16316671).set("gold",16766720).set("goldenrod",14329120).set("gray",8421504).set("green",32768).set("greenyellow",11403055).set("grey",8421504).set("honeydew",15794160).set("hotpink",16738740).set("indianred",13458524).set("indigo",4915330).set("ivory",16777200).set("khaki",15787660).set("lavender",15132410).set("lavenderblush",16773365).set("lawngreen",8190976).set("lemonchiffon",16775885).set("lightblue",11393254).set("lightcoral",15761536).set("lightcyan",14745599).set("lightgoldenrodyellow",16448210).set("lightgray",13882323).set("lightgreen",9498256).set("lightgrey",13882323).set("lightpink",16758465).set("lightsalmon",16752762).set("lightseagreen",2142890).set("lightskyblue",8900346).set("lightslategray",7833753).set("lightslategrey",7833753).set("lightsteelblue",11584734).set("lightyellow",16777184).set("lime",65280).set("limegreen",3329330).set("linen",16445670).set("magenta",16711935).set("maroon",8388608).set("mediumaquamarine",6737322).set("mediumblue",205).set("mediumorchid",12211667).set("mediumpurple",9662683).set("mediumseagreen",3978097).set("mediumslateblue",8087790).set("mediumspringgreen",64154).set("mediumturquoise",4772300).set("mediumvioletred",13047173).set("midnightblue",1644912).set("mintcream",16121850).set("mistyrose",16770273).set("moccasin",16770229).set("navajowhite",16768685).set("navy",128).set("oldlace",16643558).set("olive",8421376).set("olivedrab",7048739).set("orange",16753920).set("orangered",16729344).set("orchid",14315734).set("palegoldenrod",15657130).set("palegreen",10025880).set("paleturquoise",11529966).set("palevioletred",14381203).set("papayawhip",16773077).set("peachpuff",16767673).set("peru",13468991).set("pink",16761035).set("plum",14524637).set("powderblue",11591910).set("purple",8388736).set("rebeccapurple",6697881).set("red",16711680).set("rosybrown",12357519).set("royalblue",4286945).set("saddlebrown",9127187).set("salmon",16416882).set("sandybrown",16032864).set("seagreen",3050327).set("seashell",16774638).set("sienna",10506797).set("silver",12632256).set("skyblue",8900331).set("slateblue",6970061).set("slategray",7372944).set("slategrey",7372944).set("snow",16775930).set("springgreen",65407).set("steelblue",4620980).set("tan",13808780).set("teal",32896).set("thistle",14204888).set("tomato",16737095).set("turquoise",4251856).set("violet",15631086).set("wheat",16113331).set("white",16777215).set("whitesmoke",16119285).set("yellow",16776960).set("yellowgreen",10145074),J=o.prototype=new n;J.brighter=function(t){return t=null==t?H:Math.pow(H,t),new o(this.h,this.s,this.l*t)},J.darker=function(t){return t=null==t?C:Math.pow(C,t),new o(this.h,this.s,this.l*t)},J.rgb=function(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,s=this.l,n=s+(.5>s?s:1-s)*e,i=2*s-n;return new r(h(t>=240?t-240:t+120,i,n),h(t,i,n),h(120>t?t+240:t-120,i,n))},J.displayable=function(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1};var K=/^hsl\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/,Q=/^rgb\(\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/,T=/^rgb\(\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*\)$/,U=/^#([0-9a-f]{6})$/,V=/^#([0-9a-f]{3})$/;t.interpolateCubehelix=f(1),t.interpolateCubehelixLong=d(1),u.prototype=n.prototype,c.prototype=r.prototype,l.prototype=o.prototype;var W=p.prototype=new n,X=18;W.brighter=function(t){return new p(this.l+X*(null==t?1:t),this.a,this.b)},W.darker=function(t){return new p(this.l-X*(null==t?1:t),this.a,this.b)};var Y=4/29,Z=6/29,tt=3*Z*Z,et=1.08883,st=.95047,nt=1;W.rgb=function(){var t=(this.l+16)/116,e=isNaN(this.a)?t:t+this.a/500,s=isNaN(this.b)?t:t-this.b/200;return t=nt*N(t),e=st*N(e),s=et*N(s),new r(b(3.2404542*e-1.5371385*t-.4985314*s),b(-.969266*e+1.8760108*t+.041556*s),b(.0556434*e-.2040259*t+1.0572252*s))};var rt=Z*Z*Z,it=w.prototype=new n;it.brighter=function(t){return new w(this.h,this.c,this.l+X*(null==t?1:t))},it.darker=function(t){return new w(this.h,this.c,this.l-X*(null==t?1:t))},it.rgb=function(){return v(this).rgb()},v.prototype=p.prototype,M.prototype=w.prototype,g.prototype=s.prototype,t.color=u,t.rgb=c,t.hsl=l,t.lab=v,t.hcl=M,t.cubehelix=g,t.interpolateRgb=L,t.interpolateHsl=S,t.interpolateHslLong=_,t.interpolateLab=q,t.interpolateHcl=x,t.interpolateHclLong=k,t.interpolateCubehelixGamma=f,t.interpolateCubehelixGammaLong=d});

@@ -13,5 +13,8 @@ import {default as color, Color} from "./src/color";

import interpolateHclLong from "./src/interpolateHclLong";
import interpolateCubehelix from "./src/interpolateCubehelix";
import interpolateCubehelixLong from "./src/interpolateCubehelixLong";
import interpolateCubehelixGamma from "./src/interpolateCubehelixGamma";
import interpolateCubehelixGammaLong from "./src/interpolateCubehelixGammaLong";
export var interpolateCubehelix = interpolateCubehelixGamma(1);
export var interpolateCubehelixLong = interpolateCubehelixGammaLong(1);
// Done lazily to avoid circular dependency between Color, Rgb and Hsl.

@@ -38,4 +41,4 @@ color.prototype = Color.prototype;

interpolateHclLong,
interpolateCubehelix,
interpolateCubehelixLong
interpolateCubehelixGamma,
interpolateCubehelixGammaLong
};
{
"name": "d3-color",
"version": "0.2.1",
"version": "0.2.2",
"description": "Color spaces! RGB, HSL, Cubehelix, Lab and HCL (Lch).",

@@ -36,4 +36,4 @@ "keywords": [

"tape": "4",
"uglifyjs": "2"
"uglify-js": "2"
}
}
# d3-color
Color spaces! [RGB](https://en.wikipedia.org/wiki/RGB_color_model), [HSL](https://en.wikipedia.org/wiki/HSL_and_HSV), [Cubehelix](https://www.mrao.cam.ac.uk/~dag/CUBEHELIX/), [Lab (CIELAB) and HCL (CIELCH)](https://en.wikipedia.org/wiki/Lab_color_space#CIELAB).
Even though your browser understands a lot about colors, it doesn’t offer much help in manipulating colors through JavaScript. The d3-color module therefore provides representations for various color spaces, allowing specification, interpolation, conversion and manipulation.
Even though your browser understands a lot about colors, it doesn’t offer much help in manipulating colors through JavaScript. This module provides representations for various color spaces, allowing specification, interpolation, conversion and manipulation (such as making colors brighter or darker).
For example, take the color named “steelblue”:
Changes from D3 3.x:
```js
color("steelblue"); // {r: 70, g: 130, b: 180}
```
* A new [cubehelix](#cubehelix) color space!
Let’s try converting it to HSL:
* New “long” methods for hue interpolation in [HSL](#interpolateHslLong), [HCL](#interpolateHclLong) and [Cubehelix](#interpolateCubehelixLong).
```js
hsl("steelblue"); // {h: 207.27272727272728, s: 0.44, l: 0.4901960784313726}
```
* A new [color](#color) method parses the specified string according to the CSS specification and returns the corresponding color in its color space. For HSL color values, this is the HSL color space; for other values, the RGB color space is used. This method correctly parses RGB colors with percentages (e.g., `rgb(30%,40%,50%)`). Decimal values where integers are required are no longer allowed (e.g., `rgb(100.5,0,0)` is not a valid color).
Now rotate the hue by 90°, bump up the saturation, and format as hex:
* The [*color*.brighter](#color_brighter) method no longer special-cases behavior for black and very dark channels in RGB; it is now a simple channel multiplier, consistent with [*color*.darker](#color_darker) and other color spaces.
```js
c.h += 90;
c.s += .2;
c + ""; // #c62dcd
```
* The *rgb*.hsl method has been removed; use the [hsl constructor](#hsl) to convert to HSL instead.
Or to find the perceptual halfway point between steelblue and brown:
* All color spaces, including RGB, now support the [*color*.rgb](#color_rgb) method. This method returns a color instance representing the nearest-equivalent color in the RGB color space. Use the [rgb constructor](#rgb) if you want a copy.
```js
interpolateLab("steelblue", "brown")(.5); // #8e5c6d
```
* When converting from Lab to HCL, hue and chroma are no longer undefined if the luminance is zero. Thus, the roundtrip from Lab to HCL and back again no longer loses information.
In addition to the ubiquitous and machine-friendly [RGB](#rgb) and [HSL](#hsl) color space, d3-color supports two color spaces that are designed for humans:
* Colors are now validated upon construction. For example, an RGB color’s `r`, `g` and `b` values are integers in the range [0,255]; an HSL color’s `s` and `l` are numbers in the range [0,1].
* Dave Green’s [Cubehelix](#cubehelix)
* [Lab (CIELAB)](#lab) and [HCL (CIELCH)](#hcl)
Cubehelix features monotonic lightness, while Lab and HCL are perceptually uniform. Note that HCL is the cylindrical form of Lab, similar to how HSL is the cylindrical form of RGB.
## Installing
If you use NPM, `npm install d3-color`. Otherwise, download the [latest release](https://github.com/d3/d3-color/releases/latest).
## API Reference
<a name="color" href="#color">#</a> <b>color</b>(<i>specifier</i>)

@@ -51,2 +70,6 @@

<a name="color_displayable" href="#color_displayable">#</a> *color*.<b>displayable</b>()
Returns true if and only if the color is displayable on standard hardware. For example, this returns false for an RGB color if any channel value is less than zero or greater than 255.
<a name="color_toString" href="#color_toString">#</a> *color*.<b>toString</b>()

@@ -60,3 +83,3 @@

Constructs a new RGB color. The channel values are exposed as `r`, `g` and `b` properties on the returned instance. Channel values will be rounded to the nearest integer value and clamped to the range [0,255]. Use the [RGB color picker](http://bl.ocks.org/mbostock/78d64ca7ef013b4dcf8f) to explore this color space.
Constructs a new [RGB](https://en.wikipedia.org/wiki/RGB_color_model) color. The channel values are exposed as `r`, `g` and `b` properties on the returned instance. Channel values will be rounded to the nearest integer value. Use the [RGB color picker](http://bl.ocks.org/mbostock/78d64ca7ef013b4dcf8f) to explore this color space.

@@ -69,3 +92,3 @@ If *r*, *g* and *b* are specified, these represent the channel values of the returned color. If a CSS Color Module Level 3 *specifier* string is specified, it is parsed and then converted to the RGB color space. See [color](#color) for examples. If a [*color*](#color) instance is specified, it is converted to the RGB color space using [*color*.rgb](#color_rgb). Note that unlike [*color*.rgb](#color_rgb) this method *always* returns a new instance, even if *color* is already an RGB color.

Constructs a new HSL color. The channel values are exposed as `h`, `s` and `l` properties on the returned instance. The saturation and lightness channels will be clamped to the range [0,1]. Use the [HSL color picker](http://bl.ocks.org/mbostock/debaad4fcce9bcee14cf) to explore this color space.
Constructs a new [HSL](https://en.wikipedia.org/wiki/HSL_and_HSV) color. The channel values are exposed as `h`, `s` and `l` properties on the returned instance. Use the [HSL color picker](http://bl.ocks.org/mbostock/debaad4fcce9bcee14cf) to explore this color space.

@@ -78,3 +101,3 @@ If *h*, *s* and *l* are specified, these represent the channel values of the returned color. If a CSS Color Module Level 3 *specifier* string is specified, it is parsed and then converted to the HSL color space. See [color](#color) for examples. If a [*color*](#color) instance is specified, it is converted to the RGB color space using [*color*.rgb](#color_rgb) and then converted to HSL. (Colors already in the HSL color space skip the conversion to RGB.)

Constructs a new Lab color. The channel values are exposed as `l`, `a` and `b` properties on the returned instance. Use the [Lab color picker](http://bl.ocks.org/mbostock/9f37cc207c0cb166921b) to explore this color space.
Constructs a new [Lab](https://en.wikipedia.org/wiki/Lab_color_space#CIELAB) color. The channel values are exposed as `l`, `a` and `b` properties on the returned instance. Use the [Lab color picker](http://bl.ocks.org/mbostock/9f37cc207c0cb166921b) to explore this color space.

@@ -87,3 +110,3 @@ If *l*, *a* and *b* are specified, these represent the channel values of the returned color. If a CSS Color Module Level 3 *specifier* string is specified, it is parsed and then converted to the Lab color space. See [color](#color) for examples. If a [*color*](#color) instance is specified, it is converted to the RGB color space using [*color*.rgb](#color_rgb) and then converted to Lab. (Colors already in the Lab color space skip the conversion to RGB, and colors in the HCL color space are converted directly to Lab.)

Constructs a new HCL color. The channel values are exposed as `h`, `c` and `l` properties on the returned instance. Use the [HCL color picker](http://bl.ocks.org/mbostock/3e115519a1b495e0bd95) to explore this color space.
Constructs a new [HCL](https://en.wikipedia.org/wiki/Lab_color_space#CIELAB) color. The channel values are exposed as `h`, `c` and `l` properties on the returned instance. Use the [HCL color picker](http://bl.ocks.org/mbostock/3e115519a1b495e0bd95) to explore this color space.

@@ -96,3 +119,3 @@ If *h*, *c* and *l* are specified, these represent the channel values of the returned color. If a CSS Color Module Level 3 *specifier* string is specified, it is parsed and then converted to the HCL color space. See [color](#color) for examples. If a [*color*](#color) instance is specified, it is converted to the RGB color space using [*color*.rgb](#color_rgb) and then converted to HCL. (Colors already in the HCL color space skip the conversion to RGB, and colors in the Lab color space are converted directly to HCL.)

Constructs a new Cubehelix color. The channel values are exposed as `h`, `s` and `l` properties on the returned instance. Use the [Cubehelix color picker](http://bl.ocks.org/mbostock/ba8d75e45794c27168b5) to explore this color space.
Constructs a new [Cubehelix](https://www.mrao.cam.ac.uk/~dag/CUBEHELIX/) color. The channel values are exposed as `h`, `s` and `l` properties on the returned instance. Use the [Cubehelix color picker](http://bl.ocks.org/mbostock/ba8d75e45794c27168b5) to explore this color space.

@@ -141,3 +164,3 @@ If *h*, *s* and *l* are specified, these represent the channel values of the returned color. If a CSS Color Module Level 3 *specifier* string is specified, it is parsed and then converted to the Cubehelix color space. See [color](#color) for examples. If a [*color*](#color) instance is specified, it is converted to the RGB color space using [*color*.rgb](#color_rgb) and then converted to Cubehelix. (Colors already in the Cubehelix color space skip the conversion to RGB.)

Returns a Cubehelix color space interpolator between the two colors *a* and *b*. The colors *a* and *b* need not be in Cubehelix; they will be converted to Cubehelix using [cubehelix](#cubehelix). If either color’s hue or saturation is NaN, the opposing color’s channel value is used. The shortest path between hues is used. The return value of the interpolator is a hexadecimal RGB string.
Returns a Cubehelix color space interpolator between the two colors *a* and *b* using the default *gamma* of 1.0. The colors *a* and *b* need not be in Cubehelix; they will be converted to Cubehelix using [cubehelix](#cubehelix). If either color’s hue or saturation is NaN, the opposing color’s channel value is used. The shortest path between hues is used. The return value of the interpolator is a hexadecimal RGB string.

@@ -149,1 +172,31 @@ <a name="interpolateCubehelixLong" href="#interpolateCubehelixLong">#</a> <b>interpolateCubehelixLong</b>(<i>a</i>, <i>b</i>)

Like [interpolateCubehelix](#interpolateCubehelix), but does not use the shortest path between hues.
<a name="interpolateCubehelixGamma" href="#interpolateCubehelixGamma">#</a> <b>interpolateCubehelixGamma</b>(<i>gamma</i>)
Returns a Cubehelix color space interpolator factory using the specified *gamma*. A gamma value less than one emphasizes low intensity values, while a gamma value greater than one emphasizes high intensity values. For example:
```js
var i = interpolateCubehelixGamma(1.5)("red", "blue");
```
<a name="interpolateCubehelixGammaLong" href="#interpolateCubehelixGammaLong">#</a> <b>interpolateCubehelixGammaLong</b>(<i>gamma</i>)
Like [interpolateCubehelixGamma](#interpolateCubehelixGamma), but does not use the shortest path between hues.
## Changes from D3 3.x:
* A new [cubehelix](#cubehelix) color space!
* New “long” methods for hue interpolation in [HSL](#interpolateHslLong), [HCL](#interpolateHclLong) and [Cubehelix](#interpolateCubehelixLong).
* A new [color](#color) method parses the specified string according to the CSS specification and returns the corresponding color in its color space. For HSL color values, this is the HSL color space; for other values, the RGB color space is used. This method correctly parses RGB colors with percentages (e.g., `rgb(30%,40%,50%)`). Decimal values where integers are required are no longer allowed (e.g., `rgb(100.5,0,0)` is not a valid color).
* The [*color*.brighter](#color_brighter) method no longer special-cases behavior for black and very dark channels in RGB; it is now a simple channel multiplier, consistent with [*color*.darker](#color_darker) and other color spaces.
* The *rgb*.hsl method has been removed; use the [hsl constructor](#hsl) to convert to HSL instead.
* All color spaces, including RGB, now support the [*color*.rgb](#color_rgb) method. This method returns a color instance representing the nearest-equivalent color in the RGB color space. Use the [rgb constructor](#rgb) if you want a copy.
* When converting from Lab to HCL, hue and chroma are no longer undefined if the luminance is zero. Thus, the roundtrip from Lab to HCL and back again no longer loses information.
* Colors are now validated upon construction. For example, an RGB color’s `r`, `g` and `b` values are integers in the range [0,255]; an HSL color’s `s` and `l` are numbers in the range [0,1].

@@ -13,2 +13,5 @@ import rgb from "./rgb";

Color.prototype = {
displayable: function() {
return this.rgb().displayable();
},
toString: function() {

@@ -15,0 +18,0 @@ return this.rgb() + "";

@@ -5,4 +5,3 @@ import {default as color, Color} from "./color";

var gamma = 1, // Default gamma. TODO Customize.
A = -0.14861,
var A = -0.14861,
B = +1.78277,

@@ -26,4 +25,4 @@ C = -0.29227,

l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB);
var bl = b - l, k = (E * (g - l) - C * bl) / D, lgamma = Math.pow(l, gamma);
s = Math.sqrt(k * k + bl * bl) / (E * lgamma * (1 - lgamma)); // NaN if lgamma=0 or lgamma=1
var bl = b - l, k = (E * (g - l) - C * bl) / D;
s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)); // NaN if l=0 or l=1
h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;

@@ -56,3 +55,3 @@ if (h < 0) h += 360;

var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
l = Math.pow(this.l, gamma),
l = +this.l,
a = isNaN(this.s) ? 0 : this.s * l * (1 - l),

@@ -59,0 +58,0 @@ cosh = Math.cos(h),

@@ -1,4 +0,6 @@

export default function(h, h0) {
var delta = (h - h0) % 360;
return delta + (delta > 180 ? -360 : delta < -180 ? 360 : 0);
export default function(h1, h0) {
var delta = h1 - h0;
return delta > 180 || delta < -180
? delta - 360 * Math.round(delta / 360)
: delta;
};

@@ -42,4 +42,4 @@ import {default as color, Color} from "./color";

this.h = +h;
this.s = Math.max(0, Math.min(1, +s));
this.l = Math.max(0, Math.min(1, +l));
this.s = +s;
this.l = +l;
};

@@ -63,3 +63,3 @@

l = this.l,
m2 = l <= .5 ? l * (1 + s) : l + s - l * s,
m2 = l + (l < .5 ? l : 1 - l) * s,
m1 = 2 * l - m2;

@@ -73,2 +73,7 @@ return new Rgb(

prototype.displayable = function() {
return (0 <= this.s && this.s <= 1 || isNaN(this.s))
&& (0 <= this.l && this.l <= 1);
};
/* From FvD 13.37, CSS Color Module Level 3 */

@@ -75,0 +80,0 @@ function hsl2rgb(h, m1, m2) {

@@ -22,5 +22,5 @@ import {default as color, Color} from "./color";

export function Rgb(r, g, b) {
this.r = Math.max(0, Math.min(255, Math.round(r)));
this.g = Math.max(0, Math.min(255, Math.round(g)));
this.b = Math.max(0, Math.min(255, Math.round(b)));
this.r = Math.round(r);
this.g = Math.round(g);
this.b = Math.round(b);
};

@@ -44,2 +44,8 @@

prototype.displayable = function() {
return (0 <= this.r && this.r <= 255)
&& (0 <= this.g && this.g <= 255)
&& (0 <= this.b && this.b <= 255);
};
prototype.toString = function() {

@@ -54,5 +60,5 @@ return format(this.r, this.g, this.b);

return "#"
+ (r < 16 ? "0" + r.toString(16) : r.toString(16))
+ (g < 16 ? "0" + g.toString(16) : g.toString(16))
+ (b < 16 ? "0" + b.toString(16) : b.toString(16));
+ (r < 16 ? "0" + Math.max(0, r).toString(16) : Math.min(255, r).toString(16))
+ (g < 16 ? "0" + Math.max(0, g).toString(16) : Math.min(255, g).toString(16))
+ (b < 16 ? "0" + Math.max(0, b).toString(16) : Math.min(255, b).toString(16));
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc