## Embed Chart Authoring Guidelines ### Quickstart (TL;DR) - Create a single self-contained HTML fragment: root div + scoped style + IIFE script. - Draw marks/axes in SVG; render UI (legend and controls) in HTML. - Place legend and controls BELOW the chart (header appended after the chart). Include a legend title "Legend" and a select labeled "Metric" when relevant. - Load data from public `/data` first, then fall back to `assets/data`. - Use `window.ColorPalettes` for colors; stick to CSS variables for theming. Minimal header markup: ```html
Legend
``` See also: `d3-line-simple.html`, `d3-line-quad.html`, `d3-benchmark.html`. Authoring rules for creating a new interactive chart as a single self-contained `.html` file under `src/content/embeds/`. These conventions are derived from `d3-bar.html`, `d3-comparison.html`, `d3-neural.html`, `d3-line.html`, and `d3-pie.html`. ### A) Colors & palettes (MANDATORY) - Always obtain color arrays from `window.ColorPalettes`; do not hardcode palettes. - Use the categorical/sequential/diverging helpers and the current primary color. - If you change `--primary-color` dynamically, call `window.ColorPalettes.refresh()` so listeners update. Usage: ```js // Usage (with explicit counts) const cat = window.ColorPalettes.getColors('categorical', 8); const seq = window.ColorPalettes.getColors('sequential', 8); const div = window.ColorPalettes.getColors('diverging', 7); // For current primary color string const primaryHex = window.ColorPalettes.getPrimary(); // If you change --primary-color dynamically, call refresh to notify listeners document.documentElement.style.setProperty('--primary-color', '#6D4AFF'); window.ColorPalettes.refresh(); ``` Notes: - Keep chart accents (lines, markers, selection) aligned with `--primary-color`. - Prefer CSS variables for fills/strokes when possible; derive series colors via `ColorPalettes`. - Provide a graceful fallback to CSS variables if `window.ColorPalettes` is unavailable. ### B) Layout & form elements (HTML-only) - All UI controls (labels, selects, sliders, buttons, toggles) must be plain HTML inside the root container. - Do not draw controls with SVG; style them consistently (rounded 8px, custom caret, focus ring). - Use `