d3 / d3-scale-chromatic

Sequential, diverging and categorical color scales.
https://d3js.org/d3-scale-chromatic
Other
801 stars 106 forks source link

Add option for opacity/alpha #44

Closed SlowMo24 closed 2 years ago

SlowMo24 commented 2 years ago

I would like to have rgba-values as output. I cannot find that option so I guess this would need an extension to the existing color-getter-functions to accept an optional alpha-value?

curran commented 2 years ago

You could convert colors to RGBA format using d3.rgb.

const { r, g, b, opacity } = d3.rgb(color);
const formatted = `rgba(${r},${g},${b},${opacity})`;
SlowMo24 commented 2 years ago

ah nice, thank you! I didn't know about that function (and solved it with string replacement, but this is nicer).