Class ColorScale

java.lang.Object
com.codename1.ui.chart.ColorScale

public class ColorScale extends Object

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);
  • Constructor Summary

    Constructors
    Constructor
    Description
    ColorScale(double[] positions, int[] colors)
    Creates a scale from stops.
  • Method Summary

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

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ColorScale

      public ColorScale(double[] positions, int[] colors)

      Creates a scale from stops.

      Parameters
      • positions: ascending stop positions from 0 to 1

      • colors: 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: 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: the colour of the smallest values

      • mid: the neutral middle colour

      • high: 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: 0 to 1; values outside are clamped
      Returns

      an RGB colour