Guides
Palettes
A palette is a named set of values for some of the color tokens. The default palette is tuned so that marks keep their contrast on the light and the dark surface. There is one other, vivid, which restores the brighter light colors that the library used before 0.6b for three tokens: --ch-warn, --ch-gain and --ch-neutral.
Choosing a palette #
Set data-ch-palette="vivid" on <html>, on any ancestor of a chart, or on the element that also has data-ch-theme.
<html lang="en" data-ch-palette="vivid">
<body>{children}</body>
</html>Your own --ch-* overrides on a descendant still win over the palette. Everything that is not one of the three tokens is unchanged.
Swatches #
The default palette, with the contrast of each color against --ch-surface of the same theme:
--ch-accent- Light
#24356b11.20:1- Dark
#7f9be66.89:1
--ch-accent-soft- Light
#a9b6de1.93:1- Dark
#6f80b44.83:1
--ch-loss- Light
#e8505b3.51:1- Dark
#ff6b746.77:1
--ch-warn- Light
#be802f3.18:1- Dark
#ffb24d10.44:1
--ch-gain- Light
#3a93b83.33:1- Dark
#5cc0e69.03:1
--ch-neutral- Light
#8e8e953.12:1- Dark
#7c7c864.53:1
Contrast is against --ch-surface of the same theme.
The vivid palette changes --ch-warn, --ch-gain and --ch-neutral in the light theme only:
--ch-accent- Light
#24356b11.20:1
--ch-accent-soft- Light
#a9b6de1.93:1
--ch-loss- Light
#e8505b3.51:1
--ch-warn- Light
#f1a23b2.02:1
--ch-gain- Light
#4fa3c72.72:1
--ch-neutral- Light
#a3a3ab2.40:1
Light only: the palette does not change the dark theme. Contrast is against --ch-surface of the same theme.
Side by side #
Both panels below are pinned to the light theme, because the palette does not apply to the dark one, and both have a --ch-surface background. The panel on the right also has data-ch-palette="vivid", on the same element as data-ch-theme. The chart uses the gain, neutral and warn tones.
import type { CSSProperties, ReactNode } from 'react'
import { Axis, Bars, Chart, Grid, Line } from 'tally-charts'
import type { ExampleMeta } from '../types'
export const meta = {
id: 'palettes/vivid',
title: 'Margin by week, default palette',
rscSafe: true,
} satisfies ExampleMeta
const weeks = [
{ week: 'W1', margin: 34, plan: 36, floor: 30 },
{ week: 'W2', margin: 35, plan: 36, floor: 30 },
{ week: 'W3', margin: 31, plan: 37, floor: 30 },
{ week: 'W4', margin: 42, plan: 37, floor: 30 },
{ week: 'W5', margin: 45, plan: 38, floor: 30 },
{ week: 'W6', margin: 39, plan: 38, floor: 30 },
]
const grid = {
display: 'grid',
gridTemplateColumns: 'repeat(auto-fit, minmax(min(100%, 16rem), 1fr))',
gap: '1.5rem',
} satisfies CSSProperties
const panel = {
background: 'var(--ch-surface)',
color: 'var(--ch-ink)',
padding: '1rem',
borderRadius: 'var(--ch-radius)',
} satisfies CSSProperties
function Margin({ title }: { title: string }): ReactNode {
return (
<Chart
data={weeks}
x={{ type: 'band', field: 'week', padding: 0.35 }}
y={{ field: 'margin', domain: [20, 50] }}
margin={{ left: 36 }}
height={220}
title={title}
description="Margin passed the plan in W4 and peaked at 45% in W5."
>
<Grid ticks={3} />
<Bars id="week" tone="gain" fill="hatch-fade" />
<Line y="plan" tone="neutral" dashed dots="none" />
<Line y="floor" tone="warn" dots="none" />
<Axis side="left" ticks={3} />
<Axis side="bottom" />
</Chart>
)
}
// `data-ch-palette` sits on the same element as `data-ch-theme`, so the palette can never end up
// inside a theme of its own. The palette is light only, so both panels are pinned to light.
// Props stay serializable (no functions): the page is a server component.
export default function Vivid() {
return (
<div style={grid}>
<div data-ch-theme="light" style={panel}>
<Margin title={meta.title} />
</div>
<div data-ch-theme="light" data-ch-palette="vivid" style={panel}>
<Margin title="Margin by week, vivid palette" />
</div>
</div>
)
}
Limits #
- Light only. Where the effective theme is dark (
data-ch-theme="dark"or a dark system preference) the tokens are the normal dark ones, so a visitor in dark mode sees no difference. - Forced colors win. In Windows high contrast mode the tokens stay system colors, whatever the palette.
- Nesting. A
data-ch-theme="dark"element nested inside a light one, with a bare palette element below it, gets vivid colors in a dark region. Put the attribute on<html>or on the themed element itself to avoid it. - Contrast. The three vivid colors are below 3:1 against the light surface (warn 2.0:1, gain 2.9:1, neutral 2.4:1), so marks in these tones are harder to see than by default. Do not rely on the color alone to tell marks apart.