Skip to main content

Class: ColorMap

Defined in: Colormap.ts:27

A mapping from values to colors

Constructors

Constructor

new ColorMap(levels, colors, opts?): ColorMap

Defined in: Colormap.ts:39

Create a color map

Parameters

ParameterTypeDescription
levelsnumber[]The list of levels. The number of levels should always be one more than the number of colors.
colorsstring[] | Color[]A list of colors
opts?ColorMapOptionsOptions for the color map

Returns

ColorMap

Properties

PropertyModifierTypeDefined in
colorsreadonlyColor[]Colormap.ts:29
levelsreadonlynumber[]Colormap.ts:28
overflow_colorreadonlynull | ColorColormap.ts:30
underflow_colorreadonlynull | ColorColormap.ts:31

Methods

getColors()

getColors(): string[]

Defined in: Colormap.ts:55

Returns

string[]

an array of hex color strings


getOpacities()

getOpacities(): number[]

Defined in: Colormap.ts:62

Returns

number[]

an array of opacities, one for each color in the color map


withOpacity()

withOpacity(func): ColorMap

Defined in: Colormap.ts:71

Make a new color map with different opacities. The opacities are set by func.

Parameters

ParameterTypeDescription
func(level_lower, level_upper) => numberA function which takes the two levels associated with a color (an upper and lower bound) and returns an opacity in the range from 0 to 1.

Returns

ColorMap

A new color map


diverging()

static diverging(color1, color2, level_min, level_max, n_colors): ColorMap

Defined in: Colormap.ts:117

Create a diverging color map using two input colors

Parameters

ParameterTypeDescription
color1stringThe color corresponding to the lowest value in the color map
color2stringThe color corresponding to the highest value in the color map
level_minnumberThe lowest value in the color map
level_maxnumberThe highest value in the color map
n_colorsnumberThe number of colors to use

Returns

ColorMap

a Colormap object