diff --git a/.gitignore b/.gitignore index ca785767..53cc6f67 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ tsconfig.tsbuildinfo # macOS .DS_Store + +# Generated chart palette preview +/tools/chart-palette/render-check.html diff --git a/.storybook/preview.tsx b/.storybook/preview.tsx index 54ccf8c0..b5838a0a 100644 --- a/.storybook/preview.tsx +++ b/.storybook/preview.tsx @@ -73,6 +73,7 @@ const preview: Preview = { "Foundations/Colour", "Foundations/Typography", "Foundations/Icons", + "Foundations/Chart Colours", "Helpers", "Theme", "Theme/Logos", diff --git a/.storybook/storybook.css b/.storybook/storybook.css index 58a599fc..75ffffae 100644 --- a/.storybook/storybook.css +++ b/.storybook/storybook.css @@ -1096,3 +1096,176 @@ section.ds-mode-panel section { white-space: pre !important; overflow-x: auto; } + +/* Chart colours page */ +.ds-chart-swatches { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); + gap: 8px; +} + +.ds-chart-swatch { + display: flex; + flex-direction: column; + overflow: hidden; + border: 1px solid var(--ds-border-subtle); + border-radius: 8px; + background: var(--ds-surface); + color: var(--ds-on-surface); +} + +.ds-chart-swatch-box { + height: 72px; +} + +.ds-chart-swatch-row { + display: flex; + align-items: center; + gap: 10px; + padding: 8px 10px; +} + +.ds-chart-swatch-row svg { + flex: none; +} + +.ds-chart-swatch-text { + display: flex; + flex-direction: column; + min-width: 0; + font-size: 13px; + line-height: 1.3; +} + +.ds-chart-swatch-text code { + align-self: flex-start; +} + +.ds-chart-demos { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); + gap: 12px; + padding-top: 12px; +} + +/* Stand-in for a greyscale image, so literal greys are intended here. */ +.ds-chart-image { + position: relative; + height: 140px; + border-radius: 8px; + background: linear-gradient(90deg, #16181f, #868993 50%, #eceef2); +} + +.ds-chart-roi { + position: absolute; + top: 18%; + width: 27%; + height: 46%; + border: 2px solid; + /* Soft halo in the surface colour, outside and inside the border. */ + box-shadow: + 0 0 0 1px rgb(var(--ds-surface-channel) / 0.55), + inset 0 0 0 1px rgb(var(--ds-surface-channel) / 0.55); +} + +.ds-chart-roi-caps { + display: flex; + padding-left: 5%; + margin-top: 6px; + font-size: 12px; + color: var(--ds-on-surface-variant); +} + +.ds-chart-roi-caps span { + width: 31.5%; +} + +.ds-chart-labels { + display: flex; + flex-wrap: wrap; + gap: 8px; + align-content: center; +} + +.ds-chart-label-states { + display: flex; + flex-basis: 100%; + gap: 8px; + margin-top: 6px; +} + +.ds-chart-label { + display: inline-flex; + padding: 2px 10px; + border: 1px solid; + border-radius: 999px; + font-size: 12px; + color: var(--ds-on-surface); +} + +.ds-chart-controls { + display: flex; + flex-wrap: wrap; + gap: 16px 24px; + margin: 16px 0; + padding-bottom: 16px; +} + +.ds-chart-break { + flex-basis: 100%; + height: 0; +} + +.ds-chart-control { + display: flex; + flex-direction: column; + gap: 6px; + min-width: 0; + font-size: 13px; +} + +.ds-chart-examples { + display: grid; + grid-template-columns: minmax(0, 1fr); + gap: 12px; +} + +.ds-chart-surface { + min-width: 0; + overflow-x: auto; + padding: 12px; + border: 1px solid var(--ds-border-subtle); + border-radius: 8px; + background: var(--ds-surface); + color: var(--ds-on-surface); +} + +.ds-chart-cvd-row { + display: grid; + grid-template-columns: 130px minmax(0, 1fr); + align-items: center; + gap: 10px; + margin: 6px 0; +} + +.ds-chart-cvd-label { + font-size: 13px; + color: var(--ds-on-surface-variant); +} + +.ds-chart-cvd-strip { + display: flex; + flex-wrap: wrap; + gap: 4px; +} + +.ds-chart-cvd-strip span { + width: 28px; + height: 28px; + flex: none; + border-radius: 6px; +} + +.ds-chart-cvd-strip span:nth-child(9) { + margin-left: 10px; +} diff --git a/changelog.md b/changelog.md index 4c8d9b1c..fdafd1f0 100644 --- a/changelog.md +++ b/changelog.md @@ -24,6 +24,7 @@ - New _DataCard_ and _DataGroup_ components. - Typography docs now cover font weight, line height and letter spacing scales, with improved Storybook examples. - `JsonFormsControls.layoutRenderers`: a JsonForms vertical layout with consistent spacing between fields. +- Categorical chart palette: 12 series colours per mode (8 core, 4 additional) as `--ds-chart-*` tokens (with `-channel` variants and fill opacities, including rest, hover and selected states for regions on images and labels), a JSON export and a validation report, documented on a new Chart Colours page in Storybook. The tokens are in `src/styles/diamondDS/DiamondDSChartTokens.css`; the generator and checks are in `tools/chart-palette/`. They are loaded with the DiamondDS theme. ### Changed diff --git a/src/storybook/foundation/4. chart-colours.mdx b/src/storybook/foundation/4. chart-colours.mdx new file mode 100644 index 00000000..0e25359c --- /dev/null +++ b/src/storybook/foundation/4. chart-colours.mdx @@ -0,0 +1,421 @@ +import { useState } from "react"; +import Slider from "@mui/material/Slider"; +import MenuItem from "@mui/material/MenuItem"; +import TextField from "@mui/material/TextField"; +import Typography from "@mui/material/Typography"; +import { DiamondDSTheme, ThemeProvider } from "../../index"; +import { Meta } from "@storybook/addon-docs/blocks"; +import palette from "../../../tools/chart-palette/chart-palette.json"; +import { markerSvg } from "../../../tools/chart-palette/markers.mjs"; +import { lineSeries } from "../../../tools/chart-palette/sample.mjs"; + + + +export const Marker = ({ shape }) => ( + +); + +export const core = palette.thresholds.coreSlots; +export const total = palette.slots.length; + +export const Axes = ({ W, H, P }) => + [0, 25, 50, 75, 100].map((v) => { + const y = P.t + ((H - P.t - P.b) * (100 - v)) / 100; + return ( + + + {v} + + ); + }); + +export const seriesColor = (slot, mode, vision) => { + // The token, or its simulated value under a colour-vision deficiency. + return vision === "normal" ? `var(--ds-chart-${slot.slot})` : slot[mode].simulated[vision]; +}; + +export const gapShade = (hex, bg) => { + // The colour half way to the surface, so the gap stays a shade of the line in both modes. + return "#" + [1, 3, 5].map((i) => Math.round((parseInt(hex.slice(i, i + 2), 16) + parseInt(bg.slice(i, i + 2), 16)) / 2).toString(16).padStart(2, "0")).join(""); +}; + +export const LineStroke = ({ d, slot, mode, vision, width, dash, gap }) => { + // A broken line sits on a solid line in its gap shade, or on nothing. + const color = seriesColor(slot, mode, vision); + const hex = vision === "normal" ? slot[mode].hex : slot[mode].simulated[vision]; + if (dash === "solid") return ; + const space = Math.max(4, width * 3); + const pattern = dash === "dotted" ? `0.1 ${space}` : `${Math.max(6, width * 5)} ${space}`; + return ( + <> + {gap === "auto" && } + + + ); +}; + +export const ChartMarker = ({ slot, color, x, y }) => ( + + + +); + +export const LineChart = ({ count, cycle, mode, vision, width, width2, styles, gap, show }) => { + const W = 720, H = 240, P = { l: 30, r: 10, t: 10, b: 14 }, pts = lineSeries[0].length; + const X = (i) => P.l + ((W - P.l - P.r) * i) / (pts - 1); + const Y = (v) => P.t + (H - P.t - P.b) * (1 - v / 100); + return ( + + + {Array.from({ length: count }, (_, k) => { + const s = palette.slots[k % cycle]; + const round = Math.floor(k / cycle); + const raw = lineSeries[k % lineSeries.length]; + const base = raw.map((_, i) => raw[(i + round * 3) % pts]); + const d = base.map((y, i) => `${i ? "L" : "M"}${X(i).toFixed(1)} ${Y(y).toFixed(1)}`).join(""); + return ( + + {show !== "markers" && } + {show !== "lines" && Array.from({ length: show === "markers" ? 10 : 4 }, (_, q) => { + const t = (0.04 + (0.92 * (q + (k + 0.5) / count)) / (show === "markers" ? 10 : 4)) * (pts - 1); + const i0 = Math.min(pts - 2, Math.floor(t)); + const yv = base[i0] + (base[i0 + 1] - base[i0]) * (t - i0); + return ; + })} + + ); + })} + + ); +}; + +export const Range = ({ id, label, value, min, max, step, onChange, unit = "" }) => ( +
+ {label}: {value}{unit} + onChange(v)} sx={{ width: 160 }} /> +
+); + +export const Choice = ({ label, value, onChange, options }) => ( + onChange(e.target.value)} sx={{ minWidth: 170 }}> + {options.map(([v, text]) => ( + {text} + ))} + +); + +export const STYLE_OPTIONS = [["solid", "Solid"], ["dashed", "Dashed"], ["dotted", "Dotted"]]; + +export const InUse = () => { + const [vision, setVision] = useState("normal"); + const [show, setShow] = useState("lines"); + const [cycle, setCycle] = useState(core); + const [count, setCount] = useState(core); + const [width, setWidth] = useState(1); + const [width2, setWidth2] = useState(1.5); + const [styles, setStyles] = useState(["solid", "dashed", "dotted"]); + const [gap, setGap] = useState("auto"); + return ( + +
+ + + + + +
+ { setCycle(v); setCount(Math.min(count, v * 3)); }} options={[[core, `${core} colours`], [total, `${total} colours`]]} /> + {[0, 1, 2].map((i) => ( + setStyles(styles.map((x, j) => (j === i ? v : x)))} options={STYLE_OPTIONS} /> + ))} + +
+
+ {["light", "dark"].map((mode) => ( +
+

{mode === "light" ? "Light mode" : "Dark mode"}

+
+
+ +
+
+
+ ))} +
+ + ); +}; + +
+ +# Chart colours + + + A categorical palette for the series in line and scatter charts. It has 12 + colours per mode, ordered so the first few are the easiest to tell apart. + + +Use these colours to tell data series apart. They are separate from the UI colours: do not use intent colours as a chart palette, and do not use chart colours to signal status. See **[Colour](/docs/foundations-colour--docs)** for UI colour and **[Theme Colours](/docs/foundations-theme-colours--docs)** for the semantic roles. + +## Colours + +Each slot has its own colour, name and marker shape. Each mode is tuned separately, so a slot does not look identical in both modes, and the slot names describe the family rather than an exact shade. Slots 1 to {core} are the core. Slots {core + 1} to {total} are additional. + +
+ {["light", "dark"].map((mode) => ( +
+

{mode === "light" ? "Light mode" : "Dark mode"}

+
+ {palette.slots.map((s) => ( +
+
+
+ + + + {s.slot} {s.name} + {s.slot > core ? " (additional)" : ""} + + {s[mode].hex} + +
+
+ ))} +
+
+
+
+ {[ + ["region", 2], + ["region-hover", 2], + ["region-selected", 3], + ].map(([token, width], i) => ( +
+ ))} +
+
+ Rest + Hover + Selected +
+
+
+ {palette.slots.slice(0, core).map((s) => ( + + {s.name} + + ))} +
+ {[ + ["Rest", "label", 1], + ["Hover", "label-hover", 1], + ["Selected", "label-selected", 2], + ].map(([label, token, width]) => ( + 1 ? 600 : 400, + borderColor: "var(--ds-chart-1)", + background: `rgb(var(--ds-chart-1-channel) / var(--ds-chart-fill-${token}))`, + }} + > + {label} + + ))} +
+
+
+
+ ))} +
+ +The panels sit on `--ds-background` and each swatch on `--ds-surface`, the two surfaces charts are checked against. + +## In use + +The first {core} series drawn with the tokens on `--ds-surface`. Each series has its own marker shape. Choose Lines and markers or Markers to draw them, at different positions along each line so they do not overlap. Use the controls to simulate a colour-vision deficiency, change what is shown, or change the line width. Raise the series count past one cycle to see the colours repeat with a different line style: cycle 2 dashed, cycle 3 dotted. + + + +## Colour-vision deficiency + +How the palette looks to people with each type of colour-vision deficiency, simulated at full severity. Slots 1 to {core} stay separable. Some of the additional slots can merge for certain types, which is why every slot also has its own marker. + +
+ {["light", "dark"].map((mode) => ( +
+

{mode === "light" ? "Light mode" : "Dark mode"}

+ {[ + ["normal", "Normal vision"], + ["protan", "Protanopia"], + ["deutan", "Deuteranopia"], + ["tritan", "Tritanopia"], + ].map(([v, label]) => ( +
+ {label} +
+ {palette.slots.map((s) => ( + + ))} +
+
+ ))} +
+ ))} +
+ +## Using the palette + +
+ +### Use series in order + +Start at `--ds-chart-1` and take the next slot for each new series. Slots 1 to {core} stay separable under colour-vision deficiency. Slots {core + 1} to {total} have weaker separation for some pairs, so use them only when you need more than {core} series. Skipping or reordering slots can put weaker pairs together. + +### Work in cycles for long sequences + +For more than {total} series, go round the slots again from `--ds-chart-1`, in cycles of {core} or {total}. Within a cycle every line stays solid. Give each new cycle a different second distinction, so a repeated colour is not mistaken for the first one: change the line thickness, or break the line (dashed, then dotted). Fill the gaps in a break with a lighter or darker shade of the same colour, not with empty space, so the line still reads as one series. The checks here cover a single cycle only. Thickness, line breaks and repeated colours are not validated, so check them on your own charts and label series directly where readers must tell the cycles apart. + +### Draw charts on the surface or the background + +The colours are checked for {palette.thresholds.contrast}:1 contrast on `--ds-surface` and `--ds-background`. On raised surfaces, tooltips and dialogs they are only checked to {palette.thresholds.contrastFloor}:1, so label series directly or add a data table there. + +### Pair every colour with a marker + +Colour alone is not enough. Every slot has its own marker shape. Draw lines at least {palette.secondChannel.minLineWidth}px wide and markers at least {palette.secondChannel.minMarkerSize}px across, with a {palette.secondChannel.markerHalo}px `--ds-surface` halo on filled markers. Markers matter most in light mode, where several colours have similar lightness, and for greyscale, print and forced colours. + +### Keep series colours for marks + +Do not colour labels, values or legend text with a series colour. Set text with the text tokens and show the series colour as a swatch. + +### Regions on images + +Draw a region with a solid series-coloured border over a soft fill: `rgb(var(--ds-chart-1-channel) / var(--ds-chart-fill-region))`. Hover raises the fill to `--ds-chart-fill-region-hover`. Selected raises it again to `--ds-chart-fill-region-selected` and thickens the border from 2px to 3px, so selection does not depend on colour alone. Add a soft halo outside the border, `--ds-surface` at about 55% opacity and 1px wide, so the border reads over bright and dark pixels. Keyboard focus uses the shared focus ring, not a chart colour. The fills are decorative, and the border's contrast depends on the image behind it, so check it on your own images. + +### Labels next to a line + +Use a tint of the series colour for the label background, `rgb(var(--ds-chart-1-channel) / var(--ds-chart-fill-label))`, with a 1px border in the series colour and `--ds-on-surface` text. Hover uses `--ds-chart-fill-label-hover`. Selected uses `--ds-chart-fill-label-selected`, a 2px border and bolder text. Keep labels on `--ds-surface` or `--ds-background`, where the text keeps at least {palette.thresholds.textContrast}:1 on every tint in every state. Never use the series colour for the text itself. + +### Never use them for status + +{palette.nearStatus.length} of the {palette.slots.length} series colours ({[...palette.nearStatus].sort((a, b) => a.slot - b.slot).map((n) => `${n.slot} ${n.name}`).join(", ")}) sit close to a status or brand colour, {palette.nearStatus[0].name} most of all ({palette.nearStatus[0].token}). Use the intent colours for meaning, and the chart colours only to tell series apart. + +
+ +## Tokens + +The tokens follow `data-mode`, so use them directly and never pick a value per mode. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TokenUse
--ds-chart-1 to --ds-chart-12Series colour for lines, markers, bars and points.
--ds-chart-1-channel to --ds-chart-12-channelThe same colour as space-separated RGB, for translucent fills.
--ds-chart-fill-area + Opacity for the fill under a line ({palette.fillOpacity.area}). + Decorative, because the line carries the data. +
--ds-chart-fill-band + Opacity for a range band around a line ({palette.fillOpacity.band}). + Decorative only when the band also has a series-coloured edge. +
--ds-chart-fill-region, -hover, -selected + Opacity for a region drawn on an image at rest, on hover and when selected + ({palette.fillOpacity.region}, {palette.fillOpacity["region-hover"]}, {palette.fillOpacity["region-selected"]}), + with a solid series-coloured border. +
--ds-chart-fill-label, -hover, -selected + Opacity for the background tint of a label next to a line at rest, on hover and when selected + ({palette.fillOpacity.label}, {palette.fillOpacity["label-hover"]}, {palette.fillOpacity["label-selected"]}), + with a series-coloured border and neutral text. +
--ds-chart-fill-data + Opacity for bars, scatter points and heatmap cells ({palette.fillOpacity.data}). + Keep it opaque, because the fill is the data. +
+ +```css +.series-1 { + stroke: var(--ds-chart-1); + fill: rgb(var(--ds-chart-1-channel) / var(--ds-chart-fill-area)); +} +``` + +## Accessibility + +- Series colours are graphical objects, so they need {palette.thresholds.contrast}:1 contrast against the surface they sit on (WCAG 1.4.11). They are checked on `--ds-surface` and `--ds-background`. +- Colour must not be the only way to tell series apart (WCAG 1.4.1). Add a legend, markers and direct labels or a data table. +- Overlapping translucent fills blend into colours outside the palette. Prefer lines, or keep overlaps to two series. Separate adjacent filled segments, such as stacked bars, with a 1px to 2px `--ds-surface` gap. +- In forced-colours mode all series can collapse to one system colour. Keep `forced-color-adjust: none` on series marks, or rely on markers. + +## Maintaining the palette + +The tokens are generated from `tools/chart-palette/palette.mjs`. Do not edit `src/styles/diamondDS/DiamondDSChartTokens.css` by hand. After changing the palette, run `node tools/chart-palette/build.mjs`, which rewrites the tokens and the generated report and preview in `tools/chart-palette/`. The report lists the current contrast and separation figures, and a test fails if the outputs are stale or a check fails. + +
diff --git a/src/styles/diamondDS/DiamondDSChartTokens.css b/src/styles/diamondDS/DiamondDSChartTokens.css new file mode 100644 index 00000000..6118868b --- /dev/null +++ b/src/styles/diamondDS/DiamondDSChartTokens.css @@ -0,0 +1,79 @@ +/* Generated by tools/chart-palette/build.mjs from palette.mjs. Do not edit by hand. */ +/* + Draw charts on --ds-surface or --ds-background + (the colours are checked for 3:1 contrast on both) + and use series in order, --ds-chart-1 first. + + Slots 1-8 are the core and stay separable under + colour-vision deficiency; 9-12 are additional. +*/ + +/* Categorical chart palette, light mode */ +:root, +[data-mode="light"] { + --ds-chart-1: #8133d6; /* violet */ + --ds-chart-2: #ed604f; /* vermilion */ + --ds-chart-3: #610c12; /* wine */ + --ds-chart-4: #8a8ab9; /* lavender */ + --ds-chart-5: #1e3f80; /* indigo */ + --ds-chart-6: #316f5e; /* green */ + --ds-chart-7: #b67886; /* rose */ + --ds-chart-8: #a25500; /* amber */ + --ds-chart-9: #318ff8; /* blue */ + --ds-chart-10: #786941; /* khaki */ + --ds-chart-11: #589704; /* fern */ + --ds-chart-12: #9c5894; /* plum */ + + --ds-chart-1-channel: 129 51 214; + --ds-chart-2-channel: 237 96 79; + --ds-chart-3-channel: 97 12 18; + --ds-chart-4-channel: 138 138 185; + --ds-chart-5-channel: 30 63 128; + --ds-chart-6-channel: 49 111 94; + --ds-chart-7-channel: 182 120 134; + --ds-chart-8-channel: 162 85 0; + --ds-chart-9-channel: 49 143 248; + --ds-chart-10-channel: 120 105 65; + --ds-chart-11-channel: 88 151 4; + --ds-chart-12-channel: 156 88 148; + + /* Fill opacities: rgb(var(--ds-chart-1-channel) / var(--ds-chart-fill-area)) */ + --ds-chart-fill-area: 0.16; + --ds-chart-fill-band: 0.28; + --ds-chart-fill-data: 1; + --ds-chart-fill-region: 0.14; + --ds-chart-fill-region-hover: 0.24; + --ds-chart-fill-region-selected: 0.34; + --ds-chart-fill-label: 0.22; + --ds-chart-fill-label-hover: 0.28; + --ds-chart-fill-label-selected: 0.34; +} + +/* Categorical chart palette, dark mode */ +[data-mode="dark"] { + --ds-chart-1: #9a7efb; /* violet */ + --ds-chart-2: #dc5453; /* vermilion */ + --ds-chart-3: #ffebeb; /* wine */ + --ds-chart-4: #7f6d99; /* lavender */ + --ds-chart-5: #a7b9fe; /* indigo */ + --ds-chart-6: #5ab09a; /* green */ + --ds-chart-7: #9a5060; /* rose */ + --ds-chart-8: #ffb045; /* amber */ + --ds-chart-9: #076cd0; /* blue */ + --ds-chart-10: #b8a461; /* khaki */ + --ds-chart-11: #bded9a; /* fern */ + --ds-chart-12: #beabba; /* plum */ + + --ds-chart-1-channel: 154 126 251; + --ds-chart-2-channel: 220 84 83; + --ds-chart-3-channel: 255 235 235; + --ds-chart-4-channel: 127 109 153; + --ds-chart-5-channel: 167 185 254; + --ds-chart-6-channel: 90 176 154; + --ds-chart-7-channel: 154 80 96; + --ds-chart-8-channel: 255 176 69; + --ds-chart-9-channel: 7 108 208; + --ds-chart-10-channel: 184 164 97; + --ds-chart-11-channel: 189 237 154; + --ds-chart-12-channel: 190 171 186; +} diff --git a/src/themes/DiamondDSTheme.ts b/src/themes/DiamondDSTheme.ts index 89d8fe65..51a37793 100644 --- a/src/themes/DiamondDSTheme.ts +++ b/src/themes/DiamondDSTheme.ts @@ -20,6 +20,7 @@ import "@fontsource-variable/outfit"; import "@fontsource/ibm-plex-mono/latin-400.css"; import "@fontsource/ibm-plex-mono/latin-600.css"; import "../styles/diamondDS/DiamondDSTokens.css"; +import "../styles/diamondDS/DiamondDSChartTokens.css"; import "../styles/diamondDS/DiamondDSTypography.css"; // Enables `theme.vars` typings for MUI CSS variable themes. diff --git a/tools/chart-palette/build.mjs b/tools/chart-palette/build.mjs new file mode 100644 index 00000000..97e0b8e1 --- /dev/null +++ b/tools/chart-palette/build.mjs @@ -0,0 +1,45 @@ +// Regenerates the chart tokens, JSON export, validation report and preview from palette.mjs. +// calc/ computes and validates the colours; present/ turns the results into files. +// `--check` writes nothing and fails if the committed outputs are stale or a gated check fails. +/* global process, console */ +import { readFileSync, writeFileSync } from "node:fs"; +import { validate } from "./calc/validate.mjs"; +import { buildCss } from "./present/css.mjs"; +import { buildJson } from "./present/json.mjs"; +import { renderPreview } from "./present/preview.mjs"; +import { buildMarkdown } from "./present/report.mjs"; + +const out = (name) => new URL(name, import.meta.url); + +const report = validate(); +const css = buildCss(); +const files = { + "../../src/styles/diamondDS/DiamondDSChartTokens.css": css, + "chart-palette.json": buildJson(report), + "validation.md": buildMarkdown(report), +}; + +if (process.argv.includes("--check")) { + const stale = Object.entries(files).filter(([name, text]) => { + try { + return readFileSync(out(name), "utf8").replace(/\r\n/g, "\n") !== text; + } catch { + return true; + } + }); + stale.forEach(([name]) => console.error(`stale: ${name}`)); + report.checks + .filter((c) => c.gate && !c.pass) + .forEach((c) => console.error(`failed: ${c.label}`)); + process.exit(stale.length || !report.ok ? 1 : 0); +} + +Object.entries({ + ...files, + // A local page for looking at the palette; it is not committed or checked. + "render-check.html": renderPreview(report), +}).forEach(([name, text]) => writeFileSync(out(name), text)); +report.checks.forEach((c) => + console.log(`${c.gate ? (c.pass ? "pass" : "FAIL") : "note"} ${c.label}`), +); +process.exit(report.ok ? 0 : 1); diff --git a/tools/chart-palette/calc/colour.mjs b/tools/chart-palette/calc/colour.mjs new file mode 100644 index 00000000..e32efe3a --- /dev/null +++ b/tools/chart-palette/calc/colour.mjs @@ -0,0 +1,217 @@ +// Colour maths for the chart palette checks: sRGB, OKLab/OKLCH, CIEDE2000, +// WCAG contrast and Machado et al. (2009) CVD simulation at severity 1.0. + +const clamp01 = (x) => Math.min(1, Math.max(0, x)); + +export const hexToRgb = (hex) => { + const h = hex.replace("#", ""); + return [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16)); +}; + +export const rgbToHex = (rgb) => + "#" + + rgb + .map((v) => + Math.round(Math.min(255, Math.max(0, v))) + .toString(16) + .padStart(2, "0"), + ) + .join(""); + +const toLinear = (c) => { + const v = c / 255; + return v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4; +}; +const fromLinear = (v) => { + const c = clamp01(v); + return 255 * (c <= 0.0031308 ? 12.92 * c : 1.055 * c ** (1 / 2.4) - 0.055); +}; + +export const hexToLinear = (hex) => hexToRgb(hex).map(toLinear); +export const linearToHex = (lin) => rgbToHex(lin.map(fromLinear)); + +export const linearToOklab = ([r, g, b]) => { + const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b); + const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b); + const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b); + return [ + 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s, + 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s, + 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s, + ]; +}; + +export const hexToOklch = (hex) => { + const [L, a, b] = linearToOklab(hexToLinear(hex)); + const C = Math.hypot(a, b); + const h = ((Math.atan2(b, a) * 180) / Math.PI + 360) % 360; + return { L, C, h }; +}; + +// CIE Lab (D65) for CIEDE2000. +const linearToLab = ([r, g, b]) => { + const X = 0.4124564 * r + 0.3575761 * g + 0.1804375 * b; + const Y = 0.2126729 * r + 0.7151522 * g + 0.072175 * b; + const Z = 0.0193339 * r + 0.119192 * g + 0.9503041 * b; + const f = (t) => + t > 216 / 24389 ? Math.cbrt(t) : ((24389 / 27) * t + 16) / 116; + const fx = f(X / 0.95047); + const fy = f(Y); + const fz = f(Z / 1.08883); + return [116 * fy - 16, 500 * (fx - fy), 200 * (fy - fz)]; +}; + +const rad = (d) => (d * Math.PI) / 180; +const deg = (r) => (r * 180) / Math.PI; + +export const deltaE2000Lab = ([L1, a1, b1], [L2, a2, b2]) => { + const C1 = Math.hypot(a1, b1); + const C2 = Math.hypot(a2, b2); + const Cbar = (C1 + C2) / 2; + const G = 0.5 * (1 - Math.sqrt(Cbar ** 7 / (Cbar ** 7 + 25 ** 7))); + const a1p = (1 + G) * a1; + const a2p = (1 + G) * a2; + const C1p = Math.hypot(a1p, b1); + const C2p = Math.hypot(a2p, b2); + const h1p = C1p === 0 ? 0 : (deg(Math.atan2(b1, a1p)) + 360) % 360; + const h2p = C2p === 0 ? 0 : (deg(Math.atan2(b2, a2p)) + 360) % 360; + const dLp = L2 - L1; + const dCp = C2p - C1p; + let dhp = 0; + if (C1p * C2p !== 0) { + dhp = h2p - h1p; + if (dhp > 180) dhp -= 360; + else if (dhp < -180) dhp += 360; + } + const dHp = 2 * Math.sqrt(C1p * C2p) * Math.sin(rad(dhp / 2)); + const Lbp = (L1 + L2) / 2; + const Cbp = (C1p + C2p) / 2; + let hbp = h1p + h2p; + if (C1p * C2p !== 0) { + hbp = + Math.abs(h1p - h2p) <= 180 + ? hbp / 2 + : h1p + h2p < 360 + ? (hbp + 360) / 2 + : (hbp - 360) / 2; + } + const T = + 1 - + 0.17 * Math.cos(rad(hbp - 30)) + + 0.24 * Math.cos(rad(2 * hbp)) + + 0.32 * Math.cos(rad(3 * hbp + 6)) - + 0.2 * Math.cos(rad(4 * hbp - 63)); + const dTheta = 30 * Math.exp(-(((hbp - 275) / 25) ** 2)); + const Rc = 2 * Math.sqrt(Cbp ** 7 / (Cbp ** 7 + 25 ** 7)); + const Sl = 1 + (0.015 * (Lbp - 50) ** 2) / Math.sqrt(20 + (Lbp - 50) ** 2); + const Sc = 1 + 0.045 * Cbp; + const Sh = 1 + 0.015 * Cbp * T; + const Rt = -Math.sin(rad(2 * dTheta)) * Rc; + return Math.sqrt( + (dLp / Sl) ** 2 + + (dCp / Sc) ** 2 + + (dHp / Sh) ** 2 + + Rt * (dCp / Sc) * (dHp / Sh), + ); +}; + +// Machado, Oliveira & Fernandes (2009), severity 1.0, applied in linear sRGB. +const MACHADO = { + protan: [ + [0.152286, 1.052583, -0.204868], + [0.114503, 0.786281, 0.099216], + [-0.003882, -0.048116, 1.051998], + ], + deutan: [ + [0.367322, 0.860646, -0.227968], + [0.280085, 0.672501, 0.047413], + [-0.01182, 0.04294, 0.968881], + ], + tritan: [ + [1.255528, -0.076749, -0.178779], + [-0.078411, 0.930809, 0.147602], + [0.004733, 0.691367, 0.3039], + ], +}; + +export const simulateLinear = (lin, vision) => { + if (vision === "normal") return lin; + const m = MACHADO[vision]; + return m.map((row) => + clamp01(row[0] * lin[0] + row[1] * lin[1] + row[2] * lin[2]), + ); +}; + +export const labUnder = (hex, vision) => + linearToLab(simulateLinear(hexToLinear(hex), vision)); + +export const deltaE = (hexA, hexB, vision = "normal") => + deltaE2000Lab(labUnder(hexA, vision), labUnder(hexB, vision)); + +export const CVD_TYPES = ["protan", "deutan", "tritan"]; + +const luminance = ([r, g, b]) => 0.2126 * r + 0.7152 * g + 0.0722 * b; + +export const simulatedHex = (hex, vision) => + linearToHex(simulateLinear(hexToLinear(hex), vision)); + +export const greyHex = (hex) => + linearToHex(Array(3).fill(luminance(hexToLinear(hex)))); + +// Smallest difference between two hue angles, in degrees. +export const hueGap = (a, b) => { + const d = Math.abs(a - b) % 360; + return Math.min(d, 360 - d); +}; + +export const contrast = (hexA, hexB) => { + const [hi, lo] = [ + luminance(hexToLinear(hexA)), + luminance(hexToLinear(hexB)), + ].sort((a, b) => b - a); + return (hi + 0.05) / (lo + 0.05); +}; + +// Colour `fg` at `alpha` composited over opaque `bg`, as hex. +export const composite = (fg, bg, alpha) => { + const f = hexToRgb(fg); + const b = hexToRgb(bg); + return rgbToHex(f.map((v, i) => v * alpha + b[i] * (1 - alpha))); +}; + +// Smallest alpha (0.01 steps) at which `fg` over `bg` reaches `ratio` against `bg`; null if never. +export const minAlphaForContrast = (fg, bg, ratio = 3) => { + for (let a = 1; a <= 100; a++) { + if (contrast(composite(fg, bg, a / 100), bg) >= ratio) return a / 100; + } + return null; +}; + +// Distance for "is this the same colour family": OKLab ×100 with lightness +// discounted, since a mode's tuning legitimately shifts lightness. +export const identityDistance = (hexA, hexB) => { + const [L1, a1, b1] = linearToOklab(hexToLinear(hexA)); + const [L2, a2, b2] = linearToOklab(hexToLinear(hexB)); + return 100 * Math.hypot(0.4 * (L1 - L2), a1 - a2, b1 - b2); +}; + +// CIE L* (0-100), for greyscale comparisons. +export const lstar = (hex) => labUnder(hex, "normal")[0]; + +// APCA-W3 0.0.98G Lc of text colour `txt` on background `bg` (negative = light text on dark). +export const apcaLc = (txt, bg) => { + const Y = (hex) => { + const [r, g, b] = hexToRgb(hex).map((v) => (v / 255) ** 2.4); + const y = 0.2126729 * r + 0.7151522 * g + 0.072175 * b; + return y < 0.022 ? y + (0.022 - y) ** 1.414 : y; + }; + const yt = Y(txt); + const yb = Y(bg); + if (Math.abs(yb - yt) < 0.0005) return 0; + if (yb > yt) { + const s = (yb ** 0.56 - yt ** 0.57) * 1.14; + return s < 0.1 ? 0 : (s - 0.027) * 100; + } + const s = (yb ** 0.65 - yt ** 0.62) * 1.14; + return s > -0.1 ? 0 : (s + 0.027) * 100; +}; diff --git a/tools/chart-palette/calc/tokens.mjs b/tools/chart-palette/calc/tokens.mjs new file mode 100644 index 00000000..cb2777d9 --- /dev/null +++ b/tools/chart-palette/calc/tokens.mjs @@ -0,0 +1,83 @@ +import { readFileSync } from "node:fs"; + +const TOKEN_FILE = new URL( + "../../../src/styles/diamondDS/DiamondDSTokens.css", + import.meta.url, +); + +// The token block is the rule whose selector starts a line, so comments that mention the +// selector, or declarations inside other rules, are never read as it. +const parseBlock = (css, selector) => { + const escaped = selector.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); + const match = new RegExp(`^${escaped}\\s*\\{`, "m").exec(css); + if (!match) throw new Error(`DiamondDSTokens.css: no ${selector} block`); + const bodyStart = match.index + match[0].length; + const body = css.slice(bodyStart, css.indexOf("\n}", bodyStart)); + const tokens = {}; + for (const [, name, value] of body.matchAll(/(--ds-[\w-]+):\s*([^;]+);/g)) { + tokens[name] = value.trim(); + } + return tokens; +}; + +export const readDsTokens = () => { + const css = readFileSync(TOKEN_FILE, "utf8"); + return { + light: parseBlock(css, '[data-mode="light"]'), + dark: parseBlock(css, '[data-mode="dark"]'), + }; +}; + +// Surfaces a series mark must read against. Charts are drawn on the surface or the +// page background; raised is the menu/popover band (elevation 8) that hover cards and +// tooltips sit on, and dialog (elevation 16) is the highest surface that shows series colours. +export const SURFACE_TOKENS = { + surface: "--ds-surface", + background: "--ds-background", + raised: "--ds-elevation-8", + dialog: "--ds-elevation-16", +}; + +// The surfaces a chart may be drawn on, where the hard 3:1 applies. +export const CHART_SURFACES = ["surface", "background"]; + +// Colours a series must not be mistaken for: statuses and primary/brand, in +// every role that can appear as a mark or text colour. +const RESERVED_INTENTS = [ + "danger", + "success", + "warning", + "info", + "primary", + "brand", +]; +const RESERVED_ROLES = ["", "-emphasis", "-accent", "-solid"]; + +export const reservedTokenNames = () => + RESERVED_INTENTS.flatMap((intent) => + RESERVED_ROLES.map((role) => `--ds-${intent}${role}`), + ); + +const need = (tokens, mode, name) => { + const value = tokens[mode][name]; + if (!/^#[0-9a-f]{6}$/i.test(value ?? "")) + throw new Error(`DiamondDSTokens.css: ${mode} ${name} is not a hex colour`); + return value; +}; + +export const surfacesFor = (tokens, mode) => + Object.fromEntries( + Object.entries(SURFACE_TOKENS).map(([key, name]) => [ + key, + need(tokens, mode, name), + ]), + ); + +export const reservedFor = (tokens, mode) => + reservedTokenNames().map((name) => ({ + name, + hex: need(tokens, mode, name), + })); + +export const onSurfaceFor = (tokens, mode) => + need(tokens, mode, "--ds-on-surface"); diff --git a/tools/chart-palette/calc/validate.mjs b/tools/chart-palette/calc/validate.mjs new file mode 100644 index 00000000..872435a1 --- /dev/null +++ b/tools/chart-palette/calc/validate.mjs @@ -0,0 +1,327 @@ +import { + apcaLc, + composite, + contrast, + CVD_TYPES, + deltaE, + hexToOklch, + hueGap, + identityDistance, + lstar, + minAlphaForContrast, +} from "./colour.mjs"; +import { OPACITY, SLOTS, THRESHOLDS as T } from "../palette.mjs"; +import { MARKERS } from "../markers.mjs"; +import { + CHART_SURFACES, + onSurfaceFor, + readDsTokens, + reservedFor, + surfacesFor, +} from "./tokens.mjs"; + +export const MODES = ["light", "dark"]; + +// Pairs closer than this in L* look alike in greyscale and print. +export const GREY_CLOSE = 5; + +const LABEL_FILLS = Object.entries(OPACITY) + .filter(([k]) => k.startsWith("label")) + .map(([, v]) => v); + +const min = (xs) => Math.min(...xs); +// Lowest fill opacity reaching the contrast gate on every chart surface; null if none does. +const minAlphaOnChartSurfaces = (hex, surfaces) => { + const alphas = CHART_SURFACES.map((k) => + minAlphaForContrast(hex, surfaces[k]), + ); + return alphas.includes(null) ? null : Math.max(...alphas); +}; +const mapValues = (obj, fn) => + Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, fn(v, k)])); + +// Values stay unrounded here so every gate compares the real figure; presenters round. +const measureMode = (tokens, mode) => { + const surfaces = surfacesFor(tokens, mode); + const reserved = reservedFor(tokens, mode); + const hexes = SLOTS.map((s) => s[mode]); + const onSurface = onSurfaceFor(tokens, mode); + + const slots = hexes.map((hex, i) => { + const lch = hexToOklch(hex); + const onSurfaces = mapValues(surfaces, (bg) => contrast(hex, bg)); + const labelText = (keys) => + min( + keys.flatMap((k) => + LABEL_FILLS.map((o) => + contrast(onSurface, composite(hex, surfaces[k], o)), + ), + ), + ); + const nearest = reserved + .map((r) => { + const o = hexToOklch(r.hex); + return { + token: r.name, + deltaE: deltaE(hex, r.hex), + hueGap: + lch.C > T.neutralChroma && o.C > T.neutralChroma + ? hueGap(lch.h, o.h) + : null, + }; + }) + .sort((a, b) => a.deltaE - b.deltaE); + const fillContrast = (opacity) => + min( + Object.values(surfaces).map((bg) => + contrast(composite(hex, bg, opacity), bg), + ), + ); + return { + slot: i + 1, + oklch: lch, + lstar: lstar(hex), + contrast: onSurfaces, + dataFillContrast: min( + CHART_SURFACES.map((k) => + contrast(composite(hex, surfaces[k], OPACITY.data), surfaces[k]), + ), + ), + minAlpha: minAlphaOnChartSurfaces(hex, surfaces), + labelTextContrast: labelText(CHART_SURFACES), + labelTextContrastAll: labelText(Object.keys(surfaces)), + fillContrast: { + area: fillContrast(OPACITY.area), + band: fillContrast(OPACITY.band), + }, + readsAsText: Object.entries(surfaces).every( + ([k, bg]) => + onSurfaces[k] >= T.textContrast && + Math.abs(apcaLc(hex, bg)) >= T.textLc, + ), + nearestReserved: nearest[0], + minHueGap: min(nearest.map((n) => n.hueGap ?? 360)), + }; + }); + + const pairs = []; + for (let i = 0; i < hexes.length; i++) { + for (let j = i + 1; j < hexes.length; j++) { + pairs.push({ + a: i + 1, + b: j + 1, + normal: deltaE(hexes[i], hexes[j]), + ...Object.fromEntries( + CVD_TYPES.map((v) => [v, deltaE(hexes[i], hexes[j], v)]), + ), + }); + } + } + + const worst = (list) => + Object.fromEntries( + ["normal", ...CVD_TYPES].map((v) => { + const p = list.reduce((m, q) => (q[v] < m[v] ? q : m)); + return [v, { value: p[v], pair: [p.a, p.b] }]; + }), + ); + const prefix = Array.from({ length: hexes.length - 1 }, (_, k) => { + const n = k + 2; + return { + slots: n, + ...mapValues(worst(pairs.filter((p) => p.b <= n)), (w) => w.value), + }; + }); + + const greyClose = pairs + .map((p) => ({ + a: p.a, + b: p.b, + dL: Math.abs(slots[p.a - 1].lstar - slots[p.b - 1].lstar), + })) + .filter((g) => g.dL < GREY_CLOSE); + + return { + surfaces, + onSurface, + slots, + pairs, + greyClose, + textSlots: slots.filter((s) => s.readsAsText).map((s) => s.slot), + worstCore: worst(pairs.filter((p) => p.b <= T.coreSlots)), + worstAll: worst(pairs), + prefix, + }; +}; + +const weakPairs = (modes) => + modes.light.pairs + .map((light, k) => ({ light, dark: modes.dark.pairs[k] })) + .filter(({ light, dark }) => + [light, dark].some( + (p) => p.normal < T.normal || CVD_TYPES.some((v) => p[v] < T.cvdWeak), + ), + ) + .map(({ light, dark }) => { + const worstOf = (p) => { + const type = CVD_TYPES.reduce((m, v) => (p[v] < p[m] ? v : m)); + return { type, value: p[type] }; + }; + return { + a: light.a, + b: light.b, + light: worstOf(light), + dark: worstOf(dark), + }; + }); + +export const validate = () => { + const tokens = readDsTokens(); + const modes = Object.fromEntries( + MODES.map((m) => [m, measureMode(tokens, m)]), + ); + const everySlot = (test) => + MODES.every((m) => modes[m].slots.every((s) => test(s))); + const hueGaps = SLOTS.map((_, i) => + hueGap(modes.light.slots[i].oklch.h, modes.dark.slots[i].oklch.h), + ); + + const chromatic = SLOTS.map((_, i) => i); + const isOwn = (i, from, to) => { + const own = identityDistance(SLOTS[i][from], SLOTS[i][to]); + return chromatic.every( + (j) => j === i || identityDistance(SLOTS[i][from], SLOTS[j][to]) > own, + ); + }; + const identityFails = chromatic + .filter((i) => !isOwn(i, "light", "dark") || !isOwn(i, "dark", "light")) + .map((i) => i + 1); + + const underTarget = Object.fromEntries( + MODES.map((m) => [ + m, + modes[m].slots + .map((s) => ({ + slot: s.slot, + surfaces: Object.entries(s.contrast) + .filter(([, c]) => c < T.contrast) + .map(([k]) => k), + })) + .filter((s) => s.surfaces.length), + ]), + ); + + // Slots within reservedClose of a status or brand colour in some mode, closest first. + const nearStatus = SLOTS.map((s, i) => { + const closest = MODES.map((m) => modes[m].slots[i].nearestReserved).reduce( + (a, b) => (b.deltaE < a.deltaE ? b : a), + ); + return { slot: i + 1, name: s.name, ...closest }; + }) + .filter((n) => n.deltaE < T.reservedClose) + .sort((a, b) => a.deltaE - b.deltaE); + + const worstCvd = (which, m) => + min(CVD_TYPES.map((v) => modes[m][which][v].value)); + + const checks = [ + { + id: "contrast-surface", + gate: true, + label: `Every colour ≥ ${T.contrast}:1 on the chart surface and the page background, both modes`, + pass: everySlot((s) => + CHART_SURFACES.every((k) => s.contrast[k] >= T.contrast), + ), + }, + { + id: "contrast-floor", + gate: true, + label: `Every colour ≥ ${T.contrastFloor}:1 on the raised (elevation 8) and dialog (elevation 16) surfaces, both modes`, + pass: everySlot((s) => + Object.values(s.contrast).every((c) => c >= T.contrastFloor), + ), + }, + { + id: "data-fill", + gate: true, + label: `Data fills (opacity ${OPACITY.data}) keep ≥ ${T.contrast}:1 on the chart surface and the page background once composited`, + pass: everySlot((s) => s.dataFillContrast >= T.contrast), + }, + { + id: "label-text", + gate: true, + label: `Text in --ds-on-surface keeps ≥ ${T.textContrast}:1 on a series-coloured label tint (opacities ${LABEL_FILLS.join(", ")}), both modes`, + pass: everySlot((s) => s.labelTextContrast >= T.textContrast), + }, + { + id: "normal", + gate: true, + label: `ΔE2000 ≥ ${T.normal} between any two of ${SLOTS.length} slots, normal vision`, + pass: MODES.every((m) => modes[m].worstAll.normal.value >= T.normal), + }, + { + id: "cvd-core", + gate: true, + label: `ΔE2000 ≥ ${T.cvd} between slots 1-${T.coreSlots} under protan, deutan and tritan`, + pass: MODES.every((m) => worstCvd("worstCore", m) >= T.cvd), + }, + { + id: "cvd-all", + gate: true, + label: `ΔE2000 ≥ ${T.cvdAll} between any two of ${SLOTS.length} slots under protan, deutan and tritan (the marker carries pairs below ${T.cvdWeak})`, + pass: MODES.every((m) => worstCvd("worstAll", m) >= T.cvdAll), + }, + { + id: "chroma-floor", + gate: true, + label: `Every slot has chroma ≥ ${T.minChroma} in both modes`, + pass: SLOTS.every((_, i) => + MODES.every((m) => modes[m].slots[i].oklch.C >= T.minChroma), + ), + }, + { + id: "hue-identity", + gate: true, + label: `Each chromatic slot keeps its hue within ${T.hueDrift}° across modes`, + pass: chromatic.every((i) => hueGaps[i] <= T.hueDrift), + }, + { + id: "cross-mode-nearest", + gate: false, + label: + "Each slot's dark value is nearest to its own light value (informational, not gated; see Light and dark identity)", + pass: identityFails.length === 0, + }, + { + id: "second-channel", + gate: true, + label: "Every slot has its own marker shape; all lines are solid", + pass: + new Set(SLOTS.map((s) => s.marker)).size === SLOTS.length && + SLOTS.every((s) => MARKERS.includes(s.marker)), + }, + { + id: "reserved", + gate: false, + label: `${nearStatus.length} of ${SLOTS.length} slots sit within ΔE ${T.reservedClose} of a status or brand colour in at least one mode (slots ${ + nearStatus + .map((n) => n.slot) + .sort((a, b) => a - b) + .join(", ") || "none" + }); recorded, not gated`, + pass: nearStatus.length === 0, + }, + ]; + + return { + thresholds: T, + modes, + weakPairs: weakPairs(modes), + underTarget, + hueGaps, + identityFails, + nearStatus, + checks, + ok: checks.every((c) => !c.gate || c.pass), + }; +}; diff --git a/tools/chart-palette/chart-palette.json b/tools/chart-palette/chart-palette.json new file mode 100644 index 00000000..6ea39aab --- /dev/null +++ b/tools/chart-palette/chart-palette.json @@ -0,0 +1,537 @@ +{ + "description": "Categorical chart palette, 12 slots, light and dark. Generated by build.mjs.", + "surfaces": { + "light": { + "surface": "#ffffff", + "background": "#f6f6f9", + "raised": "#edf0f4", + "dialog": "#e6e9f0" + }, + "dark": { + "surface": "#161820", + "background": "#0e1017", + "raised": "#232734", + "dialog": "#2c3140" + } + }, + "fillOpacity": { + "area": 0.16, + "band": 0.28, + "data": 1, + "region": 0.14, + "region-hover": 0.24, + "region-selected": 0.34, + "label": 0.22, + "label-hover": 0.28, + "label-selected": 0.34 + }, + "thresholds": { + "contrast": 3, + "contrastFloor": 2.25, + "textContrast": 4.5, + "coreSlots": 8 + }, + "secondChannel": { + "minLineWidth": 1.75, + "minMarkerSize": 8, + "markerHalo": 1.5 + }, + "slots": [ + { + "slot": 1, + "name": "violet", + "token": "--ds-chart-1", + "marker": "plus", + "light": { + "hex": "#8133d6", + "rgb": [ + 129, + 51, + 214 + ], + "channel": "129 51 214", + "simulated": { + "protan": "#0060db", + "deutan": "#005fd3", + "tritan": "#6d5e83" + } + }, + "dark": { + "hex": "#9a7efb", + "rgb": [ + 154, + 126, + 251 + ], + "channel": "154 126 251", + "simulated": { + "protan": "#4b94ff", + "deutan": "#4f8ff8", + "tritan": "#8097b1" + } + } + }, + { + "slot": 2, + "name": "vermilion", + "token": "--ds-chart-2", + "marker": "square", + "light": { + "hex": "#ed604f", + "rgb": [ + 237, + 96, + 79 + ], + "channel": "237 96 79", + "simulated": { + "protan": "#857b4d", + "deutan": "#a8994b", + "tritan": "#ff425d" + } + }, + "dark": { + "hex": "#dc5453", + "rgb": [ + 220, + 84, + 83 + ], + "channel": "220 84 83", + "simulated": { + "protan": "#776f52", + "deutan": "#998c4f", + "tritan": "#f13855" + } + } + }, + { + "slot": 3, + "name": "wine", + "token": "--ds-chart-3", + "marker": "diamond", + "light": { + "hex": "#610c12", + "rgb": [ + 97, + 12, + 18 + ], + "channel": "97 12 18", + "simulated": { + "protan": "#282311", + "deutan": "#3c350f", + "tritan": "#6c000f" + } + }, + "dark": { + "hex": "#ffebeb", + "rgb": [ + 255, + 235, + 235 + ], + "channel": "255 235 235", + "simulated": { + "protan": "#eeedeb", + "deutan": "#f3f1eb", + "tritan": "#ffe9eb" + } + } + }, + { + "slot": 4, + "name": "lavender", + "token": "--ds-chart-4", + "marker": "triangle", + "light": { + "hex": "#8a8ab9", + "rgb": [ + 138, + 138, + 185 + ], + "channel": "138 138 185", + "simulated": { + "protan": "#7d90bb", + "deutan": "#7c8db8", + "tritan": "#7f929a" + } + }, + "dark": { + "hex": "#7f6d99", + "rgb": [ + 127, + 109, + 153 + ], + "channel": "127 109 153", + "simulated": { + "protan": "#64749b", + "deutan": "#677598", + "tritan": "#7b737d" + } + } + }, + { + "slot": 5, + "name": "indigo", + "token": "--ds-chart-5", + "marker": "circle", + "light": { + "hex": "#1e3f80", + "rgb": [ + 30, + 63, + 128 + ], + "channel": "30 63 128", + "simulated": { + "protan": "#1a4682", + "deutan": "#003d7f", + "tritan": "#004e59" + } + }, + "dark": { + "hex": "#a7b9fe", + "rgb": [ + 167, + 185, + 254 + ], + "channel": "167 185 254", + "simulated": { + "protan": "#a3bfff", + "deutan": "#9cb8fc", + "tritan": "#8ec6d1" + } + } + }, + { + "slot": 6, + "name": "green", + "token": "--ds-chart-6", + "marker": "triangleDown", + "light": { + "hex": "#316f5e", + "rgb": [ + 49, + 111, + 94 + ], + "channel": "49 111 94", + "simulated": { + "protan": "#6c685d", + "deutan": "#62615f", + "tritan": "#13706a" + } + }, + "dark": { + "hex": "#5ab09a", + "rgb": [ + 90, + 176, + 154 + ], + "channel": "90 176 154", + "simulated": { + "protan": "#aba799", + "deutan": "#9d9d9c", + "tritan": "#36b2a9" + } + } + }, + { + "slot": 7, + "name": "rose", + "token": "--ds-chart-7", + "marker": "triangleRing", + "light": { + "hex": "#b67886", + "rgb": [ + 182, + 120, + 134 + ], + "channel": "182 120 134", + "simulated": { + "protan": "#818286", + "deutan": "#908e85", + "tritan": "#c1747d" + } + }, + "dark": { + "hex": "#9a5060", + "rgb": [ + 154, + 80, + 96 + ], + "channel": "154 80 96", + "simulated": { + "protan": "#5d5e60", + "deutan": "#706c5e", + "tritan": "#a54956" + } + } + }, + { + "slot": 8, + "name": "amber", + "token": "--ds-chart-8", + "marker": "star", + "light": { + "hex": "#a25500", + "rgb": [ + 162, + 85, + 0 + ], + "channel": "162 85 0", + "simulated": { + "protan": "#6c5e00", + "deutan": "#7f7000", + "tritan": "#b24348" + } + }, + "dark": { + "hex": "#ffb045", + "rgb": [ + 255, + 176, + 69 + ], + "channel": "255 176 69", + "simulated": { + "protan": "#cbb537", + "deutan": "#dec848", + "tritan": "#ff9c9a" + } + } + }, + { + "slot": 9, + "name": "blue", + "token": "--ds-chart-9", + "marker": "cross", + "light": { + "hex": "#318ff8", + "rgb": [ + 49, + 143, + 248 + ], + "channel": "49 143 248", + "simulated": { + "protan": "#5a98fc", + "deutan": "#3386f6", + "tritan": "#00a8b7" + } + }, + "dark": { + "hex": "#076cd0", + "rgb": [ + 7, + 108, + 208 + ], + "channel": "7 108 208", + "simulated": { + "protan": "#2f76d4", + "deutan": "#0065ce", + "tritan": "#008494" + } + } + }, + { + "slot": 10, + "name": "khaki", + "token": "--ds-chart-10", + "marker": "diamondRing", + "light": { + "hex": "#786941", + "rgb": [ + 120, + 105, + 65 + ], + "channel": "120 105 65", + "simulated": { + "protan": "#71683e", + "deutan": "#756c42", + "tritan": "#80635f" + } + }, + "dark": { + "hex": "#b8a461", + "rgb": [ + 184, + 164, + 97 + ], + "channel": "184 164 97", + "simulated": { + "protan": "#b1a15c", + "deutan": "#b6a863", + "tritan": "#c49b94" + } + } + }, + { + "slot": 11, + "name": "fern", + "token": "--ds-chart-11", + "marker": "squareRing", + "light": { + "hex": "#589704", + "rgb": [ + 88, + 151, + 4 + ], + "channel": "88 151 4", + "simulated": { + "protan": "#9e8a00", + "deutan": "#95851e", + "tritan": "#589080" + } + }, + "dark": { + "hex": "#bded9a", + "rgb": [ + 189, + 237, + 154 + ], + "channel": "189 237 154", + "simulated": { + "protan": "#f4e194", + "deutan": "#ecde9e", + "tritan": "#bee7d8" + } + } + }, + { + "slot": 12, + "name": "plum", + "token": "--ds-chart-12", + "marker": "ring", + "light": { + "hex": "#9c5894", + "rgb": [ + 156, + 88, + 148 + ], + "channel": "156 88 148", + "simulated": { + "protan": "#566a96", + "deutan": "#687392", + "tritan": "#a15d6f" + } + }, + "dark": { + "hex": "#beabba", + "rgb": [ + 190, + 171, + 186 + ], + "channel": "190 171 186", + "simulated": { + "protan": "#abafbb", + "deutan": "#afb1b9", + "tritan": "#c0acb0" + } + } + } + ], + "nearStatus": [ + { + "slot": 5, + "name": "indigo", + "token": "--ds-brand", + "deltaE": 1 + }, + { + "slot": 8, + "name": "amber", + "token": "--ds-warning", + "deltaE": 1.7 + }, + { + "slot": 2, + "name": "vermilion", + "token": "--ds-danger-solid", + "deltaE": 5.2 + }, + { + "slot": 9, + "name": "blue", + "token": "--ds-primary-solid", + "deltaE": 6.1 + } + ], + "weakPairs": [ + { + "slots": [ + 2, + 10 + ], + "names": [ + "vermilion", + "khaki" + ] + }, + { + "slots": [ + 2, + 11 + ], + "names": [ + "vermilion", + "fern" + ] + }, + { + "slots": [ + 6, + 12 + ], + "names": [ + "green", + "plum" + ] + }, + { + "slots": [ + 8, + 10 + ], + "names": [ + "amber", + "khaki" + ] + }, + { + "slots": [ + 8, + 11 + ], + "names": [ + "amber", + "fern" + ] + }, + { + "slots": [ + 10, + 12 + ], + "names": [ + "khaki", + "plum" + ] + } + ] +} diff --git a/tools/chart-palette/chartPalette.test.js b/tools/chart-palette/chartPalette.test.js new file mode 100644 index 00000000..c8c619eb --- /dev/null +++ b/tools/chart-palette/chartPalette.test.js @@ -0,0 +1,15 @@ +// @vitest-environment node +import { describe, expect, it } from "vitest"; +import { spawnSync } from "node:child_process"; +import process from "node:process"; +import { fileURLToPath } from "node:url"; + +describe("chart palette", () => { + it("passes the gated checks and the committed outputs are current", () => { + const build = fileURLToPath(new URL("./build.mjs", import.meta.url)); + const result = spawnSync(process.execPath, [build, "--check"], { + encoding: "utf8", + }); + expect(result.status, result.stderr).toBe(0); + }); +}); diff --git a/tools/chart-palette/markers.mjs b/tools/chart-palette/markers.mjs new file mode 100644 index 00000000..6917c217 --- /dev/null +++ b/tools/chart-palette/markers.mjs @@ -0,0 +1,62 @@ +// Marker shapes: the second channel for telling series apart without colour. Shared by the +// validator (which shapes exist), the preview page and the Chart Colours docs page. +// Each shape is SVG markup centred on (0, 0), drawn in currentColor. The halo around filled +// shapes, and the fill of hollow ones, comes from --chart-halo (the surface colour). + +const R = 4.5; +export const HALO_WIDTH = 1.5; +const HALO = "var(--chart-halo, var(--ds-surface))"; + +const filled = `fill="currentColor" stroke="${HALO}" stroke-width="${HALO_WIDTH}"`; +const stroked = `fill="none" stroke="currentColor" stroke-width="2"`; +const hollow = `fill="${HALO}" stroke="currentColor" stroke-width="2"`; + +const polygon = (points, attrs) => + ``; +const triangle = (s) => [ + [0, -s], + [s, s * 0.8], + [-s, s * 0.8], +]; +const diamond = (s) => [ + [0, -s * 1.2], + [s * 1.2, 0], + [0, s * 1.2], + [-s * 1.2, 0], +]; +const star = Array.from({ length: 10 }, (_, i) => { + const a = (Math.PI / 5) * i - Math.PI / 2; + const q = i % 2 ? R * 0.75 : R * 1.7; + return [q * Math.cos(a), q * Math.sin(a)]; +}); +const rect = (r, attrs) => + ``; + +const SHAPES = { + circle: ``, + square: rect(R, filled), + triangle: polygon(triangle(R + 1), filled), + triangleDown: polygon( + triangle(R + 1).map(([x, y]) => [x, -y]), + filled, + ), + diamond: polygon(diamond(R), filled), + star: polygon(star, filled), + plus: ``, + cross: ``, + ring: ``, + squareRing: rect(R - 0.5, hollow), + triangleRing: polygon(triangle(R), `${hollow} stroke-linejoin="round"`), + diamondRing: polygon(diamond(R - 0.5), `${hollow} stroke-linejoin="round"`), +}; + +export const MARKERS = Object.keys(SHAPES); + +export const markerSvg = (shape) => { + if (!SHAPES[shape]) throw new Error(`Unknown marker shape: ${shape}`); + return SHAPES[shape]; +}; + +// One per shape, for in the preview page. +export const markerDefs = () => + MARKERS.map((m) => `${SHAPES[m]}`).join(""); diff --git a/tools/chart-palette/palette.mjs b/tools/chart-palette/palette.mjs new file mode 100644 index 00000000..ba7654bf --- /dev/null +++ b/tools/chart-palette/palette.mjs @@ -0,0 +1,136 @@ +// Source of truth for the categorical chart palette. Edit here, then run +// `node tools/chart-palette/build.mjs` to regenerate tokens, JSON and the validation report. + +// Each slot has a light and a dark value in the same hue family, each tuned to pass the checks +// in calc/validate.mjs on its own surfaces. +// Slot 3 (wine) is the near-black in light and near-white in dark; it still has a hue. +// Slots 1-8 are the core: colour alone separates them under colour-vision deficiency. +// Slots 9-12 are additional; pairs below the CVD floor are listed in validation.md. +// `marker` is the second channel; every line is solid. +export const SLOTS = [ + { + name: "violet", + light: "#8133d6", + dark: "#9a7efb", + marker: "plus", + }, + { + name: "vermilion", + light: "#ed604f", + dark: "#dc5453", + marker: "square", + }, + { + name: "wine", + light: "#610c12", + dark: "#ffebeb", + marker: "diamond", + }, + { + name: "lavender", + light: "#8a8ab9", + dark: "#7f6d99", + marker: "triangle", + }, + { + name: "indigo", + light: "#1e3f80", + dark: "#a7b9fe", + marker: "circle", + }, + { + name: "green", + light: "#316f5e", + dark: "#5ab09a", + marker: "triangleDown", + }, + { + name: "rose", + light: "#b67886", + dark: "#9a5060", + marker: "triangleRing", + }, + { + name: "amber", + light: "#a25500", + dark: "#ffb045", + marker: "star", + }, + { + name: "blue", + light: "#318ff8", + dark: "#076cd0", + marker: "cross", + }, + { + name: "khaki", + light: "#786941", + dark: "#b8a461", + marker: "diamondRing", + }, + { + name: "fern", + light: "#589704", + dark: "#bded9a", + marker: "squareRing", + }, + { + name: "plum", + light: "#9c5894", + dark: "#beabba", + marker: "ring", + }, +]; + +// Opacity applied to a series colour, e.g. rgb(var(--ds-chart-1-channel) / var(--ds-chart-fill-area)). +export const OPACITY = { + // Under a line that carries the data; decorative. + area: 0.16, + // Range band around a line; decorative only when the band also has a series-coloured edge. + band: 0.28, + // Bars, scatter points, heatmap cells: the fill is the data, so it stays opaque. + data: 1, + // Fill for a region drawn on an image, with a solid series-coloured border. + // Hover and selected raise the fill; selected also thickens the border. + region: 0.14, + "region-hover": 0.24, + "region-selected": 0.34, + // Background tint for a label next to a line, with neutral text on top. + // Hover and selected raise the tint; selected also thickens the border. + label: 0.22, + "label-hover": 0.28, + "label-selected": 0.34, +}; + +export const THRESHOLDS = { + // WCAG 1.4.11 on the surfaces charts are drawn on (--ds-surface, --ds-background). + contrast: 3, + // Floor on raised (tooltip, hover) and dialog surfaces. + // Slots under 3:1 there need labels or a data table. + contrastFloor: 2.25, + // ΔE2000 between any two slots, normal vision. + normal: 15, + // ΔE2000 between core slots under each simulated CVD type. + cvd: 13, + // Below this under some CVD type, a pair is "weak" and documented (any slot). + cvdWeak: 10, + // Hard floor for any pair of the 12 slots under any CVD type; the marker carries the rest. + cvdAll: 7, + coreSlots: 8, + // Max OKLCH hue drift for a chromatic slot between modes. + hueDrift: 20, + // Chroma below which a colour counts as grey when comparing hues. + neutralChroma: 0.04, + // A slot needs at least this much chroma in both modes for its hue to mean anything. + minChroma: 0.02, + // Recorded, not gated: a slot within this ΔE of a status or brand colour is called out. + reservedClose: 7, + // Series colour as text: WCAG ratio and APCA |Lc|. + textContrast: 4.5, + textLc: 60, +}; + +// Minimum rendering for the second channel to be usable by low-vision readers. +export const LINE = { width: 1.75, marker: 8 }; + +export const TOKEN_PREFIX = "--ds-chart"; diff --git a/tools/chart-palette/present/css.mjs b/tools/chart-palette/present/css.mjs new file mode 100644 index 00000000..6eab3d69 --- /dev/null +++ b/tools/chart-palette/present/css.mjs @@ -0,0 +1,33 @@ +import { OPACITY, SLOTS, THRESHOLDS, TOKEN_PREFIX } from "../palette.mjs"; +import { channel, tokenName } from "./format.mjs"; + +export const buildCss = () => { + const block = (mode, selector, extra = "") => + `${selector} {\n${SLOTS.map( + (s, i) => ` ${tokenName(i)}: ${s[mode]}; /* ${s.name} */`, + ).join("\n")}\n\n${SLOTS.map( + (s, i) => ` ${tokenName(i)}-channel: ${channel(s[mode])};`, + ).join("\n")}\n${extra}}\n`; + const opacity = `\n /* Fill opacities: rgb(var(${tokenName(0)}-channel) / var(${TOKEN_PREFIX}-fill-area)) */\n${Object.entries( + OPACITY, + ) + .map(([k, v]) => ` ${TOKEN_PREFIX}-fill-${k}: ${v};`) + .join("\n")}\n`; + return [ + "/* Generated by tools/chart-palette/build.mjs from palette.mjs. Do not edit by hand. */", + [ + "/*", + " Draw charts on --ds-surface or --ds-background", + ` (the colours are checked for ${THRESHOLDS.contrast}:1 contrast on both)`, + " and use series in order, --ds-chart-1 first.", + "", + ` Slots 1-${THRESHOLDS.coreSlots} are the core and stay separable under`, + ` colour-vision deficiency; ${THRESHOLDS.coreSlots + 1}-${SLOTS.length} are additional.`, + "*/", + ].join("\n") + "\n", + "/* Categorical chart palette, light mode */", + block("light", ':root,\n[data-mode="light"]', opacity), + "/* Categorical chart palette, dark mode */", + block("dark", '[data-mode="dark"]'), + ].join("\n"); +}; diff --git a/tools/chart-palette/present/format.mjs b/tools/chart-palette/present/format.mjs new file mode 100644 index 00000000..570a2ab9 --- /dev/null +++ b/tools/chart-palette/present/format.mjs @@ -0,0 +1,7 @@ +import { hexToRgb } from "../calc/colour.mjs"; +import { TOKEN_PREFIX } from "../palette.mjs"; + +export const channel = (hex) => hexToRgb(hex).join(" "); +export const tokenName = (i) => `${TOKEN_PREFIX}-${i + 1}`; +export const round = (x, places = 1) => + Math.round(x * 10 ** places) / 10 ** places; diff --git a/tools/chart-palette/present/json.mjs b/tools/chart-palette/present/json.mjs new file mode 100644 index 00000000..21f5caa7 --- /dev/null +++ b/tools/chart-palette/present/json.mjs @@ -0,0 +1,59 @@ +import { CVD_TYPES, hexToRgb, simulatedHex } from "../calc/colour.mjs"; +import { MODES } from "../calc/validate.mjs"; +import { HALO_WIDTH } from "../markers.mjs"; +import { LINE, OPACITY, SLOTS, THRESHOLDS } from "../palette.mjs"; +import { channel, tokenName } from "./format.mjs"; + +const simulated = (hex) => + Object.fromEntries(CVD_TYPES.map((v) => [v, simulatedHex(hex, v)])); + +export const buildJson = (report) => + JSON.stringify( + { + description: `Categorical chart palette, ${SLOTS.length} slots, light and dark. Generated by build.mjs.`, + surfaces: Object.fromEntries( + MODES.map((m) => [m, report.modes[m].surfaces]), + ), + fillOpacity: OPACITY, + thresholds: { + contrast: THRESHOLDS.contrast, + contrastFloor: THRESHOLDS.contrastFloor, + textContrast: THRESHOLDS.textContrast, + coreSlots: THRESHOLDS.coreSlots, + }, + secondChannel: { + minLineWidth: LINE.width, + minMarkerSize: LINE.marker, + markerHalo: HALO_WIDTH, + }, + slots: SLOTS.map((s, i) => ({ + slot: i + 1, + name: s.name, + token: tokenName(i), + marker: s.marker, + ...Object.fromEntries( + MODES.map((m) => [ + m, + { + hex: s[m], + rgb: hexToRgb(s[m]), + channel: channel(s[m]), + simulated: simulated(s[m]), + }, + ]), + ), + })), + nearStatus: report.nearStatus.map((n) => ({ + slot: n.slot, + name: n.name, + token: n.token, + deltaE: Math.round(n.deltaE * 10) / 10, + })), + weakPairs: report.weakPairs.map((w) => ({ + slots: [w.a, w.b], + names: [SLOTS[w.a - 1].name, SLOTS[w.b - 1].name], + })), + }, + null, + 2, + ) + "\n"; diff --git a/tools/chart-palette/present/preview.mjs b/tools/chart-palette/present/preview.mjs new file mode 100644 index 00000000..ae30743a --- /dev/null +++ b/tools/chart-palette/present/preview.mjs @@ -0,0 +1,87 @@ +// Builds render-check.html: an interactive preview of the palette in both modes, +// from the validation report so it can never drift from the tokens. +import { readFileSync } from "node:fs"; +import { greyHex, CVD_TYPES, simulatedHex } from "../calc/colour.mjs"; +import { CHART_SURFACES } from "../calc/tokens.mjs"; +import { GREY_CLOSE, MODES } from "../calc/validate.mjs"; +import { markerDefs } from "../markers.mjs"; +import { OPACITY, SLOTS, THRESHOLDS } from "../palette.mjs"; +import { barSeries, lineSeries, scatterSeries } from "../sample.mjs"; +import { round } from "./format.mjs"; + +const template = readFileSync( + new URL("./preview.template.html", import.meta.url), + "utf8", +); + +const dsTokens = readFileSync( + new URL("../../../src/styles/diamondDS/DiamondDSTokens.css", import.meta.url), + "utf8", +); + +const modeStats = (m) => { + const min = (xs) => Math.min(...xs); + const lstars = m.slots.map((s) => s.lstar); + return { + normal: round(m.worstAll.normal.value), + cvdCore: round(min(CVD_TYPES.map((v) => m.worstCore[v].value))), + cvdAll: round(min(CVD_TYPES.map((v) => m.worstAll[v].value))), + minContrast: round( + min(m.slots.flatMap((s) => CHART_SURFACES.map((k) => s.contrast[k]))), + 2, + ), + grey: m.greyClose.length, + pairs: (SLOTS.length * (SLOTS.length - 1)) / 2, + lmin: Math.round(min(lstars)), + lmax: Math.round(Math.max(...lstars)), + }; +}; + +// Colour values the page needs for ordering and vision simulation, so it carries no colour maths. +const modeInfo = (mode, m) => + SLOTS.map((s, i) => ({ + L: m.slots[i].lstar, + C: m.slots[i].oklch.C, + h: m.slots[i].oklch.h, + sim: { + ...Object.fromEntries( + CVD_TYPES.map((v) => [v, simulatedHex(s[mode], v)]), + ), + grey: greyHex(s[mode]), + }, + })); + +export const renderPreview = (report) => { + const data = { + core: THRESHOLDS.coreSlots, + t: { ...THRESHOLDS, greyClose: GREY_CLOSE }, + opacity: OPACITY, + sample: { line: lineSeries, scatter: scatterSeries, bars: barSeries }, + onSurface: Object.fromEntries( + MODES.map((m) => [m, report.modes[m].onSurface]), + ), + slots: SLOTS.map(({ name, light, dark, marker }) => ({ + name, + light, + dark, + marker, + })), + info: Object.fromEntries( + MODES.map((m) => [m, modeInfo(m, report.modes[m])]), + ), + surf: Object.fromEntries(MODES.map((m) => [m, report.modes[m].surfaces])), + stats: Object.fromEntries( + MODES.map((m) => [ + m, + { + ...modeStats(report.modes[m]), + under3: report.underTarget[m].length, + }, + ]), + ), + }; + return template + .replace("/*DATA*/ null", () => JSON.stringify(data)) + .replace("/*MARKERS*/", () => markerDefs()) + .replace("/*DS_TOKENS*/", () => dsTokens); +}; diff --git a/tools/chart-palette/present/preview.template.html b/tools/chart-palette/present/preview.template.html new file mode 100644 index 00000000..3109e4a4 --- /dev/null +++ b/tools/chart-palette/present/preview.template.html @@ -0,0 +1,886 @@ + + + + + + Chart palette preview + + + + + + + + +
+
+

Chart palette preview

+
    +
  • + Generated from palette.mjs. Slots 1 to + are the core and the rest are additional, + so use series in order. +
  • +
  • + Draw charts on --ds-surface or + --ds-background, where the colours are checked for + :1. On raised surfaces, tooltips and + dialogs they are checked to :1, + so use labels or a data table there. +
  • +
  • + These previews are drawn on --ds-surface. Switch mode, + simulate colour-vision deficiency and reorder by hue. +
  • +
+
+ +
+
+ Mode +
+
+
+ Order +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ +
+

Checks by mode

+
+

+ ΔE is CIEDE2000 under Machado et al. (2009) at full severity. The core + needs CVD ΔE or more and every pair + ; additional slots only need + normal-vision ΔE , and weaker pairs are + listed in validation.md. Contrast is WCAG against the chart surface; + "under :1" counts colours below that on + the chart, raised or dialog surface ( + is the accepted floor on the last two). Pairs under + L* look alike in greyscale or print + and rely on markers. Order by hue is per mode and starts at red; + colours with almost no chroma come last. +

+
+
+ + + + diff --git a/tools/chart-palette/present/report.mjs b/tools/chart-palette/present/report.mjs new file mode 100644 index 00000000..c79194a5 --- /dev/null +++ b/tools/chart-palette/present/report.mjs @@ -0,0 +1,223 @@ +import { MODES } from "../calc/validate.mjs"; +import { CVD_TYPES } from "../calc/colour.mjs"; +import { CHART_SURFACES } from "../calc/tokens.mjs"; +import { LINE, OPACITY, SLOTS } from "../palette.mjs"; +import { round } from "./format.mjs"; + +const f1 = (x) => x.toFixed(1); +const cell = (v, min) => (v < min ? `**${f1(v)}**` : f1(v)); + +export const buildMarkdown = (r) => { + const T = r.thresholds; + const L = []; + L.push("# Chart palette validation", ""); + L.push( + "Generated by `build.mjs`. Do not edit by hand. Re-run `node tools/chart-palette/build.mjs` after changing `palette.mjs`.", + "", + ); + L.push( + "CVD is simulated with Machado, Oliveira and Fernandes (2009) at severity 1.0. Contrast is WCAG 2.2.", + "ΔE is CIEDE2000. Surfaces come from `DiamondDSTokens.css`: chart surface is `--ds-surface`, raised surface (hover, tooltip, menu) is `--ds-elevation-8`, dialog surface is `--ds-elevation-16`. Charts must be drawn on `--ds-surface` or `--ds-background` (a Paper, or the page itself, not a card above elevation 0 or a raised surface). The 3:1 gate holds on those two and is not guaranteed on other surfaces. Raised and dialog surfaces are measured because tooltips, hover cards and dialogs show series colours as swatches.", + "", + ); + L.push("## Checks", "", "| Result | Check |", "| --- | --- |"); + for (const c of r.checks) + L.push(`| ${c.gate ? (c.pass ? "pass" : "FAIL") : "note"} | ${c.label} |`); + L.push(""); + + L.push("## Slots and contrast", ""); + L.push( + "Contrast is WCAG, shown as chart (the lower of surface and background) / raised / dialog. L* is CIE lightness. Min opacity is the lowest fill opacity that still reaches 3:1 on both chart surfaces.", + "", + ); + L.push( + "| Slot | Name | Light | Dark | Light contrast | Dark contrast | L* light / dark | Min opacity light / dark |", + ); + L.push("| --- | --- | --- | --- | --- | --- | --- | --- |"); + SLOTS.forEach((s, i) => { + const l = r.modes.light.slots[i]; + const d = r.modes.dark.slots[i]; + const c = (x) => + `${round(Math.min(...CHART_SURFACES.map((k) => x.contrast[k])), 2)} / ${round(x.contrast.raised, 2)} / ${round(x.contrast.dialog, 2)}`; + L.push( + `| ${i + 1} | ${s.name} | \`${s.light}\` | \`${s.dark}\` | ${c(l)} | ${c(d)} | ${round(l.lstar)} / ${round(d.lstar)} | ${l.minAlpha} / ${d.minAlpha} |`, + ); + }); + L.push(""); + + L.push("## Contrast below 3:1", ""); + L.push( + `The chart surfaces (\`--ds-surface\` and \`--ds-background\`) hold ${T.contrast}:1 (WCAG 1.4.11) for line and scatter marks. Raised and dialog surfaces hold ${T.contrastFloor}:1, so colours below ${T.contrast}:1 there need direct labels or a data table.`, + "", + ); + for (const m of MODES) { + const u = r.underTarget[m]; + L.push( + `- ${m}: ${u.length ? u.map((s) => `${s.slot} ${SLOTS[s.slot - 1].name} (${s.surfaces.join(", ")})`).join("; ") : "none"}`, + ); + } + L.push(""); + + L.push("## Fills and separators", ""); + const fc = (k) => + MODES.map((m) => { + const v = r.modes[m].slots.map((s) => s.fillContrast[k]); + return `${m} ${Math.min(...v).toFixed(2)}-${Math.max(...v).toFixed(2)}:1`; + }).join(", "); + const lcs = MODES.flatMap((m) => + r.modes[m].slots.map((s) => s.labelTextContrast), + ); + const lcAll = MODES.flatMap((m) => + r.modes[m].slots.map((s) => s.labelTextContrastAll), + ); + const lc = (k) => Math[k](...lcs).toFixed(1); + L.push( + `- Data fills (bars, points, heatmap cells) use opacity ${OPACITY.data}, and every slot is at least 3:1 opaque. Any lower opacity needs the per-slot minimum above.`, + `- Area fills (${OPACITY.area}) composite to ${fc("area")} on the surfaces. Decorative: the line carries the information.`, + `- Range bands (${OPACITY.band}) composite to ${fc("band")}. Decorative only when the band also has a series-coloured edge line; a band that encodes a range on its own does not meet 3:1.`, + `- Regions drawn on an image use a soft fill (${OPACITY.region}, hover ${OPACITY["region-hover"]}, selected ${OPACITY["region-selected"]}) with a solid series-coloured border, thicker when selected so the state is not carried by colour alone. Add a soft halo in \`--ds-surface\` (about 55% opacity, 1px each side) so the border reads over bright and dark pixels. The fills are decorative, and the border's contrast depends on the image behind it.`, + `- Labels next to a line use a tint of the series colour (${OPACITY.label}, hover ${OPACITY["label-hover"]}, selected ${OPACITY["label-selected"]}) with a series-coloured border, thicker when selected, and \`--ds-on-surface\` text. On \`--ds-surface\` and \`--ds-background\` the text reaches ${lc("min")}-${lc("max")}:1 across slots, modes and states (${T.textContrast}:1 gated). Keep labels on those surfaces: on raised and dialog surfaces the minimum is ${Math.min(...lcAll).toFixed(1)}:1.`, + "- Adjacent filled segments (stacked bars and areas, pies) can fall below 3:1 against each other: separate them with a 1-2px `--ds-surface` gap.", + "- Overlapping translucent fills blend into colours outside the palette. Prefer lines, or keep overlaps to two series.", + "", + ); + + L.push("## Greyscale and print", ""); + L.push( + "Pairs closer than 5 L* are indistinguishable in greyscale, print and achromatopsia.", + "", + `| Mode | Pairs under 5 L* | Of those, within slots 1-${T.coreSlots} |`, + "| --- | --- | --- |", + ); + for (const m of MODES) { + const close = r.modes[m].greyClose; + const core = close.filter((g) => g.b <= T.coreSlots); + L.push( + `| ${m} | ${close.length} of ${(SLOTS.length * (SLOTS.length - 1)) / 2} | ${core.length ? core.map((g) => `${g.a}↔${g.b}`).join(", ") : "none"} |`, + ); + } + L.push( + "", + `Lightness alone does not separate this palette. Where greyscale or print matters, markers are mandatory, not optional.`, + "", + ); + + L.push("## Text use", ""); + L.push( + `Series colours are for marks. Set labels, values and legend text in neutral text tokens and show the series colour as a swatch. Only these slots reach WCAG ${T.textContrast}:1 and APCA |Lc| ${T.textLc} on every supported surface, if you must colour text: light ${r.modes.light.textSlots.join(", ") || "none"}; dark ${r.modes.dark.textSlots.join(", ") || "none"}.`, + "", + ); + + L.push("## Rendering the second channel", ""); + L.push( + `- Lines at least ${LINE.width}px wide, markers at least ${LINE.marker}px across, with a 1.5px \`--ds-surface\` halo on filled markers.`, + `- All slots are solid lines, so on a line chart they differ by colour and marker only. The core (slots 1-${T.coreSlots}) holds a CVD floor of ΔE ${T.cvd}, so colour carries it; the additional slots may fall below it (see Weak pairs).`, + "- Markers only help if the chart library actually draws them. Check this per adapter.", + "- Forced-colors (Windows high contrast) can replace series colours with system colours. Keep `forced-color-adjust: none` on series marks, or rely on markers, which still render.", + "- WCAG 1.4.1: never use colour alone. Always pair with a legend and direct labels or a data table.", + "", + ); + + L.push("## Worst-case pair ΔE", ""); + L.push( + `Bold is below target (normal ${T.normal}, CVD ${T.cvd}). The CVD target applies to slots 1-${T.coreSlots} only.`, + "", + ); + L.push( + "| Mode | Pairs | Normal | Protan | Deutan | Tritan |", + "| --- | --- | --- | --- | --- | --- |", + ); + for (const m of MODES) { + for (const [label, w, cvdMin] of [ + [`1-${T.coreSlots}`, r.modes[m].worstCore, T.cvd], + ...(SLOTS.length > T.coreSlots + ? [[`1-${SLOTS.length}`, r.modes[m].worstAll, 0]] + : []), + ]) { + const c = (v, min) => `${cell(w[v].value, min)} (${w[v].pair.join("↔")})`; + L.push( + `| ${m} | ${label} | ${c("normal", T.normal)} | ${c("protan", cvdMin)} | ${c("deutan", cvdMin)} | ${c("tritan", cvdMin)} |`, + ); + } + } + L.push(""); + + L.push("## Order: worst pair among the first N slots", ""); + L.push( + "Each row is the worst pair among slots 1 to N. Later slots are never closer to the earlier ones than the row shows.", + "", + ); + L.push( + "| First N | Light normal | Light CVD | Dark normal | Dark CVD |", + "| --- | --- | --- | --- | --- |", + ); + r.modes.light.prefix.forEach((p, k) => { + const d = r.modes.dark.prefix[k]; + const cvd = (q) => f1(Math.min(...CVD_TYPES.map((v) => q[v]))); + L.push( + `| ${p.slots} | ${f1(p.normal)} | ${cvd(p)} | ${f1(d.normal)} | ${cvd(d)} |`, + ); + }); + L.push(""); + + L.push("## Weak pairs and their second channel", ""); + if (!r.weakPairs.length) { + L.push( + `None. Every pair clears ΔE ${T.cvdWeak} under protan, deutan and tritan in both modes (worst ${f1(Math.min(...MODES.flatMap((m) => CVD_TYPES.map((v) => r.modes[m].worstAll[v].value))))}), so colour carries every slot. Every slot still has its own marker shape for greyscale, print and forced-colors.`, + "", + ); + } else { + L.push( + `Pairs below ΔE ${T.cvdWeak} under some CVD type in either mode. Every slot is a solid line with its own marker shape, so these pairs rely on the marker. See Rendering the second channel for the sizes this needs.`, + "", + ); + } + for (const w of r.weakPairs) { + const a = `${w.a} ${SLOTS[w.a - 1].name}`; + const b = `${w.b} ${SLOTS[w.b - 1].name}`; + const ok = (x) => (x.value >= T.cvdWeak ? " (ok)" : ""); + L.push( + `- ${a} / ${b}: ${w.light.type} ${f1(w.light.value)}${ok(w.light)} light, ${w.dark.type} ${f1(w.dark.value)}${ok(w.dark)} dark. Told apart by marker shape.`, + ); + } + L.push(""); + + L.push("## Light and dark identity", ""); + L.push( + "Each slot keeps its hue family across modes, with lightness tuned per mode. Names follow the dark hue. Hue gap is the OKLCH hue difference between the two values.", + "", + "| Slot | Name | Light | Dark | Hue gap | L* light / dark |", + "| --- | --- | --- | --- | --- | --- |", + ); + SLOTS.forEach((s, i) => { + const l = r.modes.light.slots[i]; + const d = r.modes.dark.slots[i]; + L.push( + `| ${i + 1} | ${s.name} | \`${s.light}\` | \`${s.dark}\` | ${r.hueGaps[i].toFixed(0)}° | ${round(l.lstar)} / ${round(d.lstar)} |`, + ); + }); + L.push( + "", + `A slot's dark value is nearer to its own light value than to any other slot's, except for slots ${r.identityFails.join(", ") || "none"}. Recorded, not gated.`, + "", + ); + + L.push("## Distance from status and primary/brand colours", ""); + L.push( + "Recorded, not gated: a series resembling a status colour is accepted in charts. Nearest token by ΔE across danger, success, warning, info, primary and brand (main, emphasis, accent, solid roles). Hue gap is the smallest OKLCH hue difference to any of them.", + "", + ); + L.push( + "| Slot | Name | Light nearest | Light ΔE | Light hue gap | Dark nearest | Dark ΔE | Dark hue gap |", + "| --- | --- | --- | --- | --- | --- | --- | --- |", + ); + SLOTS.forEach((s, i) => { + const l = r.modes.light.slots[i]; + const d = r.modes.dark.slots[i]; + L.push( + `| ${i + 1} | ${s.name} | \`${l.nearestReserved.token}\` | ${f1(l.nearestReserved.deltaE)} | ${l.minHueGap.toFixed(0)}° | \`${d.nearestReserved.token}\` | ${f1(d.nearestReserved.deltaE)} | ${d.minHueGap.toFixed(0)}° |`, + ); + }); + L.push(""); + return L.join("\n"); +}; diff --git a/tools/chart-palette/sample.mjs b/tools/chart-palette/sample.mjs new file mode 100644 index 00000000..0709949e --- /dev/null +++ b/tools/chart-palette/sample.mjs @@ -0,0 +1,39 @@ +// Seeded sample data for the example charts, shared by the preview page and the docs page +// so both draw the same series. +import { SLOTS } from "./palette.mjs"; + +const rng = (seed) => { + let t = seed >>> 0; + return () => { + t = (t + 0x6d2b79f5) >>> 0; + let r = Math.imul(t ^ (t >>> 15), 1 | t); + r = (r + Math.imul(r ^ (r >>> 7), 61 | r)) ^ r; + return ((r ^ (r >>> 14)) >>> 0) / 4294967296; + }; +}; +const clamp = (v, lo, hi) => Math.max(lo, Math.min(hi, v)); +const slots = (fn) => SLOTS.map((_, k) => fn(k)); + +// A random walk per slot, 24 points between 6 and 94. +export const lineSeries = slots((k) => { + const r = rng(101 + k * 17); + let v = 18 + r() * 64; + return Array.from({ length: 24 }, (_, i) => { + v = clamp(v + (r() - 0.5) * 14 + Math.sin(i / 3 + k) * 2, 6, 94); + return +v.toFixed(1); + }); +}); + +// A cluster of 7 points per slot, as fractions of the plot area. +export const scatterSeries = slots((k) => { + const r = rng(5000 + k * 13); + const [cx, cy] = [14 + r() * 72, 14 + r() * 72]; + const point = (c) => + +clamp((c + (r() - 0.5) * 26) / 100, 0.03, 0.97).toFixed(3); + return Array.from({ length: 7 }, () => [point(cx), point(cy)]); +}); + +// Four groups of one bar per slot, valued 20 to 92. +export const barSeries = Array.from({ length: 4 }, (_, g) => + slots((k) => +(20 + rng(900 + g * 31 + k * 7)() * 72).toFixed(1)), +); diff --git a/tools/chart-palette/validation.md b/tools/chart-palette/validation.md new file mode 100644 index 00000000..64c647fd --- /dev/null +++ b/tools/chart-palette/validation.md @@ -0,0 +1,162 @@ +# Chart palette validation + +Generated by `build.mjs`. Do not edit by hand. Re-run `node tools/chart-palette/build.mjs` after changing `palette.mjs`. + +CVD is simulated with Machado, Oliveira and Fernandes (2009) at severity 1.0. Contrast is WCAG 2.2. +ΔE is CIEDE2000. Surfaces come from `DiamondDSTokens.css`: chart surface is `--ds-surface`, raised surface (hover, tooltip, menu) is `--ds-elevation-8`, dialog surface is `--ds-elevation-16`. Charts must be drawn on `--ds-surface` or `--ds-background` (a Paper, or the page itself, not a card above elevation 0 or a raised surface). The 3:1 gate holds on those two and is not guaranteed on other surfaces. Raised and dialog surfaces are measured because tooltips, hover cards and dialogs show series colours as swatches. + +## Checks + +| Result | Check | +| --- | --- | +| pass | Every colour ≥ 3:1 on the chart surface and the page background, both modes | +| pass | Every colour ≥ 2.25:1 on the raised (elevation 8) and dialog (elevation 16) surfaces, both modes | +| pass | Data fills (opacity 1) keep ≥ 3:1 on the chart surface and the page background once composited | +| pass | Text in --ds-on-surface keeps ≥ 4.5:1 on a series-coloured label tint (opacities 0.22, 0.28, 0.34), both modes | +| pass | ΔE2000 ≥ 15 between any two of 12 slots, normal vision | +| pass | ΔE2000 ≥ 13 between slots 1-8 under protan, deutan and tritan | +| pass | ΔE2000 ≥ 7 between any two of 12 slots under protan, deutan and tritan (the marker carries pairs below 10) | +| pass | Every slot has chroma ≥ 0.02 in both modes | +| pass | Each chromatic slot keeps its hue within 20° across modes | +| note | Each slot's dark value is nearest to its own light value (informational, not gated; see Light and dark identity) | +| pass | Every slot has its own marker shape; all lines are solid | +| note | 4 of 12 slots sit within ΔE 7 of a status or brand colour in at least one mode (slots 2, 5, 8, 9); recorded, not gated | + +## Slots and contrast + +Contrast is WCAG, shown as chart (the lower of surface and background) / raised / dialog. L* is CIE lightness. Min opacity is the lowest fill opacity that still reaches 3:1 on both chart surfaces. + +| Slot | Name | Light | Dark | Light contrast | Dark contrast | L* light / dark | Min opacity light / dark | +| --- | --- | --- | --- | --- | --- | --- | --- | +| 1 | violet | `#8133d6` | `#9a7efb` | 5.76 / 5.44 / 5.12 | 5.69 / 4.78 / 4.17 | 41 / 60.6 | 0.65 / 0.63 | +| 2 | vermilion | `#ed604f` | `#dc5453` | 3.05 / 2.88 / 2.71 | 4.59 / 3.85 / 3.35 | 58.9 / 54.2 | 0.99 / 0.74 | +| 3 | wine | `#610c12` | `#ffebeb` | 12.4 / 11.7 / 11.01 | 15.46 / 12.99 / 11.31 | 19.4 / 94.6 | 0.49 / 0.36 | +| 4 | lavender | `#8a8ab9` | `#7f6d99` | 3.03 / 2.86 / 2.69 | 3.84 / 3.22 / 2.81 | 59.1 / 49.2 | 1 / 0.82 | +| 5 | indigo | `#1e3f80` | `#a7b9fe` | 9.37 / 8.84 / 8.32 | 9.29 / 7.8 / 6.8 | 27.8 / 76.1 | 0.57 / 0.47 | +| 6 | green | `#316f5e` | `#5ab09a` | 5.46 / 5.15 / 4.85 | 6.84 / 5.75 / 5.01 | 42.5 / 66.2 | 0.71 / 0.56 | +| 7 | rose | `#b67886` | `#9a5060` | 3.23 / 3.05 / 2.87 | 3.11 / 2.61 / 2.28 | 57.2 / 43.4 | 0.95 / 0.98 | +| 8 | amber | `#a25500` | `#ffb045` | 5.08 / 4.79 / 4.5 | 9.74 / 8.18 / 7.13 | 44.5 / 77.7 | 0.71 / 0.46 | +| 9 | blue | `#318ff8` | `#076cd0` | 3.03 / 2.86 / 2.69 | 3.43 / 2.88 / 2.51 | 59 / 46.1 | 0.99 / 0.9 | +| 10 | khaki | `#786941` | `#b8a461` | 5 / 4.72 / 4.44 | 7.19 / 6.04 / 5.26 | 44.9 / 67.7 | 0.74 / 0.55 | +| 11 | fern | `#589704` | `#bded9a` | 3.33 / 3.14 / 2.96 | 13.28 / 11.16 / 9.72 | 56.3 / 88.8 | 0.93 / 0.39 | +| 12 | plum | `#9c5894` | `#beabba` | 4.59 / 4.34 / 4.08 | 8.2 / 6.89 / 6 | 47.2 / 72 | 0.76 / 0.5 | + +## Contrast below 3:1 + +The chart surfaces (`--ds-surface` and `--ds-background`) hold 3:1 (WCAG 1.4.11) for line and scatter marks. Raised and dialog surfaces hold 2.25:1, so colours below 3:1 there need direct labels or a data table. + +- light: 2 vermilion (raised, dialog); 4 lavender (raised, dialog); 7 rose (dialog); 9 blue (raised, dialog); 11 fern (dialog) +- dark: 4 lavender (dialog); 7 rose (raised, dialog); 9 blue (raised, dialog) + +## Fills and separators + +- Data fills (bars, points, heatmap cells) use opacity 1, and every slot is at least 3:1 opaque. Any lower opacity needs the per-slot minimum above. +- Area fills (0.16) composite to light 1.15-1.36:1, dark 1.12-1.52:1 on the surfaces. Decorative: the line carries the information. +- Range bands (0.28) composite to light 1.28-1.77:1, dark 1.23-2.27:1. Decorative only when the band also has a series-coloured edge line; a band that encodes a range on its own does not meet 3:1. +- Regions drawn on an image use a soft fill (0.14, hover 0.24, selected 0.34) with a solid series-coloured border, thicker when selected so the state is not carried by colour alone. Add a soft halo in `--ds-surface` (about 55% opacity, 1px each side) so the border reads over bright and dark pixels. The fills are decorative, and the border's contrast depends on the image behind it. +- Labels next to a line use a tint of the series colour (0.22, hover 0.28, selected 0.34) with a series-coloured border, thicker when selected, and `--ds-on-surface` text. On `--ds-surface` and `--ds-background` the text reaches 5.1-11.3:1 across slots, modes and states (4.5:1 gated). Keep labels on those surfaces: on raised and dialog surfaces the minimum is 4.0:1. +- Adjacent filled segments (stacked bars and areas, pies) can fall below 3:1 against each other: separate them with a 1-2px `--ds-surface` gap. +- Overlapping translucent fills blend into colours outside the palette. Prefer lines, or keep overlaps to two series. + +## Greyscale and print + +Pairs closer than 5 L* are indistinguishable in greyscale, print and achromatopsia. + +| Mode | Pairs under 5 L* | Of those, within slots 1-8 | +| --- | --- | --- | +| light | 19 of 66 | 1↔6, 1↔8, 2↔4, 2↔7, 4↔7, 6↔8 | +| dark | 6 of 66 | 5↔8 | + +Lightness alone does not separate this palette. Where greyscale or print matters, markers are mandatory, not optional. + +## Text use + +Series colours are for marks. Set labels, values and legend text in neutral text tokens and show the series colour as a swatch. Only these slots reach WCAG 4.5:1 and APCA |Lc| 60 on every supported surface, if you must colour text: light 1, 3, 5, 6, 8; dark 3, 5, 8, 11. + +## Rendering the second channel + +- Lines at least 1.75px wide, markers at least 8px across, with a 1.5px `--ds-surface` halo on filled markers. +- All slots are solid lines, so on a line chart they differ by colour and marker only. The core (slots 1-8) holds a CVD floor of ΔE 13, so colour carries it; the additional slots may fall below it (see Weak pairs). +- Markers only help if the chart library actually draws them. Check this per adapter. +- Forced-colors (Windows high contrast) can replace series colours with system colours. Keep `forced-color-adjust: none` on series marks, or rely on markers, which still render. +- WCAG 1.4.1: never use colour alone. Always pair with a legend and direct labels or a data table. + +## Worst-case pair ΔE + +Bold is below target (normal 15, CVD 13). The CVD target applies to slots 1-8 only. + +| Mode | Pairs | Normal | Protan | Deutan | Tritan | +| --- | --- | --- | --- | --- | --- | +| light | 1-8 | 18.2 (2↔7) | 13.0 (1↔5) | 14.3 (1↔5) | 13.5 (2↔7) | +| light | 1-12 | 16.3 (7↔12) | 7.5 (2↔10) | 7.6 (2↔11) | 10.2 (7↔12) | +| dark | 1-8 | 16.4 (1↔5) | 14.3 (1↔5) | 13.5 (1↔5) | 14.0 (5↔6) | +| dark | 1-12 | 16.4 (1↔5) | 9.5 (8↔10) | 7.7 (6↔12) | 8.7 (10↔12) | + +## Order: worst pair among the first N slots + +Each row is the worst pair among slots 1 to N. Later slots are never closer to the earlier ones than the row shows. + +| First N | Light normal | Light CVD | Dark normal | Dark CVD | +| --- | --- | --- | --- | --- | +| 2 | 43.2 | 33.5 | 37.1 | 40.0 | +| 3 | 35.1 | 30.9 | 36.6 | 30.0 | +| 4 | 25.6 | 19.3 | 18.0 | 16.5 | +| 5 | 21.0 | 13.0 | 16.4 | 13.5 | +| 6 | 21.0 | 13.0 | 16.4 | 13.5 | +| 7 | 18.2 | 13.0 | 16.4 | 13.5 | +| 8 | 18.2 | 13.0 | 16.4 | 13.5 | +| 9 | 18.2 | 10.8 | 16.4 | 10.9 | +| 10 | 18.0 | 7.5 | 16.4 | 8.7 | +| 11 | 18.0 | 7.5 | 16.4 | 8.7 | +| 12 | 16.3 | 7.5 | 16.4 | 7.7 | + +## Weak pairs and their second channel + +Pairs below ΔE 10 under some CVD type in either mode. Every slot is a solid line with its own marker shape, so these pairs rely on the marker. See Rendering the second channel for the sizes this needs. + +- 2 vermilion / 10 khaki: protan 7.5 light, deutan 8.7 dark. Told apart by marker shape. +- 2 vermilion / 11 fern: deutan 7.6 light, deutan 22.3 (ok) dark. Told apart by marker shape. +- 6 green / 12 plum: deutan 16.4 (ok) light, deutan 7.7 dark. Told apart by marker shape. +- 8 amber / 10 khaki: protan 9.2 light, protan 9.5 dark. Told apart by marker shape. +- 8 amber / 11 fern: deutan 8.3 light, deutan 11.1 (ok) dark. Told apart by marker shape. +- 10 khaki / 12 plum: tritan 12.6 (ok) light, tritan 8.7 dark. Told apart by marker shape. + +## Light and dark identity + +Each slot keeps its hue family across modes, with lightness tuned per mode. Names follow the dark hue. Hue gap is the OKLCH hue difference between the two values. + +| Slot | Name | Light | Dark | Hue gap | L* light / dark | +| --- | --- | --- | --- | --- | --- | +| 1 | violet | `#8133d6` | `#9a7efb` | 9° | 41 / 60.6 | +| 2 | vermilion | `#ed604f` | `#dc5453` | 6° | 58.9 / 54.2 | +| 3 | wine | `#610c12` | `#ffebeb` | 6° | 19.4 / 94.6 | +| 4 | lavender | `#8a8ab9` | `#7f6d99` | 19° | 59.1 / 49.2 | +| 5 | indigo | `#1e3f80` | `#a7b9fe` | 11° | 27.8 / 76.1 | +| 6 | green | `#316f5e` | `#5ab09a` | 2° | 42.5 / 66.2 | +| 7 | rose | `#b67886` | `#9a5060` | 3° | 57.2 / 43.4 | +| 8 | amber | `#a25500` | `#ffb045` | 14° | 44.5 / 77.7 | +| 9 | blue | `#318ff8` | `#076cd0` | 1° | 59 / 46.1 | +| 10 | khaki | `#786941` | `#b8a461` | 4° | 44.9 / 67.7 | +| 11 | fern | `#589704` | `#bded9a` | 0° | 56.3 / 88.8 | +| 12 | plum | `#9c5894` | `#beabba` | 2° | 47.2 / 72 | + +A slot's dark value is nearer to its own light value than to any other slot's, except for slots 3, 5, 8, 12. Recorded, not gated. + +## Distance from status and primary/brand colours + +Recorded, not gated: a series resembling a status colour is accepted in charts. Nearest token by ΔE across danger, success, warning, info, primary and brand (main, emphasis, accent, solid roles). Hue gap is the smallest OKLCH hue difference to any of them. + +| Slot | Name | Light nearest | Light ΔE | Light hue gap | Dark nearest | Dark ΔE | Dark hue gap | +| --- | --- | --- | --- | --- | --- | --- | --- | +| 1 | violet | `--ds-primary` | 15.4 | 30° | `--ds-primary` | 13.9 | 19° | +| 2 | vermilion | `--ds-danger-accent` | 6.0 | 0° | `--ds-danger-solid` | 5.2 | 0° | +| 3 | wine | `--ds-danger-emphasis` | 10.9 | 0° | `--ds-danger-emphasis` | 12.0 | 360° | +| 4 | lavender | `--ds-brand-accent` | 10.9 | 14° | `--ds-primary-solid` | 18.0 | 31° | +| 5 | indigo | `--ds-primary-emphasis` | 3.8 | 2° | `--ds-brand` | 1.0 | 1° | +| 6 | green | `--ds-success-emphasis` | 14.1 | 26° | `--ds-success` | 16.1 | 23° | +| 7 | rose | `--ds-danger-accent` | 17.7 | 19° | `--ds-danger-solid` | 15.7 | 16° | +| 8 | amber | `--ds-warning` | 1.7 | 2° | `--ds-warning` | 6.0 | 2° | +| 9 | blue | `--ds-info-accent` | 7.6 | 10° | `--ds-primary-solid` | 6.1 | 11° | +| 10 | khaki | `--ds-warning-emphasis` | 18.2 | 27° | `--ds-warning-accent` | 16.1 | 24° | +| 11 | fern | `--ds-success-accent` | 11.1 | 13° | `--ds-success-emphasis` | 8.5 | 14° | +| 12 | plum | `--ds-primary-solid` | 24.0 | 52° | `--ds-danger-emphasis` | 15.5 | 360° | diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index 66873487..28fe86f4 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -4,6 +4,7 @@ "src", "src/types", "dev", + "tools", ".storybook/**/*.tsx", ".storybook/**/*.ts", ".storybook/**/*.js",