d3 / d3-scale-chromatic

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

Support various output formats #24

Closed jonsadka closed 4 years ago

jonsadka commented 4 years ago

Current

Scale functions export an rgb string making it a bit cumbersome to work with

Proposal

Be able to specify the output format. One such example:

Part of me feels like there is a utility function in d3-color to convert the rgb string but couldnt find it

mbostock commented 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}
jonsadka commented 4 years ago

Fair enough, thanks Mike

mbostock commented 4 years ago

Thanks for the suggestion. :)