d3-interpolate color interpolators
Color interpolators: d3.interpolateRgb (RGB colors), d3.interpolateRgbBasis (B-spline through colors), d3.interpolateRgbBasisClosed (closed B-spline through colors), d3.interpolateHsl (HSL colors), d3.interpolateHslLong (HSL the long way), d3.interpolateLab (Lab colors), d3.interpolateHcl (HCL colors), d3.interpolateHclLong (HCL the long way), d3.interpolateCubehelix (Cubehelix colors), d3.interpolateCubehelixLong (Cubehelix the long way).
d3-interpolate color interpolator methods
Color interpolator methods: interpolateColor.gamma (apply gamma correction during interpolation), d3.interpolateHue (interpolate hue angle).
interpolateRgb signature and behavior
interpolateRgb(a, b) returns an RGB color space interpolator between two colors a and b with a configurable gamma that defaults to 1.0. The colors a and b need not be in RGB; they are converted to RGB using d3.rgb. The return value is an RGB string.
interpolateRgbBasis signature and behavior
interpolateRgbBasis(colors) returns a uniform nonrational B-spline interpolator through the specified array of colors, which are converted to RGB color space. Implicit control points are generated such that the interpolator returns colors[0] at t = 0 and colors[colors.length - 1] at t = 1. Opacity interpolation is not currently supported.
interpolateRgbBasisClosed signature and behavior
interpolateRgbBasisClosed(colors) returns a uniform nonrational B-spline interpolator through the specified array of colors, which are converted to RGB color space. The control points are implicitly repeated such that the resulting spline has cyclical C² continuity when repeated around t in [0,1], which is useful for creating cyclical color scales. Opacity interpolation is not currently supported.
interpolateHsl signature and behavior
interpolateHsl(a, b) returns an HSL color space interpolator between two colors a and b. The colors need not be in HSL; they are converted using d3.hsl. If either color's hue or saturation is NaN, the opposing color's channel value is used. The shortest path between hues is used. The return value is an RGB string.
interpolateLab signature and behavior
interpolateLab(a, b) returns a CIELAB color space interpolator between two colors a and b. The colors need not be in CIELAB; they are converted to CIELAB using d3.lab. The return value is an RGB string.
interpolateHcl signature and behavior
interpolateHcl(a, b) returns a CIELCh_ab color space interpolator between two colors a and b. The colors need not be in CIELCh_ab; they are converted using d3.hcl. If either color's hue or chroma is NaN, the opposing color's channel value is used. The shortest path between hues is used. The return value is an RGB string.
interpolateHclLong signature and behavior
interpolateHclLong(a, b) is like interpolateHcl, but does not use the shortest path between hues.
interpolateCubehelix signature and behavior
interpolateCubehelix(a, b) returns a Cubehelix color space interpolator between two colors a and b using a configurable gamma that defaults to 1.0. The colors need not be in Cubehelix; they are converted using d3.cubehelix. If either color's hue or saturation is NaN, the opposing color's channel value is used. The shortest path between hues is used. The return value is an RGB string.
interpolateCubehelixLong signature and behavior
interpolateCubehelixLong(a, b) is like interpolateCubehelix, but does not use the shortest path between hues.
interpolateColor.gamma method
For interpolateRgb, interpolateCubehelix, or interpolateCubehelixLong, calling .gamma(gamma) returns a new interpolator factory of the same type using the specified gamma value. This is used for gamma correction in color interpolation.
interpolateHue signature and behavior
interpolateHue(a, b) returns an interpolator between two hue angles a and b. If either hue is NaN, the opposing value is used. The shortest path between hues is used. The return value of the interpolator is a number in [0, 360).
interpolateHue example
d3.interpolateHue(20, 340)(0.5) returns 0.
B-spline color interpolation definition
Spline interpolators smoothly blend multiple input values for t in [0,1] using piecewise polynomial functions. Only cubic uniform nonrational B-splines, also known as basis splines, are currently supported.