Skip to content

Commit e80621c

Browse files
committed
Update README.
1 parent c497753 commit e80621c

File tree

2 files changed

+27
-35
lines changed

2 files changed

+27
-35
lines changed

README.md

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# d3-color
22

3-
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](https://github.com/d3/d3-interpolate), conversion and manipulation.
3+
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.)
44

55
For example, take the color named “steelblue”:
66

77
```js
8-
color("steelblue"); // {r: 70, g: 130, b: 180}
8+
var c = d3_color.color("steelblue"); // {r: 70, g: 130, b: 180}
99
```
1010

1111
Let’s try converting it to HSL:
1212

1313
```js
14-
hsl("steelblue"); // {h: 207.27272727272728, s: 0.44, l: 0.4901960784313726}
14+
var c = d3_color.hsl("steelblue"); // {h: 207.27272727272728, s: 0.44, l: 0.4901960784313726}
1515
```
1616

1717
Now rotate the hue by 90°, bump up the saturation, and format as hex:
@@ -31,11 +31,17 @@ Cubehelix features monotonic lightness, while Lab and HCL are perceptually unifo
3131

3232
## Installing
3333

34-
If you use NPM, `npm install d3-color`. Otherwise, download the [latest release](https://github.com/d3/d3-color/releases/latest).
34+
If you use NPM, `npm install d3-color`. Otherwise, download the [latest release](https://github.com/d3/d3-color/releases/latest). The released bundle supports AMD, CommonJS, and vanilla environments. Create a custom build using [Rollup](https://github.com/rollup/rollup) or your preferred bundler. You can also load directly from [d3js.org](https://d3js.org):
35+
36+
```html
37+
<script src="https://d3js.org/d3-color.v0.3.min.js"></script>
38+
```
39+
40+
In a vanilla environment, a `d3_color` global is exported. [Try d3-color in your browser.](https://tonicdev.com/npm/d3-color)
3541

3642
## API Reference
3743

38-
<a name="color" href="#color">#</a> <b>color</b>(<i>specifier</i>)
44+
<a name="color" href="#color">#</a> d3_color.<b>color</b>(<i>specifier</i>)
3945

4046
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:
4147

@@ -69,56 +75,42 @@ Returns true if and only if the color is displayable on standard hardware. For e
6975

7076
Returns the RGB hexadecimal string representing this color, such as `"#f7eaba"`. 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.
7177

72-
<a name="rgb" href="#rgb">#</a> <b>rgb</b>(<i>r</i>, <i>g</i>, <i>b</i>)<br>
73-
<a href="#rgb">#</a> <b>rgb</b>(<i>specifier</i>)<br>
74-
<a href="#rgb">#</a> <b>rgb</b>(<i>color</i>)<br>
78+
<a name="rgb" href="#rgb">#</a> d3_color.<b>rgb</b>(<i>r</i>, <i>g</i>, <i>b</i>)<br>
79+
<a href="#rgb">#</a> d3_color.<b>rgb</b>(<i>specifier</i>)<br>
80+
<a href="#rgb">#</a> d3_color.<b>rgb</b>(<i>color</i>)<br>
7581

7682
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.
7783

7884
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.
7985

80-
<a name="hsl" href="#hsl">#</a> <b>hsl</b>(<i>h</i>, <i>s</i>, <i>l</i>)<br>
81-
<a href="#hsl">#</a> <b>hsl</b>(<i>specifier</i>)<br>
82-
<a href="#hsl">#</a> <b>hsl</b>(<i>color</i>)<br>
86+
<a name="hsl" href="#hsl">#</a> d3_color.<b>hsl</b>(<i>h</i>, <i>s</i>, <i>l</i>)<br>
87+
<a href="#hsl">#</a> d3_color.<b>hsl</b>(<i>specifier</i>)<br>
88+
<a href="#hsl">#</a> d3_color.<b>hsl</b>(<i>color</i>)<br>
8389

8490
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.
8591

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

88-
<a name="lab" href="#lab">#</a> <b>lab</b>(<i>l</i>, <i>a</i>, <i>b</i>)<br>
89-
<a href="#lab">#</a> <b>lab</b>(<i>specifier</i>)<br>
90-
<a href="#lab">#</a> <b>lab</b>(<i>color</i>)<br>
94+
<a name="lab" href="#lab">#</a> d3_color.<b>lab</b>(<i>l</i>, <i>a</i>, <i>b</i>)<br>
95+
<a href="#lab">#</a> d3_color.<b>lab</b>(<i>specifier</i>)<br>
96+
<a href="#lab">#</a> d3_color.<b>lab</b>(<i>color</i>)<br>
9197

9298
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.
9399

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

96-
<a name="hcl" href="#hcl">#</a> <b>hcl</b>(<i>h</i>, <i>c</i>, <i>l</i>)<br>
97-
<a href="#hcl">#</a> <b>hcl</b>(<i>specifier</i>)<br>
98-
<a href="#hcl">#</a> <b>hcl</b>(<i>color</i>)<br>
102+
<a name="hcl" href="#hcl">#</a> d3_color.<b>hcl</b>(<i>h</i>, <i>c</i>, <i>l</i>)<br>
103+
<a href="#hcl">#</a> d3_color.<b>hcl</b>(<i>specifier</i>)<br>
104+
<a href="#hcl">#</a> d3_color.<b>hcl</b>(<i>color</i>)<br>
99105

100106
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.
101107

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

104-
<a name="cubehelix" href="#cubehelix">#</a> <b>cubehelix</b>(<i>h</i>, <i>s</i>, <i>l</i>)<br>
105-
<a href="#cubehelix">#</a> <b>cubehelix</b>(<i>specifier</i>)<br>
106-
<a href="#cubehelix">#</a> <b>cubehelix</b>(<i>color</i>)<br>
110+
<a name="cubehelix" href="#cubehelix">#</a> d3_color.<b>cubehelix</b>(<i>h</i>, <i>s</i>, <i>l</i>)<br>
111+
<a href="#cubehelix">#</a> d3_color.<b>cubehelix</b>(<i>specifier</i>)<br>
112+
<a href="#cubehelix">#</a> d3_color.<b>cubehelix</b>(<i>color</i>)<br>
107113

108114
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.
109115

110116
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.)
111-
112-
## Changes from D3 3.x:
113-
114-
* A new [cubehelix](#cubehelix) color space!
115-
116-
* 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).
117-
118-
* 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.
119-
120-
* The *rgb*.hsl method has been removed; use the [hsl constructor](#hsl) to convert to HSL instead.
121-
122-
* 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.
123-
124-
* 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.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "d3-color",
3-
"version": "0.3.1",
3+
"version": "0.3.2",
44
"description": "Color spaces! RGB, HSL, Cubehelix, Lab and HCL (Lch).",
55
"keywords": [
66
"d3",

0 commit comments

Comments
 (0)