pax_global_header 0000666 0000000 0000000 00000000064 13060566206 0014516 g ustar 00root root 0000000 0000000 52 comment=8880bbce23bfdb05d4774a4d459c15d64f7e56ea
d3-color-1.0.3/ 0000775 0000000 0000000 00000000000 13060566206 0013141 5 ustar 00root root 0000000 0000000 d3-color-1.0.3/.eslintrc 0000664 0000000 0000000 00000000227 13060566206 0014766 0 ustar 00root root 0000000 0000000 parserOptions:
sourceType: module
env:
node: true
extends:
"eslint:recommended"
rules:
no-cond-assign: 0
no-floating-decimal: 2
d3-color-1.0.3/.gitignore 0000664 0000000 0000000 00000000100 13060566206 0015120 0 ustar 00root root 0000000 0000000 *.sublime-workspace
.DS_Store
build/
node_modules
npm-debug.log
d3-color-1.0.3/.npmignore 0000664 0000000 0000000 00000000036 13060566206 0015137 0 ustar 00root root 0000000 0000000 *.sublime-*
build/*.zip
test/
d3-color-1.0.3/LICENSE 0000664 0000000 0000000 00000002703 13060566206 0014150 0 ustar 00root root 0000000 0000000 Copyright 2010-2016 Mike Bostock
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the author nor the names of contributors may be used to
endorse or promote products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
d3-color-1.0.3/README.md 0000664 0000000 0000000 00000024175 13060566206 0014431 0 ustar 00root root 0000000 0000000 # d3-color
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, conversion and manipulation. (Also see [d3-interpolate](https://github.com/d3/d3-interpolate) for color interpolation.)
For example, take the color named “steelblue”:
```js
var c = d3.color("steelblue"); // {r: 70, g: 130, b: 180, opacity: 1}
```
Let’s try converting it to HSL:
```js
var c = d3.hsl("steelblue"); // {h: 207.27…, s: 0.44, l: 0.4902…, opacity: 1}
```
Now rotate the hue by 90°, bump up the saturation, and format as a string for CSS:
```js
c.h += 90;
c.s += 0.2;
c + ""; // rgb(198, 45, 205)
```
To fade the color slightly:
```js
c.opacity = 0.8;
c + ""; // rgba(198, 45, 205, 0.8)
```
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:
* 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). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-color.v1.min.js) or as part of [D3 4.0](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported:
```html
```
[Try d3-color in your browser.](https://tonicdev.com/npm/d3-color)
## API Reference
# d3.color(specifier) [<>](https://github.com/d3/d3-color/blob/master/src/color.js "Source")
Parses the specified [CSS Color Module Level 3](http://www.w3.org/TR/css3-color/#colorunits) *specifier* string, returning an [RGB](#rgb) or [HSL](#hsl) color. If the specifier was not valid, null is returned. Some examples:
* `rgb(255, 255, 255)`
* `rgb(10%, 20%, 30%)`
* `rgba(255, 255, 255, 0.4)`
* `rgba(10%, 20%, 30%, 0.4)`
* `hsl(120, 50%, 20%)`
* `hsla(120, 50%, 20%, 0.4)`
* `#ffeeaa`
* `#fea`
* `steelblue`
The list of supported [named colors](http://www.w3.org/TR/SVG/types.html#ColorKeywords) is specified by CSS.
Note: this function may also be used with `instanceof` to test if an object is a color instance. The same is true of color subclasses, allowing you to test whether a color is in a particular color space.
# *color*.opacity
This color’s opacity, typically in the range [0, 1].
# *color*.rgb() [<>](https://github.com/d3/d3-color/blob/master/src/color.js#L209 "Source")
Returns the [RGB equivalent](#rgb) of this color. For RGB colors, that’s `this`.
# *color*.brighter([k]) [<>](https://github.com/d3/d3-color/blob/master/src/color.js#L221 "Source")
Returns a brighter copy of this color. If *k* is specified, it controls how much brighter the returned color should be. If *k* is not specified, it defaults to 1. The behavior of this method is dependent on the implementing color space.
# *color*.darker([k]) [<>](https://github.com/d3/d3-color/blob/master/src/color.js#L225 "Source")
Returns a darker copy of this color. If *k* is specified, it controls how much darker the returned color should be. If *k* is not specified, it defaults to 1. The behavior of this method is dependent on the implementing color space.
# *color*.displayable() [<>](https://github.com/d3/d3-color/blob/master/src/color.js#L169 "Source")
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, or if the opacity is not in the range [0, 1].
# *color*.toString() [<>](https://github.com/d3/d3-color/blob/master/src/color.js#L172 "Source")
Returns a string representing this color according to the [CSS Object Model specification](https://drafts.csswg.org/cssom/#serialize-a-css-component-value), such as `rgb(247, 234, 186)`. If this color is not displayable, a suitable displayable color is returned instead. For example, RGB channel values greater than 255 are clamped to 255.
# d3.rgb(r, g, b[, opacity]) [<>](https://github.com/d3/d3-color/blob/master/src/color.js#L209 "Source")
# d3.rgb(specifier)
# d3.rgb(color)
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. Use the [RGB color picker](http://bl.ocks.org/mbostock/78d64ca7ef013b4dcf8f) to explore this color space.
If *r*, *g* and *b* are specified, these represent the channel values of the returned color; an *opacity* may also be specified. 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.
# d3.hsl(h, s, l[, opacity]) [<>](https://github.com/d3/d3-color/blob/master/src/color.js#L281 "Source")
# d3.hsl(specifier)
# d3.hsl(color)
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.
If *h*, *s* and *l* are specified, these represent the channel values of the returned color; an *opacity* may also be specified. 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.)
# d3.lab(l, a, b[, opacity]) [<>](https://github.com/d3/d3-color/blob/master/src/lab.js#L30 "Source")
# d3.lab(specifier)
# d3.lab(color)
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.
If *l*, *a* and *b* are specified, these represent the channel values of the returned color; an *opacity* may also be specified. 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.)
# d3.hcl(h, c, l[, opacity]) [<>](https://github.com/d3/d3-color/blob/master/src/lab.js#L87 "Source")
# d3.hcl(specifier)
# d3.hcl(color)
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.
If *h*, *c* and *l* are specified, these represent the channel values of the returned color; an *opacity* may also be specified. 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.)
# d3.cubehelix(h, s, l[, opacity]) [<>](https://github.com/d3/d3-color/blob/master/src/cubehelix.js#L32 "Source")
# d3.cubehelix(specifier)
# d3.cubehelix(color)
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.
If *h*, *s* and *l* are specified, these represent the channel values of the returned color; an *opacity* may also be specified. 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.)
d3-color-1.0.3/d3-color.sublime-project 0000664 0000000 0000000 00000000271 13060566206 0017611 0 ustar 00root root 0000000 0000000 {
"folders": [
{
"path": ".",
"file_exclude_patterns": [
"*.sublime-workspace"
],
"folder_exclude_patterns": [
"build"
]
}
]
}
d3-color-1.0.3/index.js 0000664 0000000 0000000 00000000235 13060566206 0014606 0 ustar 00root root 0000000 0000000 export {default as color, rgb, hsl} from "./src/color";
export {default as lab, hcl} from "./src/lab";
export {default as cubehelix} from "./src/cubehelix";
d3-color-1.0.3/package.json 0000664 0000000 0000000 00000002653 13060566206 0015435 0 ustar 00root root 0000000 0000000 {
"name": "d3-color",
"version": "1.0.3",
"description": "Color spaces! RGB, HSL, Cubehelix, Lab and HCL (Lch).",
"keywords": [
"d3",
"d3-module",
"color",
"rgb",
"hsl",
"lab",
"hcl",
"lch",
"cubehelix"
],
"homepage": "https://d3js.org/d3-color/",
"license": "BSD-3-Clause",
"author": {
"name": "Mike Bostock",
"url": "http://bost.ocks.org/mike"
},
"main": "build/d3-color.js",
"module": "index",
"jsnext:main": "index",
"repository": {
"type": "git",
"url": "https://github.com/d3/d3-color.git"
},
"scripts": {
"pretest": "rm -rf build && mkdir build && rollup --banner \"$(preamble)\" -f umd -n d3 -o build/d3-color.js -- index.js",
"test": "tape 'test/**/*-test.js' && eslint index.js src test",
"prepublish": "npm run test && uglifyjs --preamble \"$(preamble)\" build/d3-color.js -c -m -o build/d3-color.min.js",
"postpublish": "git push && git push --tags && cd ../d3.github.com && cp ../d3-color/build/d3-color.js d3-color.v1.js && cp ../d3-color/build/d3-color.min.js d3-color.v1.min.js && git add d3-color.v1.js d3-color.v1.min.js && git commit -m \"d3-color ${npm_package_version}\" && git push && cd - && zip -j build/d3-color.zip -- LICENSE README.md build/d3-color.js build/d3-color.min.js"
},
"devDependencies": {
"eslint": "3",
"package-preamble": "0.0",
"rollup": "0.41",
"tape": "4",
"uglify-js": "^2.8.11"
}
}
d3-color-1.0.3/src/ 0000775 0000000 0000000 00000000000 13060566206 0013730 5 ustar 00root root 0000000 0000000 d3-color-1.0.3/src/color.js 0000664 0000000 0000000 00000022074 13060566206 0015411 0 ustar 00root root 0000000 0000000 import define, {extend} from "./define";
export function Color() {}
export var darker = 0.7;
export var brighter = 1 / darker;
var reI = "\\s*([+-]?\\d+)\\s*",
reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",
reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
reHex3 = /^#([0-9a-f]{3})$/,
reHex6 = /^#([0-9a-f]{6})$/,
reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$"),
reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$"),
reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$"),
reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$"),
reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$"),
reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
var named = {
aliceblue: 0xf0f8ff,
antiquewhite: 0xfaebd7,
aqua: 0x00ffff,
aquamarine: 0x7fffd4,
azure: 0xf0ffff,
beige: 0xf5f5dc,
bisque: 0xffe4c4,
black: 0x000000,
blanchedalmond: 0xffebcd,
blue: 0x0000ff,
blueviolet: 0x8a2be2,
brown: 0xa52a2a,
burlywood: 0xdeb887,
cadetblue: 0x5f9ea0,
chartreuse: 0x7fff00,
chocolate: 0xd2691e,
coral: 0xff7f50,
cornflowerblue: 0x6495ed,
cornsilk: 0xfff8dc,
crimson: 0xdc143c,
cyan: 0x00ffff,
darkblue: 0x00008b,
darkcyan: 0x008b8b,
darkgoldenrod: 0xb8860b,
darkgray: 0xa9a9a9,
darkgreen: 0x006400,
darkgrey: 0xa9a9a9,
darkkhaki: 0xbdb76b,
darkmagenta: 0x8b008b,
darkolivegreen: 0x556b2f,
darkorange: 0xff8c00,
darkorchid: 0x9932cc,
darkred: 0x8b0000,
darksalmon: 0xe9967a,
darkseagreen: 0x8fbc8f,
darkslateblue: 0x483d8b,
darkslategray: 0x2f4f4f,
darkslategrey: 0x2f4f4f,
darkturquoise: 0x00ced1,
darkviolet: 0x9400d3,
deeppink: 0xff1493,
deepskyblue: 0x00bfff,
dimgray: 0x696969,
dimgrey: 0x696969,
dodgerblue: 0x1e90ff,
firebrick: 0xb22222,
floralwhite: 0xfffaf0,
forestgreen: 0x228b22,
fuchsia: 0xff00ff,
gainsboro: 0xdcdcdc,
ghostwhite: 0xf8f8ff,
gold: 0xffd700,
goldenrod: 0xdaa520,
gray: 0x808080,
green: 0x008000,
greenyellow: 0xadff2f,
grey: 0x808080,
honeydew: 0xf0fff0,
hotpink: 0xff69b4,
indianred: 0xcd5c5c,
indigo: 0x4b0082,
ivory: 0xfffff0,
khaki: 0xf0e68c,
lavender: 0xe6e6fa,
lavenderblush: 0xfff0f5,
lawngreen: 0x7cfc00,
lemonchiffon: 0xfffacd,
lightblue: 0xadd8e6,
lightcoral: 0xf08080,
lightcyan: 0xe0ffff,
lightgoldenrodyellow: 0xfafad2,
lightgray: 0xd3d3d3,
lightgreen: 0x90ee90,
lightgrey: 0xd3d3d3,
lightpink: 0xffb6c1,
lightsalmon: 0xffa07a,
lightseagreen: 0x20b2aa,
lightskyblue: 0x87cefa,
lightslategray: 0x778899,
lightslategrey: 0x778899,
lightsteelblue: 0xb0c4de,
lightyellow: 0xffffe0,
lime: 0x00ff00,
limegreen: 0x32cd32,
linen: 0xfaf0e6,
magenta: 0xff00ff,
maroon: 0x800000,
mediumaquamarine: 0x66cdaa,
mediumblue: 0x0000cd,
mediumorchid: 0xba55d3,
mediumpurple: 0x9370db,
mediumseagreen: 0x3cb371,
mediumslateblue: 0x7b68ee,
mediumspringgreen: 0x00fa9a,
mediumturquoise: 0x48d1cc,
mediumvioletred: 0xc71585,
midnightblue: 0x191970,
mintcream: 0xf5fffa,
mistyrose: 0xffe4e1,
moccasin: 0xffe4b5,
navajowhite: 0xffdead,
navy: 0x000080,
oldlace: 0xfdf5e6,
olive: 0x808000,
olivedrab: 0x6b8e23,
orange: 0xffa500,
orangered: 0xff4500,
orchid: 0xda70d6,
palegoldenrod: 0xeee8aa,
palegreen: 0x98fb98,
paleturquoise: 0xafeeee,
palevioletred: 0xdb7093,
papayawhip: 0xffefd5,
peachpuff: 0xffdab9,
peru: 0xcd853f,
pink: 0xffc0cb,
plum: 0xdda0dd,
powderblue: 0xb0e0e6,
purple: 0x800080,
rebeccapurple: 0x663399,
red: 0xff0000,
rosybrown: 0xbc8f8f,
royalblue: 0x4169e1,
saddlebrown: 0x8b4513,
salmon: 0xfa8072,
sandybrown: 0xf4a460,
seagreen: 0x2e8b57,
seashell: 0xfff5ee,
sienna: 0xa0522d,
silver: 0xc0c0c0,
skyblue: 0x87ceeb,
slateblue: 0x6a5acd,
slategray: 0x708090,
slategrey: 0x708090,
snow: 0xfffafa,
springgreen: 0x00ff7f,
steelblue: 0x4682b4,
tan: 0xd2b48c,
teal: 0x008080,
thistle: 0xd8bfd8,
tomato: 0xff6347,
turquoise: 0x40e0d0,
violet: 0xee82ee,
wheat: 0xf5deb3,
white: 0xffffff,
whitesmoke: 0xf5f5f5,
yellow: 0xffff00,
yellowgreen: 0x9acd32
};
define(Color, color, {
displayable: function() {
return this.rgb().displayable();
},
toString: function() {
return this.rgb() + "";
}
});
export default function color(format) {
var m;
format = (format + "").trim().toLowerCase();
return (m = reHex3.exec(format)) ? (m = parseInt(m[1], 16), new Rgb((m >> 8 & 0xf) | (m >> 4 & 0x0f0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1)) // #f00
: (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
: (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
: (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
: (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
: (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
: (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
: (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
: named.hasOwnProperty(format) ? rgbn(named[format])
: format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
: null;
}
function rgbn(n) {
return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
}
function rgba(r, g, b, a) {
if (a <= 0) r = g = b = NaN;
return new Rgb(r, g, b, a);
}
export function rgbConvert(o) {
if (!(o instanceof Color)) o = color(o);
if (!o) return new Rgb;
o = o.rgb();
return new Rgb(o.r, o.g, o.b, o.opacity);
}
export function rgb(r, g, b, opacity) {
return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
}
export function Rgb(r, g, b, opacity) {
this.r = +r;
this.g = +g;
this.b = +b;
this.opacity = +opacity;
}
define(Rgb, rgb, extend(Color, {
brighter: function(k) {
k = k == null ? brighter : Math.pow(brighter, k);
return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
},
darker: function(k) {
k = k == null ? darker : Math.pow(darker, k);
return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
},
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)
&& (0 <= this.opacity && this.opacity <= 1);
},
toString: function() {
var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
return (a === 1 ? "rgb(" : "rgba(")
+ Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
+ Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
+ Math.max(0, Math.min(255, Math.round(this.b) || 0))
+ (a === 1 ? ")" : ", " + a + ")");
}
}));
function hsla(h, s, l, a) {
if (a <= 0) h = s = l = NaN;
else if (l <= 0 || l >= 1) h = s = NaN;
else if (s <= 0) h = NaN;
return new Hsl(h, s, l, a);
}
export function hslConvert(o) {
if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
if (!(o instanceof Color)) o = color(o);
if (!o) return new Hsl;
if (o instanceof Hsl) return o;
o = o.rgb();
var r = o.r / 255,
g = o.g / 255,
b = o.b / 255,
min = Math.min(r, g, b),
max = Math.max(r, g, b),
h = NaN,
s = max - min,
l = (max + min) / 2;
if (s) {
if (r === max) h = (g - b) / s + (g < b) * 6;
else if (g === max) h = (b - r) / s + 2;
else h = (r - g) / s + 4;
s /= l < 0.5 ? max + min : 2 - max - min;
h *= 60;
} else {
s = l > 0 && l < 1 ? 0 : h;
}
return new Hsl(h, s, l, o.opacity);
}
export function hsl(h, s, l, opacity) {
return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
}
function Hsl(h, s, l, opacity) {
this.h = +h;
this.s = +s;
this.l = +l;
this.opacity = +opacity;
}
define(Hsl, hsl, extend(Color, {
brighter: function(k) {
k = k == null ? brighter : Math.pow(brighter, k);
return new Hsl(this.h, this.s, this.l * k, this.opacity);
},
darker: function(k) {
k = k == null ? darker : Math.pow(darker, k);
return new Hsl(this.h, this.s, this.l * k, this.opacity);
},
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 + (l < 0.5 ? l : 1 - l) * s,
m1 = 2 * l - m2;
return new Rgb(
hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
hsl2rgb(h, m1, m2),
hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
this.opacity
);
},
displayable: function() {
return (0 <= this.s && this.s <= 1 || isNaN(this.s))
&& (0 <= this.l && this.l <= 1)
&& (0 <= this.opacity && this.opacity <= 1);
}
}));
/* From FvD 13.37, CSS Color Module Level 3 */
function hsl2rgb(h, m1, m2) {
return (h < 60 ? m1 + (m2 - m1) * h / 60
: h < 180 ? m2
: h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
: m1) * 255;
}
d3-color-1.0.3/src/cubehelix.js 0000664 0000000 0000000 00000003477 13060566206 0016251 0 ustar 00root root 0000000 0000000 import define, {extend} from "./define";
import {Color, rgbConvert, Rgb, darker, brighter} from "./color";
import {deg2rad, rad2deg} from "./math";
var 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;
function cubehelixConvert(o) {
if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
if (!(o instanceof Rgb)) o = rgbConvert(o);
var r = o.r / 255,
g = o.g / 255,
b = o.b / 255,
l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
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;
return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
}
export default function cubehelix(h, s, l, opacity) {
return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
}
export function Cubehelix(h, s, l, opacity) {
this.h = +h;
this.s = +s;
this.l = +l;
this.opacity = +opacity;
}
define(Cubehelix, cubehelix, extend(Color, {
brighter: function(k) {
k = k == null ? brighter : Math.pow(brighter, k);
return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
},
darker: function(k) {
k = k == null ? darker : Math.pow(darker, k);
return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
},
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)),
this.opacity
);
}
}));
d3-color-1.0.3/src/define.js 0000664 0000000 0000000 00000000524 13060566206 0015521 0 ustar 00root root 0000000 0000000 export default function(constructor, factory, prototype) {
constructor.prototype = factory.prototype = prototype;
prototype.constructor = constructor;
}
export function extend(parent, definition) {
var prototype = Object.create(parent.prototype);
for (var key in definition) prototype[key] = definition[key];
return prototype;
}
d3-color-1.0.3/src/lab.js 0000664 0000000 0000000 00000006137 13060566206 0015033 0 ustar 00root root 0000000 0000000 import define, {extend} from "./define";
import {Color, rgbConvert, Rgb} from "./color";
import {deg2rad, rad2deg} from "./math";
var Kn = 18,
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;
function labConvert(o) {
if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
if (o instanceof Hcl) {
var h = o.h * deg2rad;
return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
}
if (!(o instanceof Rgb)) o = rgbConvert(o);
var b = rgb2xyz(o.r),
a = rgb2xyz(o.g),
l = rgb2xyz(o.b),
x = xyz2lab((0.4124564 * b + 0.3575761 * a + 0.1804375 * l) / Xn),
y = xyz2lab((0.2126729 * b + 0.7151522 * a + 0.0721750 * l) / Yn),
z = xyz2lab((0.0193339 * b + 0.1191920 * a + 0.9503041 * l) / Zn);
return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
}
export default function lab(l, a, b, opacity) {
return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
}
export function Lab(l, a, b, opacity) {
this.l = +l;
this.a = +a;
this.b = +b;
this.opacity = +opacity;
}
define(Lab, lab, extend(Color, {
brighter: function(k) {
return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
},
darker: function(k) {
return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
},
rgb: function() {
var y = (this.l + 16) / 116,
x = isNaN(this.a) ? y : y + this.a / 500,
z = isNaN(this.b) ? y : y - this.b / 200;
y = Yn * lab2xyz(y);
x = Xn * lab2xyz(x);
z = Zn * lab2xyz(z);
return new Rgb(
xyz2rgb( 3.2404542 * x - 1.5371385 * y - 0.4985314 * z), // D65 -> sRGB
xyz2rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z),
xyz2rgb( 0.0556434 * x - 0.2040259 * y + 1.0572252 * z),
this.opacity
);
}
}));
function xyz2lab(t) {
return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
}
function lab2xyz(t) {
return t > t1 ? t * t * t : t2 * (t - t0);
}
function xyz2rgb(x) {
return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
}
function rgb2xyz(x) {
return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
}
function hclConvert(o) {
if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
if (!(o instanceof Lab)) o = labConvert(o);
var h = Math.atan2(o.b, o.a) * rad2deg;
return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
}
export function hcl(h, c, l, opacity) {
return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
}
export function Hcl(h, c, l, opacity) {
this.h = +h;
this.c = +c;
this.l = +l;
this.opacity = +opacity;
}
define(Hcl, hcl, extend(Color, {
brighter: function(k) {
return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k), this.opacity);
},
darker: function(k) {
return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k), this.opacity);
},
rgb: function() {
return labConvert(this).rgb();
}
}));
d3-color-1.0.3/src/math.js 0000664 0000000 0000000 00000000110 13060566206 0015207 0 ustar 00root root 0000000 0000000 export var deg2rad = Math.PI / 180;
export var rad2deg = 180 / Math.PI;
d3-color-1.0.3/test/ 0000775 0000000 0000000 00000000000 13060566206 0014120 5 ustar 00root root 0000000 0000000 d3-color-1.0.3/test/color-test.js 0000664 0000000 0000000 00000015513 13060566206 0016556 0 ustar 00root root 0000000 0000000 var tape = require("tape"),
color = require("../");
require("./rgbEqual");
require("./hslEqual");
tape("color(format) parses CSS color names (e.g., \"rebeccapurple\")", function(test) {
test.rgbEqual(color.color("moccasin"), 255, 228, 181, 1);
test.rgbEqual(color.color("aliceblue"), 240, 248, 255, 1);
test.rgbEqual(color.color("yellow"), 255, 255, 0, 1);
test.rgbEqual(color.color("moccasin"), 255, 228, 181, 1);
test.rgbEqual(color.color("aliceblue"), 240, 248, 255, 1);
test.rgbEqual(color.color("yellow"), 255, 255, 0, 1);
test.rgbEqual(color.color("rebeccapurple"), 102, 51, 153, 1);
test.rgbEqual(color.color("transparent"), NaN, NaN, NaN, 0);
test.end();
});
tape("color(format) parses 6-digit hexadecimal (e.g., \"#abcdef\")", function(test) {
test.rgbEqual(color.color("#abcdef"), 171, 205, 239, 1);
test.end();
});
tape("color(format) parses 3-digit hexadecimal (e.g., \"#abc\")", function(test) {
test.rgbEqual(color.color("#abc"), 170, 187, 204, 1);
test.end();
});
tape("color(format) parses RGB integer format (e.g., \"rgb(12,34,56)\")", function(test) {
test.rgbEqual(color.color("rgb(12,34,56)"), 12, 34, 56, 1);
test.end();
});
tape("color(format) parses RGBA integer format (e.g., \"rgba(12,34,56,0.4)\")", function(test) {
test.rgbEqual(color.color("rgba(12,34,56,0.4)"), 12, 34, 56, 0.4);
test.end();
});
tape("color(format) parses RGB percentage format (e.g., \"rgb(12%,34%,56%)\")", function(test) {
test.rgbEqual(color.color("rgb(12%,34%,56%)"), 31, 87, 143, 1);
test.rgbStrictEqual(color.color("rgb(100%,100%,100%)"), 255, 255, 255, 1);
test.end();
});
tape("color(format) parses RGBA percentage format (e.g., \"rgba(12%,34%,56%,0.4)\")", function(test) {
test.rgbEqual(color.color("rgba(12%,34%,56%,0.4)"), 31, 87, 143, 0.4);
test.rgbStrictEqual(color.color("rgba(100%,100%,100%,0.4)"), 255, 255, 255, 0.4);
test.end();
});
tape("color(format) parses HSL format (e.g., \"hsl(60,100%,20%)\")", function(test) {
test.hslEqual(color.color("hsl(60,100%,20%)"), 60, 1, 0.2, 1);
test.end();
});
tape("color(format) parses HSLA format (e.g., \"hsla(60,100%,20%,0.4)\")", function(test) {
test.hslEqual(color.color("hsla(60,100%,20%,0.4)"), 60, 1, 0.2, 0.4);
test.end();
});
tape("color(format) ignores leading and trailing whitespace", function(test) {
test.rgbEqual(color.color(" aliceblue\t\n"), 240, 248, 255, 1);
test.rgbEqual(color.color(" #abc\t\n"), 170, 187, 204, 1);
test.rgbEqual(color.color(" #aabbcc\t\n"), 170, 187, 204, 1);
test.rgbEqual(color.color(" rgb(120,30,50)\t\n"), 120, 30, 50, 1);
test.hslEqual(color.color(" hsl(120,30%,50%)\t\n"), 120, 0.3, 0.5, 1);
test.end();
});
tape("color(format) ignores whitespace between numbers", function(test) {
test.rgbEqual(color.color(" rgb( 120 , 30 , 50 ) "), 120, 30, 50, 1);
test.hslEqual(color.color(" hsl( 120 , 30% , 50% ) "), 120, 0.3, 0.5, 1);
test.rgbEqual(color.color(" rgba( 12 , 34 , 56 , 0.4 ) "), 12, 34, 56, 0.4);
test.rgbEqual(color.color(" rgba( 12% , 34% , 56% , 0.4 ) "), 31, 87, 143, 0.4);
test.hslEqual(color.color(" hsla( 60 , 100% , 20% , 0.4 ) "), 60, 1, 0.2, 0.4);
test.end();
});
tape("color(format) allows number signs", function(test) {
test.rgbEqual(color.color("rgb(+120,+30,+50)"), 120, 30, 50, 1);
test.hslEqual(color.color("hsl(+120,+30%,+50%)"), 120, 0.3, 0.5, 1);
test.rgbEqual(color.color("rgb(-120,-30,-50)"), -120, -30, -50, 1);
test.hslEqual(color.color("hsl(-120,-30%,-50%)"), NaN, NaN, -0.5, 1);
test.rgbEqual(color.color("rgba(12,34,56,+0.4)"), 12, 34, 56, 0.4);
test.rgbEqual(color.color("rgba(12,34,56,-0.4)"), NaN, NaN, NaN, -0.4);
test.rgbEqual(color.color("rgba(12%,34%,56%,+0.4)"), 31, 87, 143, 0.4);
test.rgbEqual(color.color("rgba(12%,34%,56%,-0.4)"), NaN, NaN, NaN, -0.4);
test.hslEqual(color.color("hsla(60,100%,20%,+0.4)"), 60, 1, 0.2, 0.4);
test.hslEqual(color.color("hsla(60,100%,20%,-0.4)"), NaN, NaN, NaN, -0.4);
test.end();
});
tape("color(format) allows decimals for non-integer values", function(test) {
test.rgbEqual(color.color("rgb(20.0%,30.4%,51.2%)"), 51, 78, 131, 1);
test.hslEqual(color.color("hsl(20.0,30.4%,51.2%)"), 20, 0.304, 0.512, 1);
test.end();
});
tape("color(format) allows leading decimal for hue, opacity and percentages", function(test) {
test.hslEqual(color.color("hsl(.9,.3%,.5%)"), 0.9, 0.003, 0.005, 1);
test.hslEqual(color.color("hsla(.9,.3%,.5%,.5)"), 0.9, 0.003, 0.005, 0.5);
test.rgbEqual(color.color("rgb(.1%,.2%,.3%)"), 0, 1, 1, 1);
test.rgbEqual(color.color("rgba(120,30,50,.5)"), 120, 30, 50, 0.5);
test.end();
});
tape("color(format) allows exponential format for hue, opacity and percentages", function(test) {
test.hslEqual(color.color("hsl(1e1,2e1%,3e1%)"), 10, 0.2, 0.3, 1);
test.hslEqual(color.color("hsla(9e-1,3e-1%,5e-1%,5e-1)"), 0.9, 0.003, 0.005, 0.5);
test.rgbEqual(color.color("rgb(1e-1%,2e-1%,3e-1%)"), 0, 1, 1, 1);
test.rgbEqual(color.color("rgba(120,30,50,1e-1)"), 120, 30, 50, 0.1);
test.end();
});
tape("color(format) does not allow decimals for integer values", function(test) {
test.equal(color.color("rgb(120.5,30,50)"), null);
test.end();
});
tape("color(format) does not allow empty decimals", function(test) {
test.equal(color.color("rgb(120.,30,50)"), null);
test.equal(color.color("rgb(120.%,30%,50%)"), null);
test.equal(color.color("rgba(120,30,50,1.)"), null);
test.equal(color.color("rgba(12%,30%,50%,1.)"), null);
test.equal(color.color("hsla(60,100%,20%,1.)"), null);
test.end();
});
tape("color(format) does not allow made-up names", function(test) {
test.equal(color.color("bostock"), null);
test.end();
});
tape("color(format) does not allow whitespace before open paren or percent sign", function(test) {
test.equal(color.color("rgb (120,30,50)"), null);
test.equal(color.color("rgb (12%,30%,50%)"), null);
test.equal(color.color("hsl (120,30%,50%)"), null);
test.equal(color.color("hsl(120,30 %,50%)"), null);
test.equal(color.color("rgba (120,30,50,1)"), null);
test.equal(color.color("rgba (12%,30%,50%,1)"), null);
test.equal(color.color("hsla (120,30%,50%,1)"), null);
test.end();
});
tape("color(format) is case-insensitive", function(test) {
test.rgbEqual(color.color("aLiCeBlUE"), 240, 248, 255, 1);
test.rgbEqual(color.color("transPARENT"), NaN, NaN, NaN, 0);
test.rgbEqual(color.color(" #aBc\t\n"), 170, 187, 204, 1);
test.rgbEqual(color.color(" #aaBBCC\t\n"), 170, 187, 204, 1);
test.rgbEqual(color.color(" rGB(120,30,50)\t\n"), 120, 30, 50, 1);
test.hslEqual(color.color(" HSl(120,30%,50%)\t\n"), 120, 0.3, 0.5, 1);
test.end();
});
tape("color(format) returns undefined RGB channel values for unknown formats", function(test) {
test.equal(color.color("invalid"), null);
test.equal(color.color("hasOwnProperty"), null);
test.equal(color.color("__proto__"), null);
test.equal(color.color("#ab"), null);
test.equal(color.color("#abcd"), null);
test.end();
});
d3-color-1.0.3/test/cubehelix-test.js 0000664 0000000 0000000 00000000503 13060566206 0017401 0 ustar 00root root 0000000 0000000 var tape = require("tape"),
color = require("../");
tape("cubehelix(…) returns an instance of cubehelix and color", function(test) {
var c = color.cubehelix("steelblue");
test.ok(c instanceof color.cubehelix);
test.ok(c instanceof color.color);
test.equal(c.constructor.name, "Cubehelix");
test.end();
});
d3-color-1.0.3/test/hcl-test.js 0000664 0000000 0000000 00000022705 13060566206 0016207 0 ustar 00root root 0000000 0000000 var tape = require("tape"),
color = require("../");
require("./hclEqual");
require("./rgbEqual");
tape("hcl(…) returns an instance of hcl and color", function(test) {
var c = color.hcl(120, 40, 50);
test.ok(c instanceof color.hcl);
test.ok(c instanceof color.color);
test.equal(c.constructor.name, "Hcl");
test.end();
});
tape("hcl(…) exposes h, c, and l channel values", function(test) {
test.hclEqual(color.hcl("#abc"), 257.7177616818892, 10.774886733325554, 75.10497524893663, 1);
test.end();
});
tape("hcl(…) returns defined hue and chroma, even for black and white", function(test) {
test.hclEqual(color.hcl("black"), 0, 0, 0, 1);
test.hclEqual(color.hcl("#000"), 0, 0, 0, 1);
test.hclEqual(color.hcl(color.lab("#000")), 0, 0, 0, 1);
test.hclEqual(color.hcl("white"), 158.19859051364818, 0.00001795054880958058, 100.00000386666655, 1);
test.hclEqual(color.hcl("#fff"), 158.19859051364818, 0.00001795054880958058, 100.00000386666655, 1);
test.hclEqual(color.hcl(color.lab("#fff")), 158.19859051364818, 0.00001795054880958058, 100.00000386666655, 1);
test.end();
});
tape("hcl.toString() converts to RGB and formats as hexadecimal", function(test) {
test.equal(color.hcl("#abcdef") + "", "rgb(171, 205, 239)");
test.equal(color.hcl("moccasin") + "", "rgb(255, 228, 181)");
test.equal(color.hcl("hsl(60, 100%, 20%)") + "", "rgb(102, 102, 0)");
test.equal(color.hcl("rgb(12, 34, 56)") + "", "rgb(12, 34, 56)");
test.equal(color.hcl(color.rgb(12, 34, 56)) + "", "rgb(12, 34, 56)");
test.equal(color.hcl(color.hsl(60, 1, 0.2)) + "", "rgb(102, 102, 0)");
test.end();
});
tape("hcl.toString() reflects h, c and l channel values", function(test) {
var c = color.hcl("#abc");
c.h += 10, c.c += 1, c.l -= 1;
test.equal(c + "", "rgb(170, 183, 204)");
test.end();
});
tape("hcl.toString() treats undefined opacity as 1", function(test) {
var c = color.hcl("#abc");
c.opacity = NaN;
test.equal(c + "", "rgb(170, 187, 204)");
test.end();
});
tape("hcl.toString() treats undefined channel values as 0", function(test) {
test.equal(color.hcl("invalid") + "", "rgb(0, 0, 0)");
test.equal(color.hcl("#000") + "", "rgb(0, 0, 0)");
test.equal(color.hcl("#ccc") + "", "rgb(204, 204, 204)");
test.equal(color.hcl("#fff") + "", "rgb(255, 255, 255)");
test.equal(color.hcl(NaN, 20, 40) + "", "rgb(94, 94, 94)"); // equivalent to hcl(*, *, 40)
test.equal(color.hcl(120, NaN, 40) + "", "rgb(94, 94, 94)");
test.equal(color.hcl(0, NaN, 40) + "", "rgb(94, 94, 94)");
test.equal(color.hcl(120, 50, NaN) + "", "rgb(0, 0, 0)"); // equivalent to hcl(*, *, 0)
test.equal(color.hcl(0, 50, NaN) + "", "rgb(0, 0, 0)");
test.equal(color.hcl(120, 0, NaN) + "", "rgb(0, 0, 0)");
test.end();
});
tape("hcl(h, c, l) does not wrap hue to [0,360)", function(test) {
test.hclEqual(color.hcl(-10, 40, 50), -10, 40, 50, 1);
test.hclEqual(color.hcl(0, 40, 50), 0, 40, 50, 1);
test.hclEqual(color.hcl(360, 40, 50), 360, 40, 50, 1);
test.hclEqual(color.hcl(370, 40, 50), 370, 40, 50, 1);
test.end();
});
tape("hcl(h, c, l) does not clamp l channel value", function(test) {
test.hclEqual(color.hcl(120, 20, -10), 120, 20, -10, 1);
test.hclEqual(color.hcl(120, 20, 0), 120, 20, 0, 1);
test.hclEqual(color.hcl(120, 20, 100), 120, 20, 100, 1);
test.hclEqual(color.hcl(120, 20, 110), 120, 20, 110, 1);
test.end();
});
tape("hcl(h, c, l, opacity) does not clamp opacity to [0,1]", function(test) {
test.hclEqual(color.hcl(120, 20, 100, -0.2), 120, 20, 100, -0.2);
test.hclEqual(color.hcl(120, 20, 110, 1.2), 120, 20, 110, 1.2);
test.end();
});
tape("hcl(h, c, l) coerces channel values to numbers", function(test) {
test.hclEqual(color.hcl("120", "40", "50"), 120, 40, 50, 1);
test.end();
});
tape("hcl(h, c, l, opacity) coerces opacity to number", function(test) {
test.hclEqual(color.hcl(120, 40, 50, "0.2"), 120, 40, 50, 0.2);
test.end();
});
tape("hcl(h, c, l) allows undefined channel values", function(test) {
test.hclEqual(color.hcl(undefined, NaN, "foo"), NaN, NaN, NaN, 1);
test.hclEqual(color.hcl(undefined, 40, 50), NaN, 40, 50, 1);
test.hclEqual(color.hcl(42, undefined, 50), 42, NaN, 50, 1);
test.hclEqual(color.hcl(42, 40, undefined), 42, 40, NaN, 1);
test.end();
});
tape("hcl(h, c, l, opacity) converts undefined opacity to 1", function(test) {
test.hclEqual(color.hcl(10, 20, 30, null), 10, 20, 30, 1);
test.hclEqual(color.hcl(10, 20, 30, undefined), 10, 20, 30, 1);
test.end();
});
tape("hcl(format) parses the specified format and converts to HCL", function(test) {
test.hclEqual(color.hcl("#abcdef"), 259.84214815790716, 20.768234621934273, 81.04386565274363, 1);
test.hclEqual(color.hcl("#abc"), 257.7177616818892, 10.774886733325554, 75.10497524893663, 1);
test.hclEqual(color.hcl("rgb(12, 34, 56)"), 270.41717207657933, 16.833655998102003, 12.65624852526134, 1);
test.hclEqual(color.hcl("rgb(12%, 34%, 56%)"), 274.03009307843763, 36.289366963489435, 36.040298589825746, 1);
test.hclEqual(color.hcl("rgba(12%, 34%, 56%, 0.4)"), 274.03009307843763, 36.289366963489435, 36.040298589825746, 0.4);
test.hclEqual(color.hcl("hsl(60,100%,20%)"), 102.85124420310271, 49.44871600399321, 41.73251953866431, 1);
test.hclEqual(color.hcl("hsla(60,100%,20%,0.4)"), 102.85124420310271, 49.44871600399321, 41.73251953866431, 0.4);
test.hclEqual(color.hcl("aliceblue"), 252.44447593419056, 4.4710949781436735, 97.17864982306108, 1);
test.end();
});
tape("hcl(format) returns undefined channel values for unknown formats", function(test) {
test.hclEqual(color.hcl("invalid"), NaN, NaN, NaN, NaN);
test.end();
});
tape("hcl(hcl) copies an HCL color", function(test) {
var c1 = color.hcl(120, 30, 50, 0.4),
c2 = color.hcl(c1);
test.hclEqual(c1, 120, 30, 50, 0.4);
c1.h = c1.c = c1.l = c1.opacity = 0;
test.hclEqual(c1, 0, 0, 0, 0);
test.hclEqual(c2, 120, 30, 50, 0.4);
test.end();
});
tape("hcl(lab) returns defined hue, even if a and b are non-zero", function(test) {
test.hclEqual(color.hcl(color.lab(0, 0, 0)), 0, 0, 0, 1);
test.hclEqual(color.hcl(color.lab(50, 0, 0)), 0, 0, 50, 1);
test.hclEqual(color.hcl(color.lab(100, 0, 0)), 0, 0, 100, 1);
test.hclEqual(color.hcl(color.lab(0, 10, 0)), 0, 10, 0, 1);
test.hclEqual(color.hcl(color.lab(50, 10, 0)), 0, 10, 50, 1);
test.hclEqual(color.hcl(color.lab(100, 10, 0)), 0, 10, 100, 1);
test.end();
});
tape("hcl(rgb) converts from RGB", function(test) {
test.hclEqual(color.hcl(color.rgb(255, 0, 0, 0.4)), 39.99901061253294, 104.55176567686985, 53.24079414130722, 0.4);
test.end();
});
tape("hcl(color) converts from another colorspace via color.rgb()", function(test) {
function TestColor() {}
TestColor.prototype = Object.create(color.color.prototype);
TestColor.prototype.rgb = function() { return color.rgb(12, 34, 56, 0.4); };
TestColor.prototype.toString = function() { throw new Error("should use rgb, not toString"); };
test.hclEqual(color.hcl(new TestColor), 270.41717207657933, 16.833655998102003, 12.65624852526134, 0.4);
test.end();
});
tape("hcl.brighter(k) returns a brighter color if k > 0", function(test) {
var c = color.hcl("rgba(165, 42, 42, 0.4)");
test.hclEqual(c.brighter(0.5), 31.577795955065785, 58.32679960239559, 46.52650524281069, 0.4);
test.hclEqual(c.brighter(1), 31.577795955065785, 58.32679960239559, 55.52650524281069, 0.4);
test.hclEqual(c.brighter(2), 31.577795955065785, 58.32679960239559, 73.52650524281069, 0.4);
test.end();
});
tape("hcl.brighter(k) returns a copy", function(test) {
var c1 = color.hcl("rgba(70, 130, 180, 0.4)"),
c2 = c1.brighter(1);
test.hclEqual(c1, 262.78126775909277, 32.44906314974561, 52.46551718768575, 0.4);
test.hclEqual(c2, 262.78126775909277, 32.44906314974561, 70.46551718768575, 0.4);
test.end();
});
tape("hcl.brighter() is equivalent to hcl.brighter(1)", function(test) {
var c1 = color.hcl("rgba(70, 130, 180, 0.4)"),
c2 = c1.brighter(),
c3 = c1.brighter(1);
test.hclEqual(c2, c3.h, c3.c, c3.l, 0.4);
test.end();
});
tape("hcl.brighter(k) is equivalent to hcl.darker(-k)", function(test) {
var c1 = color.hcl("rgba(70, 130, 180, 0.4)"),
c2 = c1.brighter(1.5),
c3 = c1.darker(-1.5);
test.hclEqual(c2, c3.h, c3.c, c3.l, 0.4);
test.end();
});
tape("hcl.darker(k) returns a darker color if k > 0", function(test) {
var c = color.hcl("rgba(165, 42, 42, 0.4)");
test.hclEqual(c.darker(0.5), 31.577795955065785, 58.32679960239559, 28.526505242810693, 0.4);
test.hclEqual(c.darker(1), 31.577795955065785, 58.32679960239559, 19.526505242810693, 0.4);
test.hclEqual(c.darker(2), 31.577795955065785, 58.32679960239559, 1.5265052428106927, 0.4);
test.end();
});
tape("hcl.darker(k) returns a copy", function(test) {
var c1 = color.hcl("rgba(70, 130, 180, 0.4)"),
c2 = c1.darker(1);
test.hclEqual(c1, 262.78126775909277, 32.44906314974561, 52.46551718768575, 0.4);
test.hclEqual(c2, 262.78126775909277, 32.44906314974561, 34.46551718768575, 0.4);
test.end();
});
tape("hcl.darker() is equivalent to hcl.darker(1)", function(test) {
var c1 = color.hcl("rgba(70, 130, 180, 0.4)"),
c2 = c1.darker(),
c3 = c1.darker(1);
test.hclEqual(c2, c3.h, c3.c, c3.l, 0.4);
test.end();
});
tape("hcl.darker(k) is equivalent to hcl.brighter(-k)", function(test) {
var c1 = color.hcl("rgba(70, 130, 180, 0.4)"),
c2 = c1.darker(1.5),
c3 = c1.brighter(-1.5);
test.hclEqual(c2, c3.h, c3.c, c3.l, 0.4);
test.end();
});
tape("hcl.rgb() converts to RGB", function(test) {
var c = color.hcl(120, 30, 50, 0.4);
test.rgbEqual(c.rgb(), 109, 125, 74, 0.4);
test.end();
});
d3-color-1.0.3/test/hclEqual.js 0000664 0000000 0000000 00000001411 13060566206 0016211 0 ustar 00root root 0000000 0000000 var tape = require("tape"),
color = require("../");
tape.Test.prototype.hclEqual = function(actual, h, c, l, opacity) {
this._assert(actual instanceof color.hcl
&& (isNaN(h) ? isNaN(actual.h) && actual.h !== actual.h : h - 1e-6 <= actual.h && actual.h <= h + 1e-6)
&& (isNaN(c) ? isNaN(actual.c) && actual.c !== actual.c : c - 1e-6 <= actual.c && actual.c <= c + 1e-6)
&& (isNaN(l) ? isNaN(actual.l) && actual.l !== actual.l : l - 1e-6 <= actual.l && actual.l <= l + 1e-6)
&& (isNaN(opacity) ? isNaN(actual.opacity) && actual.opacity !== actual.opacity : actual.opacity === opacity), {
message: "should be equal",
operator: "hclEqual",
actual: [actual.h, actual.c, actual.l, actual.opacity],
expected: [h, c, l, opacity]
});
};
d3-color-1.0.3/test/hsl-test.js 0000664 0000000 0000000 00000026437 13060566206 0016235 0 ustar 00root root 0000000 0000000 var tape = require("tape"),
color = require("../");
require("./hslEqual");
require("./rgbEqual");
tape("hsl(…) returns an instance of hsl and color", function(test) {
var c = color.hsl(120, 0.4, 0.5);
test.ok(c instanceof color.hsl);
test.ok(c instanceof color.color);
test.equal(c.constructor.name, "Hsl");
test.end();
});
tape("hsl(…) exposes h, s, and l channel values and opacity", function(test) {
test.hslEqual(color.hsl("#abc"), 210, 0.25, 0.7333333, 1);
test.hslEqual(color.hsl("hsla(60, 100%, 20%, 0.4)"), 60, 1, 0.2, 0.4);
test.end();
});
tape("hsl.toString() converts to RGB and formats as rgb(…) or rgba(…)", function(test) {
test.equal(color.hsl("#abcdef") + "", "rgb(171, 205, 239)");
test.equal(color.hsl("moccasin") + "", "rgb(255, 228, 181)");
test.equal(color.hsl("hsl(60, 100%, 20%)") + "", "rgb(102, 102, 0)");
test.equal(color.hsl("hsla(60, 100%, 20%, 0.4)") + "", "rgba(102, 102, 0, 0.4)");
test.equal(color.hsl("rgb(12, 34, 56)") + "", "rgb(12, 34, 56)");
test.equal(color.hsl(color.rgb(12, 34, 56)) + "", "rgb(12, 34, 56)");
test.equal(color.hsl(color.hsl(60, 1, 0.2)) + "", "rgb(102, 102, 0)");
test.equal(color.hsl(color.hsl(60, 1, 0.2, 0.4)) + "", "rgba(102, 102, 0, 0.4)");
test.end();
});
tape("hsl.toString() reflects h, s and l channel values and opacity", function(test) {
var c = color.hsl("#abc");
c.h += 10, c.s += 0.01, c.l -= 0.01, c.opacity = 0.4;
test.equal(c + "", "rgba(166, 178, 203, 0.4)");
test.end();
});
tape("hsl.toString() treats undefined channel values as 0", function(test) {
test.equal(color.hsl("invalid") + "", "rgb(0, 0, 0)");
test.equal(color.hsl("#000") + "", "rgb(0, 0, 0)");
test.equal(color.hsl("#ccc") + "", "rgb(204, 204, 204)");
test.equal(color.hsl("#fff") + "", "rgb(255, 255, 255)");
test.equal(color.hsl(NaN, 0.5, 0.4) + "", "rgb(102, 102, 102)"); // equivalent to hsl(*, 0, 0.4)
test.equal(color.hsl(120, NaN, 0.4) + "", "rgb(102, 102, 102)");
test.equal(color.hsl(NaN, NaN, 0.4) + "", "rgb(102, 102, 102)");
test.equal(color.hsl(120, 0.5, NaN) + "", "rgb(0, 0, 0)"); // equivalent to hsl(120, 0.5, 0)
test.end();
});
tape("hsl.toString() treats undefined opacity as 1", function(test) {
var c = color.hsl("#abc");
c.opacity = NaN;
test.equal(c + "", "rgb(170, 187, 204)");
test.end();
});
tape("hsl(h, s, l) does not wrap hue to [0,360)", function(test) {
test.hslEqual(color.hsl(-10, 0.4, 0.5), -10, 0.4, 0.5, 1);
test.hslEqual(color.hsl(0, 0.4, 0.5), 0, 0.4, 0.5, 1);
test.hslEqual(color.hsl(360, 0.4, 0.5), 360, 0.4, 0.5, 1);
test.hslEqual(color.hsl(370, 0.4, 0.5), 370, 0.4, 0.5, 1);
test.end();
});
tape("hsl(h, s, l) does not clamp s and l channel values to [0,1]", function(test) {
test.hslEqual(color.hsl(120, -0.1, 0.5), 120, -0.1, 0.5, 1);
test.hslEqual(color.hsl(120, 1.1, 0.5), 120, 1.1, 0.5, 1);
test.hslEqual(color.hsl(120, 0.2, -0.1), 120, 0.2, -0.1, 1);
test.hslEqual(color.hsl(120, 0.2, 1.1), 120, 0.2, 1.1, 1);
test.end();
});
tape("hsl(h, s, l, opacity) does not clamp opacity to [0,1]", function(test) {
test.hslEqual(color.hsl(120, 0.1, 0.5, -0.2), 120, 0.1, 0.5, -0.2);
test.hslEqual(color.hsl(120, 0.9, 0.5, 1.2), 120, 0.9, 0.5, 1.2);
test.end();
});
tape("hsl(h, s, l) coerces channel values to numbers", function(test) {
test.hslEqual(color.hsl("120", ".4", ".5"), 120, 0.4, 0.5, 1);
test.end();
});
tape("hsl(h, s, l, opacity) coerces opacity to number", function(test) {
test.hslEqual(color.hsl(120, 0.1, 0.5, "0.2"), 120, 0.1, 0.5, 0.2);
test.hslEqual(color.hsl(120, 0.9, 0.5, "0.9"), 120, 0.9, 0.5, 0.9);
test.end();
});
tape("hsl(h, s, l) allows undefined channel values", function(test) {
test.hslEqual(color.hsl(undefined, NaN, "foo"), NaN, NaN, NaN, 1);
test.hslEqual(color.hsl(undefined, 0.4, 0.5), NaN, 0.4, 0.5, 1);
test.hslEqual(color.hsl(42, undefined, 0.5), 42, NaN, 0.5, 1);
test.hslEqual(color.hsl(42, 0.4, undefined), 42, 0.4, NaN, 1);
test.end();
});
tape("hsl(h, s, l, opacity) converts undefined opacity to 1", function(test) {
test.hslEqual(color.hsl(10, 0.2, 0.3, null), 10, 0.2, 0.3, 1);
test.hslEqual(color.hsl(10, 0.2, 0.3, undefined), 10, 0.2, 0.3, 1);
test.end();
});
tape("hsl(h, s, l) preserves explicit hue, even for grays", function(test) {
test.hslEqual(color.hsl(0, 0, 0), 0, 0, 0, 1);
test.hslEqual(color.hsl(42, 0, 0.5), 42, 0, 0.5, 1);
test.hslEqual(color.hsl(118, 0, 1), 118, 0, 1, 1);
test.end();
});
tape("hsl(h, s, l) preserves explicit saturation, even for white or black", function(test) {
test.hslEqual(color.hsl(0, 0, 0), 0, 0, 0, 1);
test.hslEqual(color.hsl(0, 0.18, 0), 0, 0.18, 0, 1);
test.hslEqual(color.hsl(0, 0.42, 1), 0, 0.42, 1, 1);
test.hslEqual(color.hsl(0, 1, 1), 0, 1, 1, 1);
test.end();
});
tape("hsl(format) parses the specified format and converts to HSL", function(test) {
test.hslEqual(color.hsl("#abcdef"), 210, 0.68, 0.8039215, 1);
test.hslEqual(color.hsl("#abc"), 210, 0.25, 0.733333333, 1);
test.hslEqual(color.hsl("rgb(12, 34, 56)"), 210, 0.647058, 0.1333333, 1);
test.hslEqual(color.hsl("rgb(12%, 34%, 56%)"), 210, 0.647058, 0.34, 1);
test.hslEqual(color.hsl("hsl(60,100%,20%)"), 60, 1, 0.2, 1);
test.hslEqual(color.hsl("hsla(60,100%,20%,0.4)"), 60, 1, 0.2, 0.4);
test.hslEqual(color.hsl("aliceblue"), 208, 1, 0.9705882, 1);
test.hslEqual(color.hsl("transparent"), NaN, NaN, NaN, 0);
test.end();
});
tape("hsl(format) ignores the hue if the saturation is <= 0", function(test) {
test.hslEqual(color.hsl("hsl(120,0%,20%)"), NaN, 0, 0.2, 1);
test.hslEqual(color.hsl("hsl(120,-10%,20%)"), NaN, -0.1, 0.2, 1);
test.end();
});
tape("hsl(format) ignores the hue and saturation if the lightness is <= 0 or >= 1", function(test) {
test.hslEqual(color.hsl("hsl(120,20%,-10%)"), NaN, NaN, -0.1, 1);
test.hslEqual(color.hsl("hsl(120,20%,0%)"), NaN, NaN, 0.0, 1);
test.hslEqual(color.hsl("hsl(120,20%,100%)"), NaN, NaN, 1.0, 1);
test.hslEqual(color.hsl("hsl(120,20%,120%)"), NaN, NaN, 1.2, 1);
test.end();
});
tape("hsl(format) ignores all channels if the alpha is <= 0", function(test) {
test.hslEqual(color.hsl("hsla(120,20%,10%,0)"), NaN, NaN, NaN, 0);
test.hslEqual(color.hsl("hsla(120,20%,10%,-0.1)"), NaN, NaN, NaN, -0.1);
test.end();
});
tape("hsl(format) does not lose precision when parsing HSL formats", function(test) {
test.hslEqual(color.hsl("hsl(325,50%,40%)"), 325, 0.5, 0.4, 1);
test.end();
});
tape("hsl(format) returns undefined channel values for unknown formats", function(test) {
test.hslEqual(color.hsl("invalid"), NaN, NaN, NaN, NaN);
test.end();
});
tape("hsl(hsl) copies an HSL color", function(test) {
var c1 = color.hsl("hsla(120,30%,50%,0.4)"),
c2 = color.hsl(c1);
test.hslEqual(c1, 120, 0.3, 0.5, 0.4);
c1.h = c1.s = c1.l = c1.opacity = 0;
test.hslEqual(c1, 0, 0, 0, 0);
test.hslEqual(c2, 120, 0.3, 0.5, 0.4);
test.end();
});
tape("hsl(rgb) converts from RGB", function(test) {
test.hslEqual(color.hsl(color.rgb(255, 0, 0, 0.4)), 0, 1, 0.5, 0.4);
test.end();
});
tape("hsl(color) returns undefined hue and zero saturation for grays (but not white and black)", function(test) {
test.hslEqual(color.hsl("gray"), NaN, 0, 0.5019608, 1);
test.hslEqual(color.hsl("#ccc"), NaN, 0, 0.8, 1);
test.hslEqual(color.hsl(color.rgb("gray")), NaN, 0, 0.5019608, 1);
test.end();
});
tape("hsl(color) returns undefined hue and saturation for black and white", function(test) {
test.hslEqual(color.hsl("black"), NaN, NaN, 0, 1);
test.hslEqual(color.hsl("#000"), NaN, NaN, 0, 1);
test.hslEqual(color.hsl("white"), NaN, NaN, 1, 1);
test.hslEqual(color.hsl("#fff"), NaN, NaN, 1, 1);
test.hslEqual(color.hsl(color.rgb("#fff")), NaN, NaN, 1, 1);
test.end();
});
tape("hsl(color) converts from another colorspace via color.rgb()", function(test) {
function TestColor() {}
TestColor.prototype = Object.create(color.color.prototype);
TestColor.prototype.rgb = function() { return color.rgb(12, 34, 56, 0.4); };
TestColor.prototype.toString = function() { throw new Error("should use rgb, not toString"); };
test.hslEqual(color.hsl(new TestColor), 210, 0.6470588, 0.1333334, 0.4);
test.end();
});
tape("hsl.displayable() returns true if the color is within the RGB gamut and the opacity is in [0,1]", function(test) {
test.equal(color.hsl("white").displayable(), true);
test.equal(color.hsl("red").displayable(), true);
test.equal(color.hsl("black").displayable(), true);
test.equal(color.hsl("invalid").displayable(), false);
test.equal(color.hsl(NaN, NaN, 1).displayable(), true);
test.equal(color.hsl(NaN, NaN, 1.5).displayable(), false);
test.equal(color.hsl(120, -0.5, 0).displayable(), false);
test.equal(color.hsl(120, 1.5, 0).displayable(), false);
test.equal(color.hsl(0, 1, 1, 0).displayable(), true);
test.equal(color.hsl(0, 1, 1, 1).displayable(), true);
test.equal(color.hsl(0, 1, 1, -0.2).displayable(), false);
test.equal(color.hsl(0, 1, 1, 1.2).displayable(), false);
test.end();
});
tape("hsl.brighter(k) returns a brighter color if k > 0", function(test) {
var c = color.hsl("rgba(165, 42, 42, 0.4)");
test.hslEqual(c.brighter(0.5), 0, 0.5942028, 0.4851222, 0.4);
test.hslEqual(c.brighter(1), 0, 0.5942028, 0.5798319, 0.4);
test.hslEqual(c.brighter(2), 0, 0.5942028, 0.8283313, 0.4);
test.end();
});
tape("hsl.brighter(k) returns a copy", function(test) {
var c1 = color.hsl("rgba(70, 130, 180, 0.4)"),
c2 = c1.brighter(1);
test.hslEqual(c1, 207.272727, 0.44, 0.4901961, 0.4);
test.hslEqual(c2, 207.272727, 0.44, 0.7002801, 0.4);
test.end();
});
tape("hsl.brighter() is equivalent to hsl.brighter(1)", function(test) {
var c1 = color.hsl("rgba(70, 130, 180, 0.4)"),
c2 = c1.brighter(),
c3 = c1.brighter(1);
test.hslEqual(c2, c3.h, c3.s, c3.l, 0.4);
test.end();
});
tape("hsl.brighter(k) is equivalent to hsl.darker(-k)", function(test) {
var c1 = color.hsl("rgba(70, 130, 180, 0.4)"),
c2 = c1.brighter(1.5),
c3 = c1.darker(-1.5);
test.hslEqual(c2, c3.h, c3.s, c3.l, 0.4);
test.end();
});
tape("hsl(\"black\").brighter() still returns black", function(test) {
var c1 = color.hsl("black"),
c2 = c1.brighter(1);
test.hslEqual(c1, NaN, NaN, 0, 1);
test.hslEqual(c2, NaN, NaN, 0, 1);
test.end();
});
tape("hsl.darker(k) returns a darker color if k > 0", function(test) {
var c = color.hsl("rgba(165, 42, 42, 0.4)");
test.hslEqual(c.darker(0.5), 0, 0.5942029, 0.3395855, 0.4);
test.hslEqual(c.darker(1), 0, 0.5942029, 0.2841176, 0.4);
test.hslEqual(c.darker(2), 0, 0.5942029, 0.1988823, 0.4);
test.end();
});
tape("hsl.darker(k) returns a copy", function(test) {
var c1 = color.hsl("rgba(70, 130, 180, 0.4)"),
c2 = c1.darker(1);
test.hslEqual(c1, 207.272727, 0.44, 0.4901961, 0.4);
test.hslEqual(c2, 207.272727, 0.44, 0.3431373, 0.4);
test.end();
});
tape("hsl.darker() is equivalent to hsl.darker(1)", function(test) {
var c1 = color.hsl("rgba(70, 130, 180, 0.4)"),
c2 = c1.darker(),
c3 = c1.darker(1);
test.hslEqual(c2, c3.h, c3.s, c3.l, 0.4);
test.end();
});
tape("hsl.darker(k) is equivalent to hsl.brighter(-k)", function(test) {
var c1 = color.hsl("rgba(70, 130, 180, 0.4)"),
c2 = c1.darker(1.5),
c3 = c1.brighter(-1.5);
test.hslEqual(c2, c3.h, c3.s, c3.l, 0.4);
test.end();
});
tape("hsl.rgb() converts to RGB", function(test) {
var c = color.hsl(120, 0.3, 0.5, 0.4);
test.rgbEqual(c.rgb(), 89, 166, 89, 0.4);
test.end();
});
d3-color-1.0.3/test/hslEqual.js 0000664 0000000 0000000 00000001411 13060566206 0016231 0 ustar 00root root 0000000 0000000 var tape = require("tape"),
color = require("../");
tape.Test.prototype.hslEqual = function(actual, h, s, l, opacity) {
this._assert(actual instanceof color.hsl
&& (isNaN(h) ? isNaN(actual.h) && actual.h !== actual.h : h - 1e-6 <= actual.h && actual.h <= h + 1e-6)
&& (isNaN(s) ? isNaN(actual.s) && actual.s !== actual.s : s - 1e-6 <= actual.s && actual.s <= s + 1e-6)
&& (isNaN(l) ? isNaN(actual.l) && actual.l !== actual.l : l - 1e-6 <= actual.l && actual.l <= l + 1e-6)
&& (isNaN(opacity) ? isNaN(actual.opacity) && actual.opacity !== actual.opacity : actual.opacity === opacity), {
message: "should be equal",
operator: "hslEqual",
actual: [actual.h, actual.s, actual.l, actual.opacity],
expected: [h, s, l, opacity]
});
};
d3-color-1.0.3/test/lab-test.js 0000664 0000000 0000000 00000020176 13060566206 0016177 0 ustar 00root root 0000000 0000000 var tape = require("tape"),
color = require("../");
require("./labEqual");
require("./rgbEqual");
tape("lab(…) returns an instance of lab and color", function(test) {
var c = color.lab(120, 40, 50);
test.ok(c instanceof color.lab);
test.ok(c instanceof color.color);
test.equal(c.constructor.name, "Lab");
test.end();
});
tape("lab(…) exposes l, a and b channel values and opacity", function(test) {
test.labEqual(color.lab("rgba(170, 187, 204, 0.4)"), 75.104975, -2.292115, -10.528266, 0.4);
test.end();
});
tape("lab.toString() converts to RGB and formats as rgb(…) or rgba(…)", function(test) {
test.equal(color.lab("#abcdef") + "", "rgb(171, 205, 239)");
test.equal(color.lab("moccasin") + "", "rgb(255, 228, 181)");
test.equal(color.lab("hsl(60, 100%, 20%)") + "", "rgb(102, 102, 0)");
test.equal(color.lab("hsla(60, 100%, 20%, 0.4)") + "", "rgba(102, 102, 0, 0.4)");
test.equal(color.lab("rgb(12, 34, 56)") + "", "rgb(12, 34, 56)");
test.equal(color.lab(color.rgb(12, 34, 56)) + "", "rgb(12, 34, 56)");
test.equal(color.lab(color.hsl(60, 1, 0.2)) + "", "rgb(102, 102, 0)");
test.equal(color.lab(color.hsl(60, 1, 0.2, 0.4)) + "", "rgba(102, 102, 0, 0.4)");
test.end();
});
tape("lab.toString() reflects l, a and b channel values and opacity", function(test) {
var c = color.lab("#abc");
c.l += 10, c.a -= 10, c.b += 10, c.opacity = 0.4;
test.equal(c + "", "rgba(186, 220, 213, 0.4)");
test.end();
});
tape("lab.toString() treats undefined channel values as 0", function(test) {
test.equal(color.lab("invalid") + "", "rgb(0, 0, 0)");
test.equal(color.lab(NaN, 0, 0) + "", "rgb(0, 0, 0)");
test.equal(color.lab(50, NaN, 0) + "", "rgb(119, 119, 119)");
test.equal(color.lab(50, 0, NaN) + "", "rgb(119, 119, 119)");
test.equal(color.lab(50, NaN, NaN) + "", "rgb(119, 119, 119)");
test.end();
});
tape("lab.toString() treats undefined opacity as 1", function(test) {
var c = color.lab("#abc");
c.opacity = NaN;
test.equal(c + "", "rgb(170, 187, 204)");
test.end();
});
tape("lab(l, a, b) does not clamp l channel value", function(test) {
test.labEqual(color.lab(-10, 1, 2), -10, 1, 2, 1);
test.labEqual(color.lab(0, 1, 2), 0, 1, 2, 1);
test.labEqual(color.lab(100, 1, 2), 100, 1, 2, 1);
test.labEqual(color.lab(110, 1, 2), 110, 1, 2, 1);
test.end();
});
tape("lab(l, a, b, opacity) does not clamp opacity to [0,1]", function(test) {
test.labEqual(color.lab(50, 10, 20, -0.2), 50, 10, 20, -0.2);
test.labEqual(color.lab(50, 10, 20, 1.2), 50, 10, 20, 1.2);
test.end();
});
tape("lab(l, a, b) coerces channel values to numbers", function(test) {
test.labEqual(color.lab("50", "4", "-5"), 50, 4, -5, 1);
test.end();
});
tape("lab(l, a, b, opacity) coerces opacity to number", function(test) {
test.labEqual(color.lab(50, 4, -5, "0.2"), 50, 4, -5, 0.2);
test.end();
});
tape("lab(l, a, b) allows undefined channel values", function(test) {
test.labEqual(color.lab(undefined, NaN, "foo"), NaN, NaN, NaN, 1);
test.labEqual(color.lab(undefined, 4, -5), NaN, 4, -5, 1);
test.labEqual(color.lab(42, undefined, -5), 42, NaN, -5, 1);
test.labEqual(color.lab(42, 4, undefined), 42, 4, NaN, 1);
test.end();
});
tape("lab(l, a, b, opacity) converts undefined opacity to 1", function(test) {
test.labEqual(color.lab(10, 20, 30, null), 10, 20, 30, 1);
test.labEqual(color.lab(10, 20, 30, undefined), 10, 20, 30, 1);
test.end();
});
tape("lab(format) parses the specified format and converts to Lab", function(test) {
test.labEqual(color.lab("#abcdef"), 81.04386565274363, -3.6627002800885267, -20.442705201854984, 1);
test.labEqual(color.lab("#abc"), 75.10497524893663, -2.292114632248876, -10.528266458853786, 1);
test.labEqual(color.lab("rgb(12, 34, 56)"), 12.65624852526134, 0.12256520883417721, -16.833209795877284, 1);
test.labEqual(color.lab("rgb(12%, 34%, 56%)"), 36.040298589825746, 2.5504315155944477, -36.19963333647264, 1);
test.labEqual(color.lab("rgba(12%, 34%, 56%, 0.4)"), 36.040298589825746, 2.5504315155944477, -36.19963333647264, 0.4);
test.labEqual(color.lab("hsl(60,100%,20%)"), 41.73251953866431, -10.998411255098816, 48.21006600604577, 1);
test.labEqual(color.lab("hsla(60,100%,20%,0.4)"), 41.73251953866431, -10.998411255098816, 48.21006600604577, 0.4);
test.labEqual(color.lab("aliceblue"), 97.17864982306108, -1.3486158598345344, -4.262854157273543, 1);
test.end();
});
tape("lab(format) returns undefined channel values for unknown formats", function(test) {
test.labEqual(color.lab("invalid"), NaN, NaN, NaN, NaN);
test.end();
});
tape("lab(lab) copies a Lab color", function(test) {
var c1 = color.lab(50, 4, -5, 0.4),
c2 = color.lab(c1);
test.labEqual(c1, 50, 4, -5, 0.4);
c1.l = c1.a = c1.b = c1.opacity = 0;
test.labEqual(c1, 0, 0, 0, 0);
test.labEqual(c2, 50, 4, -5, 0.4);
test.end();
});
tape("lab(hcl(lab)) doesn’t lose a and b channels if luminance is zero", function(test) {
test.labEqual(color.lab(color.hcl(color.lab(0, 10, 0))), 0, 10, 0, 1);
test.end();
});
tape("lab(rgb) converts from RGB", function(test) {
test.labEqual(color.lab(color.rgb(255, 0, 0, 0.4)), 53.24079414130722, 80.09245959641109, 67.20319651585301, 0.4);
test.end();
});
tape("lab(color) converts from another colorspace via color.rgb()", function(test) {
function TestColor() {}
TestColor.prototype = Object.create(color.color.prototype);
TestColor.prototype.rgb = function() { return color.rgb(12, 34, 56, 0.4); };
TestColor.prototype.toString = function() { throw new Error("should use rgb, not toString"); };
test.labEqual(color.lab(new TestColor), 12.65624852526134, 0.12256520883417721, -16.833209795877284, 0.4);
test.end();
});
tape("lab.brighter(k) returns a brighter color if k > 0", function(test) {
var c = color.lab("rgba(165, 42, 42, 0.4)");
test.labEqual(c.brighter(0.5), 46.52650524281069, 49.69034644081097, 30.543166542619616, 0.4);
test.labEqual(c.brighter(1), 55.52650524281069, 49.69034644081097, 30.543166542619616, 0.4);
test.labEqual(c.brighter(2), 73.52650524281069, 49.69034644081097, 30.543166542619616, 0.4);
test.end();
});
tape("lab.brighter(k) returns a copy", function(test) {
var c1 = color.lab("rgba(70, 130, 180, 0.4)"),
c2 = c1.brighter(1);
test.labEqual(c1, 52.46551718768575, -4.0774710123572255, -32.19186122981343, 0.4);
test.labEqual(c2, 70.46551718768575, -4.0774710123572255, -32.19186122981343, 0.4);
test.end();
});
tape("lab.brighter() is equivalent to lab.brighter(1)", function(test) {
var c1 = color.lab("rgba(70, 130, 180, 0.4)"),
c2 = c1.brighter(),
c3 = c1.brighter(1);
test.labEqual(c2, c3.l, c3.a, c3.b, 0.4);
test.end();
});
tape("lab.brighter(k) is equivalent to lab.darker(-k)", function(test) {
var c1 = color.lab("rgba(70, 130, 180, 0.4)"),
c2 = c1.brighter(1.5),
c3 = c1.darker(-1.5);
test.labEqual(c2, c3.l, c3.a, c3.b, 0.4);
test.end();
});
tape("lab.darker(k) returns a darker color if k > 0", function(test) {
var c = color.lab("rgba(165, 42, 42, 0.4)");
test.labEqual(c.darker(0.5), 28.526505242810693, 49.69034644081097, 30.543166542619616, 0.4);
test.labEqual(c.darker(1), 19.526505242810693, 49.69034644081097, 30.543166542619616, 0.4);
test.labEqual(c.darker(2), 1.5265052428106927, 49.69034644081097, 30.543166542619616, 0.4);
test.end();
});
tape("lab.darker(k) returns a copy", function(test) {
var c1 = color.lab("rgba(70, 130, 180, 0.4)"),
c2 = c1.darker(1);
test.labEqual(c1, 52.46551718768575, -4.0774710123572255, -32.19186122981343, 0.4);
test.labEqual(c2, 34.46551718768575, -4.0774710123572255, -32.19186122981343, 0.4);
test.end();
});
tape("lab.darker() is equivalent to lab.darker(1)", function(test) {
var c1 = color.lab("rgba(70, 130, 180, 0.4)"),
c2 = c1.darker(),
c3 = c1.darker(1);
test.labEqual(c2, c3.l, c3.a, c3.b, 0.4);
test.end();
});
tape("lab.darker(k) is equivalent to lab.brighter(-k)", function(test) {
var c1 = color.lab("rgba(70, 130, 180, 0.4)"),
c2 = c1.darker(1.5),
c3 = c1.brighter(-1.5);
test.labEqual(c2, c3.l, c3.a, c3.b, 0.4);
test.end();
});
tape("lab.rgb() converts to RGB", function(test) {
var c = color.lab(50, 4, -5, 0.4);
test.rgbEqual(c.rgb(), 122, 117, 127, 0.4);
test.end();
});
d3-color-1.0.3/test/labEqual.js 0000664 0000000 0000000 00000001411 13060566206 0016201 0 ustar 00root root 0000000 0000000 var tape = require("tape"),
color = require("../");
tape.Test.prototype.labEqual = function(actual, l, a, b, opacity) {
this._assert(actual instanceof color.lab
&& (isNaN(l) ? isNaN(actual.l) && actual.l !== actual.l : l - 1e-6 <= actual.l && actual.l <= l + 1e-6)
&& (isNaN(a) ? isNaN(actual.a) && actual.a !== actual.a : a - 1e-6 <= actual.a && actual.a <= a + 1e-6)
&& (isNaN(b) ? isNaN(actual.b) && actual.b !== actual.b : b - 1e-6 <= actual.b && actual.b <= b + 1e-6)
&& (isNaN(opacity) ? isNaN(actual.opacity) && actual.opacity !== actual.opacity : actual.opacity === opacity), {
message: "should be equal",
operator: "labEqual",
actual: [actual.l, actual.a, actual.b, actual.opacity],
expected: [l, a, b, opacity]
});
};
d3-color-1.0.3/test/rgb-test.js 0000664 0000000 0000000 00000022150 13060566206 0016205 0 ustar 00root root 0000000 0000000 var tape = require("tape"),
color = require("../");
require("./rgbEqual");
tape("rgb(…) returns an instance of rgb and color", function(test) {
var c = color.rgb(70, 130, 180);
test.ok(c instanceof color.rgb);
test.ok(c instanceof color.color);
test.equal(c.constructor.name, "Rgb");
test.end();
});
tape("rgb(…) exposes r, g and b channel values and opacity", function(test) {
test.rgbEqual(color.rgb("#abc"), 170, 187, 204, 1);
test.rgbEqual(color.rgb("rgba(170, 187, 204, 0.4)"), 170, 187, 204, 0.4);
test.end();
});
tape("rgb.toString() formats as rgb(…) or rgba(…)", function(test) {
test.equal(color.rgb("#abcdef") + "", "rgb(171, 205, 239)");
test.equal(color.rgb("moccasin") + "", "rgb(255, 228, 181)");
test.equal(color.rgb("hsl(60, 100%, 20%)") + "", "rgb(102, 102, 0)");
test.equal(color.rgb("rgb(12, 34, 56)") + "", "rgb(12, 34, 56)");
test.equal(color.rgb(color.rgb(12, 34, 56)) + "", "rgb(12, 34, 56)");
test.equal(color.rgb(color.hsl(60, 1, 0.2)) + "", "rgb(102, 102, 0)");
test.equal(color.rgb("rgba(12, 34, 56, 0.4)") + "", "rgba(12, 34, 56, 0.4)");
test.equal(color.rgb("rgba(12%, 34%, 56%, 0.4)") + "", "rgba(31, 87, 143, 0.4)");
test.equal(color.rgb("hsla(60, 100%, 20%, 0.4)") + "", "rgba(102, 102, 0, 0.4)");
test.end();
});
tape("rgb.toString() reflects r, g and b channel values and opacity", function(test) {
var c = color.rgb("#abc");
++c.r, ++c.g, ++c.b, c.opacity = 0.5;
test.equal(c + "", "rgba(171, 188, 205, 0.5)");
test.end();
});
tape("rgb.toString() treats undefined channel values as 0", function(test) {
test.equal(color.rgb("invalid") + "", "rgb(0, 0, 0)");
test.equal(color.rgb(NaN, 12, 34) + "", "rgb(0, 12, 34)");
test.end();
});
tape("rgb.toString() treats undefined opacity as 1", function(test) {
var c = color.rgb("#abc");
++c.r, ++c.g, ++c.b, c.opacity = NaN;
test.equal(c + "", "rgb(171, 188, 205)");
test.end();
});
tape("rgb.toString() clamps r, g, b and opacity channel values", function(test) {
test.equal(color.rgb(-1, 2, 3) + "", "rgb(0, 2, 3)");
test.equal(color.rgb( 2, -1, 3) + "", "rgb(2, 0, 3)");
test.equal(color.rgb( 2, 3, -1) + "", "rgb(2, 3, 0)");
test.equal(color.rgb( 2, 3, -1, -0.2) + "", "rgba(2, 3, 0, 0)");
test.equal(color.rgb( 2, 3, -1, 1.2) + "", "rgb(2, 3, 0)");
test.end();
});
tape("rgb.toString() rounds r, g and b channel values", function(test) {
test.equal(color.rgb(0.5, 2.0, 3.0) + "", "rgb(1, 2, 3)");
test.equal(color.rgb(2.0, 0.5, 3.0) + "", "rgb(2, 1, 3)");
test.equal(color.rgb(2.0, 3.0, 0.5) + "", "rgb(2, 3, 1)");
test.end();
});
tape("rgb(r, g, b) does not round channel values", function(test) {
test.rgbStrictEqual(color.rgb(1.2, 2.6, 42.9), 1.2, 2.6, 42.9, 1);
test.end();
});
tape("rgb(r, g, b) does not clamp channel values", function(test) {
test.rgbEqual(color.rgb(-10, -20, -30), -10, -20, -30, 1);
test.rgbEqual(color.rgb(300, 400, 500), 300, 400, 500, 1);
test.end();
});
tape("rgb(r, g, b, opacity) does not clamp opacity", function(test) {
test.rgbEqual(color.rgb(-10, -20, -30, -0.2), -10, -20, -30, -0.2);
test.rgbEqual(color.rgb(300, 400, 500, 1.2), 300, 400, 500, 1.2);
test.end();
});
tape("rgb(r, g, b) coerces channel values to numbers", function(test) {
test.rgbEqual(color.rgb("12", "34", "56"), 12, 34, 56, 1);
test.rgbEqual(color.rgb(null, null, null), 0, 0, 0, 1);
test.end();
});
tape("rgb(r, g, b, opacity) coerces opacity to number", function(test) {
test.rgbStrictEqual(color.rgb(-10, -20, -30, "-0.2"), -10, -20, -30, -0.2);
test.rgbStrictEqual(color.rgb(300, 400, 500, "1.2"), 300, 400, 500, 1.2);
test.end();
});
tape("rgb(r, g, b) allows undefined channel values", function(test) {
test.rgbEqual(color.rgb(undefined, NaN, "foo"), NaN, NaN, NaN, 1);
test.rgbEqual(color.rgb(undefined, 42, 56), NaN, 42, 56, 1);
test.rgbEqual(color.rgb(42, undefined, 56), 42, NaN, 56, 1);
test.rgbEqual(color.rgb(42, 56, undefined), 42, 56, NaN, 1);
test.end();
});
tape("rgb(r, g, b, opacity) converts undefined opacity to 1", function(test) {
test.rgbEqual(color.rgb(10, 20, 30, null), 10, 20, 30, 1);
test.rgbEqual(color.rgb(10, 20, 30, undefined), 10, 20, 30, 1);
test.end();
});
tape("rgb(format) parses the specified format and converts to RGB", function(test) {
test.rgbEqual(color.rgb("#abcdef"), 171, 205, 239, 1);
test.rgbEqual(color.rgb("#abc"), 170, 187, 204, 1);
test.rgbEqual(color.rgb("rgb(12, 34, 56)"), 12, 34, 56, 1);
test.rgbEqual(color.rgb("rgb(12%, 34%, 56%)"), 31, 87, 143, 1);
test.rgbEqual(color.rgb("hsl(60,100%,20%)"), 102, 102, 0, 1);
test.rgbEqual(color.rgb("aliceblue"), 240, 248, 255, 1);
test.rgbEqual(color.rgb("hsla(60,100%,20%,0.4)"), 102, 102, 0, 0.4);
test.end();
});
tape("rgb(format) ignores all channels if the alpha is <= 0", function(test) {
test.rgbEqual(color.rgb("rgba(12,34,45,0)"), NaN, NaN, NaN, 0);
test.rgbEqual(color.rgb("rgba(12,34,45,-0.1)"), NaN, NaN, NaN, -0.1);
test.end();
});
tape("rgb(format) returns undefined channel values for unknown formats", function(test) {
test.rgbEqual(color.rgb("invalid"), NaN, NaN, NaN, NaN);
test.end();
});
tape("rgb(rgb) copies an RGB color", function(test) {
var c1 = color.rgb("rgba(70, 130, 180, 0.4)"),
c2 = color.rgb(c1);
test.rgbEqual(c1, 70, 130, 180, 0.4);
c1.r = c1.g = c1.b = c1.opacity = 0;
test.rgbEqual(c1, 0, 0, 0, 0);
test.rgbEqual(c2, 70, 130, 180, 0.4);
test.end();
});
tape("rgb(hsl) converts from HSL", function(test) {
test.rgbEqual(color.rgb(color.hsl(0, 1, 0.5)), 255, 0, 0, 1);
test.rgbEqual(color.rgb(color.hsl(0, 1, 0.5, 0.4)), 255, 0, 0, 0.4);
test.end();
});
tape("rgb(color) converts from another colorspace via color.rgb()", function(test) {
function TestColor() {}
TestColor.prototype = Object.create(color.color.prototype);
TestColor.prototype.rgb = function() { return color.rgb(12, 34, 56, 0.4); };
TestColor.prototype.toString = function() { throw new Error("should use rgb, not toString"); };
test.rgbEqual(color.rgb(new TestColor), 12, 34, 56, 0.4);
test.end();
});
tape("rgb.displayable() returns true if the color is within the RGB gamut and opacity is in [0,1]", function(test) {
test.equal(color.rgb("white").displayable(), true);
test.equal(color.rgb("red").displayable(), true);
test.equal(color.rgb("black").displayable(), true);
test.equal(color.rgb("invalid").displayable(), false);
test.equal(color.rgb(-1, 0, 0).displayable(), false);
test.equal(color.rgb(0, -1, 0).displayable(), false);
test.equal(color.rgb(0, 0, -1).displayable(), false);
test.equal(color.rgb(256, 0, 0).displayable(), false);
test.equal(color.rgb(0, 256, 0).displayable(), false);
test.equal(color.rgb(0, 0, 256).displayable(), false);
test.equal(color.rgb(0, 0, 255, 0).displayable(), true);
test.equal(color.rgb(0, 0, 255, 1.2).displayable(), false);
test.equal(color.rgb(0, 0, 255, -0.2).displayable(), false);
test.end();
});
tape("rgb.brighter(k) returns a brighter color if k > 0", function(test) {
var c = color.rgb("rgba(165, 42, 42, 0.4)");
test.rgbEqual(c.brighter(0.5), 197, 50, 50, 0.4);
test.rgbEqual(c.brighter(1), 236, 60, 60, 0.4);
test.rgbEqual(c.brighter(2), 337, 86, 86, 0.4);
test.end();
});
tape("rgb.brighter(k) returns a copy", function(test) {
var c1 = color.rgb("rgba(70, 130, 180, 0.4)"),
c2 = c1.brighter(1);
test.rgbEqual(c1, 70, 130, 180, 0.4);
test.rgbEqual(c2, 100, 186, 257, 0.4);
test.end();
});
tape("rgb.brighter() is equivalent to rgb.brighter(1)", function(test) {
var c1 = color.rgb("rgba(70, 130, 180, 0.4)"),
c2 = c1.brighter(),
c3 = c1.brighter(1);
test.rgbEqual(c2, c3.r, c3.g, c3.b, 0.4);
test.end();
});
tape("rgb.brighter(k) is equivalent to rgb.darker(-k)", function(test) {
var c1 = color.rgb("rgba(70, 130, 180, 0.4)"),
c2 = c1.brighter(1.5),
c3 = c1.darker(-1.5);
test.rgbEqual(c2, c3.r, c3.g, c3.b, 0.4);
test.end();
});
tape("rgb(\"black\").brighter() still returns black", function(test) {
var c1 = color.rgb("black"),
c2 = c1.brighter(1);
test.rgbEqual(c1, 0, 0, 0, 1);
test.rgbEqual(c2, 0, 0, 0, 1);
test.end();
});
tape("rgb.darker(k) returns a darker color if k > 0", function(test) {
var c = color.rgb("rgba(165, 42, 42, 0.4)");
test.rgbEqual(c.darker(0.5), 138, 35, 35, 0.4);
test.rgbEqual(c.darker(1), 115, 29, 29, 0.4);
test.rgbEqual(c.darker(2), 81, 21, 21, 0.4);
test.end();
});
tape("rgb.darker(k) returns a copy", function(test) {
var c1 = color.rgb("rgba(70, 130, 180, 0.4)"),
c2 = c1.darker(1);
test.rgbEqual(c1, 70, 130, 180, 0.4);
test.rgbEqual(c2, 49, 91, 126, 0.4);
test.end();
});
tape("rgb.darker() is equivalent to rgb.darker(1)", function(test) {
var c1 = color.rgb("rgba(70, 130, 180, 0.4)"),
c2 = c1.darker(),
c3 = c1.darker(1);
test.rgbEqual(c2, c3.r, c3.g, c3.b, 0.4);
test.end();
});
tape("rgb.darker(k) is equivalent to rgb.brighter(-k)", function(test) {
var c1 = color.rgb("rgba(70, 130, 180, 0.4)"),
c2 = c1.darker(1.5),
c3 = c1.brighter(-1.5);
test.rgbEqual(c2, c3.r, c3.g, c3.b, 0.4);
test.end();
});
tape("rgb.rgb() returns this", function(test) {
var c = color.rgb(70, 130, 180);
test.equal(c.rgb(), c);
test.end();
});
d3-color-1.0.3/test/rgbEqual.js 0000664 0000000 0000000 00000002702 13060566206 0016221 0 ustar 00root root 0000000 0000000 var tape = require("tape"),
color = require("../");
tape.Test.prototype.rgbStrictEqual = function(actual, r, g, b, opacity) {
this._assert(actual instanceof color.rgb
&& (isNaN(r) ? isNaN(actual.r) && actual.r !== actual.r : actual.r === r)
&& (isNaN(g) ? isNaN(actual.g) && actual.g !== actual.g : actual.g === g)
&& (isNaN(b) ? isNaN(actual.b) && actual.b !== actual.b : actual.b === b)
&& (isNaN(opacity) ? isNaN(actual.opacity) && actual.opacity !== actual.opacity : actual.opacity === opacity), {
message: "should be equal",
operator: "rgbStrictEqual",
actual: [actual.r, actual.g, actual.b, actual.opacity],
expected: [r, g, b, opacity]
});
};
tape.Test.prototype.rgbEqual = function(actual, r, g, b, opacity) {
this._assert(actual instanceof color.rgb
&& (isNaN(r) ? isNaN(actual.r) && actual.r !== actual.r : Math.round(actual.r) === Math.round(r))
&& (isNaN(g) ? isNaN(actual.g) && actual.g !== actual.g : Math.round(actual.g) === Math.round(g))
&& (isNaN(b) ? isNaN(actual.b) && actual.b !== actual.b : Math.round(actual.b) === Math.round(b))
&& (isNaN(opacity) ? isNaN(actual.opacity) && actual.opacity !== actual.opacity : actual.opacity === opacity), {
message: "should be equal",
operator: "rgbEqual",
actual: [Math.round(actual.r), Math.round(actual.g), Math.round(actual.b), actual.opacity],
expected: [Math.round(r), Math.round(g), Math.round(b), opacity]
});
};