Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public class ColorScale

  1. Object
  2. ColorScale

Maps numbers to colours for heatmaps: a sequence of colour stops interpolated linearly.

ColorScale temp = ColorScale.diverging(0x2166AC, 0xF7F7F7, 0xB2182B);
int rgb = temp.colorAt(0.75);

Constructors

public ColorScale(double[] positions, int[] colors)Creates a scale from stops.

Methods

public static ColorScale sequential(int rgb)A single hue scale from a pale tint to the full colour, for magnitudes.
public static ColorScale diverging(int low, int mid, int high)A two hue scale through a neutral middle, for values above and below a reference.
public static ColorScale viridis()A perceptually uniform scale (viridis) that stays readable in greyscale and for colour-blind readers.
public int colorAt(double f)The colour at a position.

Inherited methods

Constructor details

ColorScale

public ColorScale(double[] positions, int[] colors)
Creates a scale from stops.

Parameters

positions double[]
ascending stop positions from 0 to 1
colors int[]
the colour at each stop

Method details

sequential

public static ColorScale sequential(int rgb)
A single hue scale from a pale tint to the full colour, for magnitudes.

Parameters

rgb int
the colour of the largest values

Returns

the scale

diverging

public static ColorScale diverging(int low, int mid, int high)
A two hue scale through a neutral middle, for values above and below a reference.

Parameters

low int
the colour of the smallest values
mid int
the neutral middle colour
high int
the colour of the largest values

Returns

the scale

viridis

public static ColorScale viridis()
A perceptually uniform scale (viridis) that stays readable in greyscale and for colour-blind readers.

Returns

the scale

colorAt

public int colorAt(double f)
The colour at a position.

Parameters

f double
0 to 1; values outside are clamped

Returns

an RGB colour