warm-paper-ui

Instructions for building pages with this kit

These rules are for AI coding agents and for humans. Follow them whenever you create or change a page, component or chart that uses this kit. They are short on purpose: when in doubt, copy a pattern from examples/ instead of inventing a new one.

1. Setup

2. Colour

3. Type

4. Layout and components

5. Dark mode

6. Responsive

7. Accessibility

Visualisations

These rules are mandatory for every chart, graph, plot or other data visualisation.

  1. D3.js only. Load D3 from cdnjs or jsDelivr with an exact, pinned version, for example https://cdnjs.cloudflare.com/ajax/libs/d3/7.9.0/d3.min.js (with its integrity hash). No other chart libraries (no Chart.js, ECharts, Highcharts, Plotly, Vega, Recharts …), no chart images (PNG/JPG/static SVG exports). Small inline meters such as .progress and .stat tiles are components, not charts, and may be used without D3.
  2. Research the form first, then build. Before writing any chart code:
    • look up which forms of representation exist for this kind of data and question, using the D3 gallery and a chart-choice reference such as the Data Viz Project or the Financial Times Visual Vocabulary;
    • list the candidate forms, each with a one-line rationale (what it shows well, what it hides);
    • pick the most fitting one and say why. Sometimes the answer is not a chart but a stat tile or a table.
    • Only then implement it. Keep the list with the chart (the examples put it in a “Why this form” box) or in the pull request description.
  3. Colours from the kit tokens, read at runtime. Use js/chart-theme.js: ChartTheme.read(container) returns the current token values via getComputedStyle, and ChartTheme.observe(container, render) re-renders on theme change and resize, so dark mode works. Series colours are t.series[0..3] (--chart-1 … --chart-4) in that fixed order; never cycle them, fold a fifth series into t.other or use small multiples. Status meaning (good/bad) uses t.good / t.bad, never a series colour.
  4. Styling. Axes and gridlines are hairlines in --line-2 / --line (ChartTheme.styleAxis). Tick and axis labels are --ink-3, sans, 10.5 px. Chart titles use the serif (.chart-title, one <em> accent allowed). Values and labels use ink tokens, never the series colour. Marks: columns at most 24 px wide with a 4 px rounded end (ChartTheme.columnPath), lines 2 px, end dots r = 4 with a 2 px ring in the surface colour.
  5. One y-axis per chart. Never two scales on one chart; use two charts or small multiples.
  6. Accessibility. Two or more series get a legend (.legend); label selectively (the end or the extreme, not every point); add a hover tooltip (ChartTheme.tooltip) and a table view (details.chart-table); give the chart container role="img" and an aria-label that states the main finding.
  7. Responsive. Size the SVG from the container width on every render; reduce ticks and drop direct labels on narrow screens, keep the legend.

See examples/charts.html for a column chart, a multi-series line chart and small multiples that follow all of the above.

Before you finish