Skip to content

Commit

Permalink
Add d3.gray.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Apr 17, 2018
1 parent bf3fde6 commit 331187b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -119,6 +119,10 @@ Constructs a new [Lab](https://en.wikipedia.org/wiki/Lab_color_space#CIELAB) col

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.)

<a name="gray" href="#gray">#</a> d3.<b>gray</b>(<i>l</i>[, <i>opacity</i>]) [<>](https://github.com/d3/d3-color/blob/master/src/lab.js "Source")<br>

Constructs a new [Lab](#lab) color with the specified *l* value and *a* = *b* = 0.

<a name="hcl" href="#hcl">#</a> d3.<b>hcl</b>(<i>h</i>, <i>c</i>, <i>l</i>[, <i>opacity</i>]) [<>](https://github.com/d3/d3-color/blob/master/src/lab.js "Source")<br>
<a href="#hcl">#</a> d3.<b>hcl</b>(<i>specifier</i>)<br>
<a href="#hcl">#</a> d3.<b>hcl</b>(<i>color</i>)<br>
Expand Down
2 changes: 1 addition & 1 deletion index.js
@@ -1,3 +1,3 @@
export {default as color, rgb, hsl} from "./src/color";
export {default as lab, hcl, lch} from "./src/lab";
export {default as lab, hcl, lch, gray} from "./src/lab";
export {default as cubehelix} from "./src/cubehelix";
4 changes: 4 additions & 0 deletions src/lab.js
Expand Up @@ -31,6 +31,10 @@ function labConvert(o) {
return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
}

export function gray(l, opacity) {
return new Lab(l, 0, 0, opacity == null ? 1 : opacity);
}

export default function lab(l, a, b, opacity) {
return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
}
Expand Down
12 changes: 12 additions & 0 deletions test/gray-test.js
@@ -0,0 +1,12 @@
var tape = require("tape"),
color = require("../");

require("./labEqual");

tape("gray(l[, opacity]) is an alias for lab(l, 0, 0[, opacity])", function(test) {
test.labEqual(color.gray(120), 120, 0, 0, 1);
test.labEqual(color.gray(120, 0.5), 120, 0, 0, 0.5);
test.labEqual(color.gray(120, null), 120, 0, 0, 1);
test.labEqual(color.gray(120, undefined), 120, 0, 0, 1);
test.end();
});

0 comments on commit 331187b

Please sign in to comment.