Skip to content

Releases: d3/d3-color

v1.0.1

02 Aug 21:53
Compare
Choose a tag to compare
  • Add module entry point to package.json.

v1.0.0

14 Jun 22:41
Compare
Choose a tag to compare
  • First stable release.

Changes since D3 3.x

All colors now have opacity exposed as color.opacity, which is a number in [0, 1]. You can pass an optional opacity argument to the color space constructors d3.rgb, d3.hsl, d3.lab, d3.hcl or d3.cubehelix.

You can now parse rgba(…) and hsla(…) CSS color specifiers or the string “transparent” using d3.color. The “transparent” color is defined as an RGB color with zero opacity and undefined red, green and blue channels; this differs slightly from CSS which defines it as transparent black, but is useful for simplifying color interpolation logic where either the starting or ending color has undefined channels. The color.toString method now likewise returns an rgb(…) or rgba(…) string with integer channel values, not the hexadecimal RGB format, consistent with CSS computed values. This improves performance by short-circuiting transitions when the element’s starting style matches its ending style.

The new d3.color method is the primary method for parsing colors: it returns a d3.color instance in the appropriate color space, or null if the CSS color specifier is invalid. For example:

var red = d3.color("hsl(0, 80%, 50%)"); // {h: 0, l: 0.5, s: 0.8, opacity: 1}

The parsing implementation is now more robust. For example, you can no longer mix integers and percentages in rgb(…), and it correctly handles whitespace, decimal points, number signs, and other edge cases. The color space constructors d3.rgb, d3.hsl, d3.lab, d3.hcl and d3.cubehelix now always return a copy of the input color, converted to the corresponding color space. While color.rgb remains, rgb.hsl has been removed; use d3.hsl to convert a color to the RGB color space.

The RGB color space no longer greedily quantizes and clamps channel values when creating colors, improving accuracy in color space conversion. Quantization and clamping now occurs in color.toString when formatting a color for display. You can use the new color.displayable to test whether a color is out-of-gamut.

The rgb.brighter method no longer special-cases black. This is a multiplicative operator, defining a new color r′, g′, b′ where r′ = r × pow(0.7, k), g′ = g × pow(0.7, k) and b′ = b × pow(0.7, k); a brighter black is still black.

There’s a new d3.cubehelix color space, generalizing Dave Green’s color scheme! (See also d3.interpolateCubehelixDefault from d3-scale.) You can continue to define your own custom color spaces, too; see d3-hsv for an example.

See CHANGES for all D3 changes since 3.x.

v0.5.0

07 Jun 23:31
Compare
Choose a tag to compare
  • Export to the global d3 in vanilla environments (d3/d3#2840).

v0.4.2

22 Feb 00:01
Compare
Choose a tag to compare
  • Fix prototype.constructor (#25).

v0.4.1

03 Feb 05:19
Compare
Choose a tag to compare
  • Fix implicitly undefined channels when parsing CSS formats.

v0.4.0

03 Feb 00:22
Compare
Choose a tag to compare
  • Colors now have opacity!
  • Add support for parsing rgba(…) and hsla(…) colors.
  • Fix color.toString to match CSSOM; return rgb(…) or rgba(…), not hex.

v0.3.4

29 Jan 19:06
Compare
Choose a tag to compare
  • Generate anonymous AMD.

v0.3.3

05 Jan 05:24
Compare
Choose a tag to compare
  • Resolve some circular dependencies for Babel (#22).

v0.3.2

18 Dec 22:48
Compare
Choose a tag to compare
  • Improve the README.

v0.3.1

25 Nov 19:42
Compare
Choose a tag to compare