diff --git a/README.md b/README.md index 8deb181..540946e 100644 --- a/README.md +++ b/README.md @@ -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.) +# d3.gray(l[, opacity]) [<>](https://github.com/d3/d3-color/blob/master/src/lab.js "Source")
+ +Constructs a new [Lab](#lab) color with the specified *l* value and *a* = *b* = 0. + # d3.hcl(h, c, l[, opacity]) [<>](https://github.com/d3/d3-color/blob/master/src/lab.js "Source")
# d3.hcl(specifier)
# d3.hcl(color)
diff --git a/index.js b/index.js index e3e68e6..29d6b41 100644 --- a/index.js +++ b/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"; diff --git a/src/lab.js b/src/lab.js index 5105822..d9a009f 100644 --- a/src/lab.js +++ b/src/lab.js @@ -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); } diff --git a/test/gray-test.js b/test/gray-test.js new file mode 100644 index 0000000..e5fee13 --- /dev/null +++ b/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(); +});