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.

Contrast against the surface is deliberately not a gate for these marks: four of the light slots and one of the dark sit below 3:1 on a typical chart surface, which is legal only because identity is never carried by color alone here: a chart with two or more series always draws a legend, and the tooltip names the series it reports. Keep that relief in place if you swap in your own colors.

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 matching theme's mode, what a chart uses unless told otherwise.
    • 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.