d3 / d3-scale-chromatic

Sequential, diverging and categorical color scales.

Home Page:https://d3js.org/d3-scale-chromatic

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add option for opacity/alpha

SlowMo24 opened this issue · comments

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?

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})`;

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