d3 / d3-scale-chromatic

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

Heterogeneous format of color with different color schemes #17

Closed PBrockmann closed 6 years ago

PBrockmann commented 6 years ago

I get heterogeneous format of color, either HTML code such as "#21918c" or rgba code such as "rgb(255, 94, 99)" with different color schemes.

var interpolators = [ 'interpolateViridis', 'interpolateInferno', 'interpolateMagma', 'interpolatePlasma', 'interpolateWarm', 'interpolateCool', 'interpolateRainbow', 'interpolateCubehelixDefault' ]; for(var i=0, size=interpolators.length; i<size; i++) { interpolator = interpolators[i]; s = d3.scaleSequential().domain([0, 100]).interpolator(d3[interpolator]); console.log(s(50)); }

For the last 4 ones, I get rgba output, but 4 first ones give HTML code. Is there a way to force the format ?

mbostock commented 6 years ago

The behavior of the interpolator depends on its implementation, and interpolateViridis (and the other Viridis color schemes) have a different implementation from scales. If you want to convert between formats, you should use d3-color to parse the returned string and convert it into the desired format.

PBrockmann commented 6 years ago

Ok. No problem. Thanks M. Bostock