Closed jonsadka closed 4 years ago
This class follows the patterns of D3’s color interpolators and returns the result of color.toString which is the RGB-formatted color (for compatibility with computed values CSS, and to prevent transitions when the color hasn’t actually changed).
So, I think it’d be too much work to support arbitrary output formats everywhere D3 has color interpolators.
If you want to compute the channel values in RGB color space, you can parse the string returned by the interpolator:
d3.rgb(d3.interpolateSpectral(0.5)) // {r: 251, g: 248, b: 176}
Fair enough, thanks Mike
Thanks for the suggestion. :)
Current
Scale functions export an
rgb
string making it a bit cumbersome to work withd3.interpolateSpectral(0.5)
=>"rgb(251, 248, 176)"
Proposal
Be able to specify the output format. One such example:
d3.interpolateSpectral(0.5, 'object')
=>{r: 251, g: 248, b: 176}
d3.interpolateSpectral(0.5, 'array')
=>[251, 248, 176]
Part of me feels like there is a utility function in d3-color to convert the rgb string but couldnt find it