Class ChartPalette

java.lang.Object
limn.components.chart.ChartPalette

public final class ChartPalette extends Object
The colors a chart hands to its series (or, in a donut, to its slices) when the application names none. Two built-in sets, one for light surfaces and one for dark, picked automatically from the active Theme.

The two sets are the same eight hues stepped for their surface, not two unrelated palettes, and the order is the mechanism, not decoration: it was chosen so that every adjacent pair stays apart under simulated protanopia and deuteranopia (OKLab ΔE ≥ 8) as well as under normal vision (ΔE ≥ 15), because adjacent slots are the pairs a stacked bar, a grouped bar and a legend actually put side by side. Reordering the slots or editing a hex breaks that guarantee; ChartPaletteTest pins the values so the break is a test failure rather than a silent regression.

What a chart draws by default is held to 3:1 on the palette's surfaces, as WCAG 2.1 1.4.11 asks of a mark that is needed to read the chart: defaultFor(limn.components.Theme) moves each slot in OKLab lightness alone, keeping its hue and its chroma where the gamut allows, darker in a light palette and lighter in a dark one, only until it clears 3:1 on the canvas, a card and a popover; then it moves an adjacent pair further apart wherever the move brought it under the separation above. Four of the light slots and one of the dark sit below 3:1 as written, on most palettes' surfaces. forLightSurface() and forDarkSurface() keep the slots as written. A palette of your own is used as given: hold it to 3:1 yourself, or let a legend and the tooltip name every series.

Past the last slot the palette repeats, shading each repeat alternately toward white and black. That keeps a ninth series drawable, but two series then differ only by lightness: at that point fold the tail into an "Other" series, or split the chart.


 chart.setPalette(ChartPalette.of(Color.rgb(0x4C8DFF), Color.rgb(0xF472B6)));
 
  • Method Details

    • of

      public static ChartPalette of(Color... colors)
      A palette over the given colors, in the order they will be assigned.
      Throws:
      IllegalArgumentException - if no color is given
    • of

      public static ChartPalette of(List<Color> colors)
      of(Color...) over a list; the list is copied.
    • forLightSurface

      public static ChartPalette forLightSurface()
      The built-in slots for a light surface.
    • forDarkSurface

      public static ChartPalette forDarkSurface()
      The built-in slots for a dark surface.
    • defaultFor

      public static ChartPalette defaultFor(Theme theme)
      The built-in set for theme's mode, solved for its surfaces: what a chart uses unless told otherwise. Each slot clears 3:1 on the theme's background, surface and raised surface, and adjacent slots stay apart under normal vision, protanopia and deuteranopia; see the class comment. Solved once per palette.
    • color

      public Color color(int index)
      The color for slot index. Indexes past size() repeat the slots, shading each repeat alternately lighter and darker; see the class note on why that is a fallback rather than an extension.
      Throws:
      IllegalArgumentException - if index is negative
    • size

      public int size()
      How many distinct slots this palette declares.
    • colors

      public List<Color> colors()
      The slots, in assignment order.