Skip to main content

Class: ColorMap

Defined in: Colormap.ts:28

A mapping from values to colors

Constructors​

Constructor​

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

Defined in: Colormap.ts:40

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:30
levelsreadonlynumber[]Colormap.ts:29
overflow_colorreadonlyColor | nullColormap.ts:31
underflow_colorreadonlyColor | nullColormap.ts:32

Methods​

getColor()​

getColor(val): string

Defined in: Colormap.ts:72

Sample from the color map

Parameters​

ParameterTypeDescription
valnumberThe value to sample from the color map

Returns​

string

A color as an RGBA hex string


getColors()​

getColors(): string[]

Defined in: Colormap.ts:56

Returns​

string[]

an array of hex color strings


getOpacities()​

getOpacities(): number[]

Defined in: Colormap.ts:63

Returns​

number[]

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


withOpacity()​

withOpacity(func): ColorMap

Defined in: Colormap.ts:94

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:140

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