Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public class ColorScale
- Object
- 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
positionsdouble[]- ascending stop positions from 0 to 1
colorsint[]- 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
rgbint- 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
lowint- the colour of the smallest values
midint- the neutral middle colour
highint- 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
fdouble- 0 to 1; values outside are clamped
Returns
an RGB colour