Class: Colormap

Colormap

Creates a colormap for mapping numerical values to colors. Supports linear, spline, and bar interpolation between colors.


new Colormap( [colors] [, options])

Creates a new Colormap instance.

Parameters:
Name Type Argument Default Description
colors Array.<Color> <optional>
[black, white]

Array of colors to interpolate between

options Object <optional>

Configuration options

Properties
Name Type Argument Default Description
domain Array.<number> <optional>
[0,1]

Domain range for mapping

lowColor Color <optional>

Color for values below domain (defaults to first color)

highColor Color <optional>

Color for values above domain (defaults to last color)

description string <optional>
''

Description of the colormap

type 'linear' | 'spline' | 'bar' <optional>
'linear'

Interpolation type

Source:
Throws:

If colors/domain format is invalid

Type
Error

Methods


at(x)

Gets color for a value using configured interpolation type.

Parameters:
Name Type Description
x number

Value to get color for

Source:
Throws:

If interpolation type is invalid

Type
Error
Returns:

Corresponding color

Type
Color

rangeDomain()

Gets the domain range of the colormap.

Source:
Returns:

Array containing [min, max] of domain

Type
Array.<number>

sample(maxSteps)

Samples the colormap into a buffer.

Parameters:
Name Type Description
maxSteps number

Number of samples to generate

Source:
Returns:

Sample data and buffer

Type
Object