Skip to main content

colormapBuilder()

function colormapBuilder(
color,
convertTo,
n,
opacity): number[][] | string[];

Builds a color ramp (discrete or continuous) from a specified colormap.

Parameters

ParameterTypeDefault valueDescription
colorstringundefinedName of the colormap to use (e.g. 'viridis', 'RdBu_r').
convertTostring''Optional output format ('hex' or 'css'). Default is raw RGB arrays.
nnumber255Number of color steps to generate (default: 255).
opacitynumber1Opacity factor from 0 to 1 (default: 1).

Returns

number[][] | string[]

Array of colors in the selected format.

Example

// Generate a viridis ramp as CSS rgba() strings
const colors = colormapBuilder('viridis', 'css', 10, 0.8);
console.log(colors[0]); // "rgba(68,1,84,0.8)"