# Chart colours (data visualisation)

https://docs.kleaver.ie/theming/chart-colours/

Charts (`.chart`, `.hero-stat`, `.waffle`, `.strip`, Sankey, Gantt and treemap) read these tokens from `tokens.css`:

| Token | What it is |
|---|---|
| `--chart-1` … `--chart-8` | Series colours in a **fixed order**: ggplot2's default hue palette (salmon, teal, violet, ochre, sky, green, pink, emerald). Never cycled; a ninth series folds into "Other". |
| `--chart-seq-1` … `--chart-seq-5` | One hue, taken from `--color-brand`, for magnitude and ordered stages (1 = least, 5 = most). |
| `--chart-state-up`, `--chart-state-warn`, `--chart-state-down` | Up / degraded / down in strips and good-or-bad cues. Dark surfaces use the status tokens; light surfaces use darker steps that clear 3:1 on white. |
| `--chart-emphasis`, `--chart-muted` | Highlight one series, grey the rest. |
| `--chart-grid`, `--chart-axis`, `--chart-surface`, `--chart-label` | Chart chrome and text on a coloured fill. |
| `--chart-link-opacity` | Optional. How solid Sankey bands are (default `0.42`); set it in `theme.css` if bands look too faint or too heavy on a theme. |

**Light or dark:** the series colours follow `data-theme`. Dark steps are the default; light steps apply under
`<html data-theme="light">`. A light client theme that adopts charts sets `data-theme="light"` on `<html>` (kleaver.ie and
the status site already do). A client can retune the ramp in `theme.css` (`--chart-seq-*`); chart CSS never goes in a client folder.

**Where the series colours come from.** ggplot2's `hue_pal()`: eight hues evenly spaced round the HCL wheel from 15°,
chroma 100, lightness 65 (ggplot2's own values, used on light surfaces) and 55 on dark surfaces, where 65 sits above the
dark lightness band. ggplot2 assigns them in hue order and re-spaces them for each series count; here they keep **one
order** (so a series keeps its colour whatever else is on the chart), chosen by checking every ordering with
`validate_palette.js` so that neighbours, and the first three together (they overlap in Venn and radar charts), stay
distinct for colour-blind and full-colour readers. Two series get salmon and teal, ggplot2's own pair.

| Slot | Light (l 65) | Dark (l 55) |
|---|---|---|
| 1 salmon | `#f8766d` | `#da5b51` |
| 2 teal | `#00bfc4` | `#00a5aa` |
| 3 violet | `#c77cff` | `#ae5ee9` |
| 4 ochre | `#cd9600` | `#b07c00` |
| 5 sky | `#00a9ff` | `#0090e4` |
| 6 green | `#7cae00` | `#629400` |
| 7 pink | `#ff61cc` | `#e33eb2` |
| 8 emerald | `#00be67` | `#00a24b` |

**Checked with `validate_palette.js`** (data-viz method; 2026-12-01):

| Mode | Surface | Adjacent pairs (all 8) | First three, all pairs |
|---|---|---|---|
| light | `#f6f8fa` | pass; worst colour-blind separation 10.1, normal vision 26.5 | pass; 10.1 / 22.3 |
| dark | `#161b22` | pass; worst colour-blind separation 12.0, normal vision 26.7 | pass; 12.0 / 23.7 |

**Contrast warning, light mode:** at ggplot2's lightness every series colour is about 2.1–2.5:1 on the light surface
(under the 3:1 mark target). That is the price of keeping ggplot2's look; it is why every chart ships a legend for two or
more series, direct labels where they fit, and a table view. Dark mode clears 3:1 throughout.

### Palette knobs: `data-chart-palette` and `data-chart-ordinal`

Two whole-site choices, set on `<html>` next to `data-theme` (never per chart, so a series keeps its colour across a site).
They live in the `Chart` block of `components.css`, so sites without charts don't carry them.

| Attribute | Values | What changes |
|---|---|---|
| `data-chart-palette` | *(absent)* = ggplot2 · `dark2` | `--chart-1…8`, the series colours |
| `data-chart-ordinal` | *(absent)* = brand ramp · `viridis` | `--chart-seq-1…5`, used by ordered charts (funnel, waffle) |

**`dark2`: ColorBrewer Dark2, adjusted to pass.** Dark2's eighth colour is grey (fails the chroma floor: it can't carry
identity), so that slot is ColorBrewer Set1 blue `#377eb8` (Dark2 has no blue). Its mustard `#e6ab02` sits just above the
lightness band, so it is snapped down keeping hue and chroma: `#e1a600` light, `#c28800` dark. Order chosen by checking all
orderings: teal-green, orange, purple, green, magenta, mustard, blue, brown (`#1b9e77 #d95f02 #7570b3 #66a61e #e7298a
#e1a600|#c28800 #377eb8 #a6761d`). Light and dark: adjacent pass, worst colour-blind separation 11.6, normal vision 23.0;
first three all-pairs 11.6 / 19.9. Light contrast WARN on green (2.8:1) and mustard (2.04:1); dark clears 3:1.

**`viridis`: viridis steps for ordered charts.** Light (least → most, more = darker): `#44bf70 #22a884 #2a788e #414487
#440154`. Dark (more = lighter): `#355f8d #21918c #44bf70 #bddf26 #fde725`. Ordinal checks: lightness runs one way, every
step at least 0.06 apart, lightest end 2.21:1 (light) and 2.61:1 (dark) on the surface. It **deliberately fails the
"one hue" ordinal rule** (hue spread about 150°): viridis is a multi-hue scale built so lightness carries the order and
colour-blind readers see the same ramp. Opt-in only; the brand ramp stays the default.

The docs page `dataviz.html` has a switcher that sets these attributes (and `data-theme`) live, mirrored in the address
(`?theme=dark&palette=dark2&ordinal=viridis`).

The magnitude ramp's lightest step clears 2:1 against the surface in both modes (dark 2.30, light 2.12 for the default brand).
