d3 / d3-color

Color spaces! RGB, HSL, Cubehelix, CIELAB, and more.
https://d3js.org/d3-color
ISC License
398 stars 91 forks source link

use d3.color('rgba(255,255,255,0)'), the rgb is all NaN. #52

Closed FEliuyg closed 5 years ago

FEliuyg commented 5 years ago

when i use d3.color parse rgba(255,255,255,0), the result of r,g,b is NaN. why the a is 0, the r,g,b is NaN.

mbostock commented 5 years ago

The color parser treats transparent colors as having undefined R, G and B values because CSS does not support an explicit way of representing undefined channel values and therefore supporting achromatic interpolation. If you want to construct a transparent color with defined R, G and B values, you need to use the d3.rgb constructor instead:

d3.rgb(255, 255, 255, 0)
nickofthyme commented 4 years ago

Is this intentionally different functionality for hexadecimal colors?

d3.rgb('#00000000)');

// returns
{
  r: 0,
  b: 0,
  g: 0,
  opacity: 0,
}
mbostock commented 4 years ago

That looks like a bug in #67.

mbostock commented 4 years ago

Fixed in f176ff11d69195a06dc478bd80c33d26411bf3c7.