Skip to content

Colors / Chart Tokens

css/modules/charts/_index.scss

The chart tokens name the colours and fonts a chart takes from the page: its series, its text, axes and gridlines, its range controls, its tooltip. Each has one --chart-* name. Most defaults point at a token the library already has, so a chart follows the page's palette, its surfaces and a project's overrides; three series, the tooltip's shadow and its type size keep RareCharts' own values.

RareCharts reads these names first, from its 0.9.8_7, and keeps its own values as fallbacks for a page without Rare Styles. A chart's own theme (an explicit theme, or darkTheme) still wins over the page.

The library's own pieces beside a chart do not read these names; they use the roles the chart tokens are made from. A legend swatch takes a series when you give it one, --swatch-color: var(--chart-series-1). A row of stats sets its labels in --text-color-light, which --chart-label-color points at by default. To change both, re-map the role; a re-mapped chart token changes only the chart.

Like every token they live on :root, outside the .rd gate: a chart in an island, or on a page without .rd, reads the same names. One of them names a colour the library cannot see there: see On a host's background.

Series

Six series colours, in the order a multi-series chart uses them: --signal, the main chart colour, then RareCharts' orange, green, yellow, violet and red. Where the library's palette has the hue, the token points at it. RareCharts 0.9.8_6 and earlier read no tokens and start with orange, then a light blue #0af, so their series 1 and 2 differ.

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
TokenDefaultHue
--chart-series-1var(--signal)blue, #1677ff
--chart-series-2var(--orange)orange, #fa8c16
--chart-series-3#00c97agreen
--chart-series-4#fc0yellow, #ffcc00
--chart-series-5#c4fviolet, #cc44ff
--chart-series-6var(--red)red, #ff0000

Re-map a series for every chart on :root, or for one chart on its container:

:root {
    --chart-series-1: var(--green);  /* every chart */
}

#revenue-chart {
    --chart-series-1: var(--purple); /* this one */
}

Text, axes and gridlines

These name roles of the surface the chart sits on, so they change with it (see Surfaces).

TokenDefaultColours
--chart-bgvar(--surface-current)the surface: the plates behind labels, halos and knockouts
--chart-text-colorvar(--primary-text-color)titles, data labels, end labels
--chart-label-colorvar(--text-color-light)axis ticks, secondary text
--chart-axis-colorvar(--border-color)axis lines, the zero baseline
--chart-grid-colorvar(--border-color-light)gridlines

Range controls

The timeframe buttons and the Lin/Log switch of a time-series chart. A hovered control takes the active control's text and border.

TokenDefaultColours
--chart-control-textvar(--text-color-light)a control's label
--chart-control-bordervar(--border-color)its border
--chart-control-hover-bordervar(--primary-text-color)the border of a hovered and of the active control
--chart-control-active-textvar(--primary-text-color)the label of a hovered and of the active control
--chart-control-active-bgvar(--white)the active control's background
--chart-control-fillvar(--gray)the filled half of the Lin/Log switch

Tooltip

The tooltip is a popover with a surface of its own, so it stays light on a dark card.

TokenDefaultColours
--chart-tooltip-bgvar(--white)its background
--chart-tooltip-bordervar(--border-color-light)its border
--chart-tooltip-textvar(--primary-text-color)rows and titles
--chart-tooltip-mutedvar(--text-color-light)dates, shares, counts
--chart-tooltip-shadow0 2px 8px, black at 10%its lift
--chart-tooltip-font-size13pxits type size: RareCharts' own, fixed like the chart's other type, so it does not follow the root font size

Fonts and focus

TokenDefaultSets
--chart-font-familyvar(--primary-font)chart text
--chart-font-family-numericvar(--code-font)figures in the tooltip: every digit one width
--chart-focus-ringvar(--focus-ring-color)keyboard focus on controls and nodes

Surfaces

--surface-current is the background of the surface an element sits on. The page's is --bg-color (on paper it is white). A .card and a .card-inverted set their own and paint their background with it. A .panel paints no background and sets none, so the surface behind it passes through: a panel on a dark card sits on the dark card. --chart-bg follows the surface, so a chart's label plates hide the gridlines under them without showing a box (RareCharts 0.9.8_7 and later; earlier versions read none of the --chart-* tokens).

.card-inverted re-maps more than its text. Its border roles turn quiet on the dark surface, as they are on the light page: --border-color is --gray-mid-dark, --border-color-light a step closer to the surface, and --border-color-dark is light. So a frame, a panel's dividers and a chart's axes read without glaring. The chart tokens follow: light text and labels, and an active control in the darkest grey under a light label and border.

A .card inside a .card-inverted is a light surface again: it restores the text, link and border roles to their page values, and the chart tokens with them, so a chart in it reads as on the page. A project's own value on :root for one of the text, axis, grid or control tokens (the eight listed under A surface of your own) does not reach a .card-inverted or a .card in one: both resolve those tokens again from their roles. Restate the token on those surfaces. A role re-mapped on :root reaches the nested .card, but not the .card-inverted, which sets its own.

The same tokens on the three library surfaces, and on a panel in the dark card:

A surface of your own

Set --surface-current and paint with it. A custom property is resolved where it is declared, so a token made from another, such as --chart-bg from --surface-current, keeps its :root value inside your surface unless the surface restates it:

.report-band {
    --surface-current: var(--gray-mid-light);
    --chart-bg: var(--surface-current);

    background: var(--surface-current);
}

A dark surface also re-maps the text and border roles, and restates the chart tokens made from them, as .card-inverted does: --chart-text-color, --chart-label-color, --chart-axis-color, --chart-grid-color, --chart-control-text, --chart-control-border, --chart-control-hover-border and --chart-control-active-text, plus its own --chart-control-active-bg and --chart-control-fill.

On a host's background

In an island, or on a page without .rd, the library paints no page background: the block sits on the host's. --surface-current still says --bg-color, so a chart there would draw its label plates as light grey boxes on a background of another colour. Tell the island what it sits on:

<div class="rd" style="--surface-current: #faf0e6;
                       --chart-bg: var(--surface-current)">
    …a chart…
</div>