Skip to main content

colormapBuilder()

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

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

Parameters

ParameterTypeDescription
colorstringName of the colormap to use (e.g. 'viridis', 'RdBu_r').
convertTo?stringOptional output format ('hex' or 'css'). Default is raw RGB arrays.
n?numberNumber of color steps to generate (default: 255).
opacity?numberOpacity factor from 0 to 1 (default: 1).

Returns

string[] | number[][]

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)"