name: visualize
description: "Create interactive visualizations directly in the conversation. Use to show how something works; explore 'what happens when', 'what changes', or 'help me understand'; compare or inspect; create simulations, charts, graphs, diagrams, and UI previews. Use standard tools for static scientific figures."
Visualize
A request for a new standalone file, website, app page, component, or
project change is not an in-conversation visualization, even with charts.
Build it in the project.
Create a visual only when the user needs to see or explore it in the
conversation and it materially improves the explanation.
Use a Markdown table when asked for a table; a fenced Mermaid block when
labeled nodes and edges explain a static structure. Visualize dynamics,
motion, adjustable inputs, spatial layout, and data worth hovering or
filtering.
Work silently: no progress commentary. In the reply, describe only what the
visual helps the user see or decide. Never announce this skill, HTML, SVG,
scripts, or local files.
Read this file in full before authoring. Copy into every compaction summary:
Reload the full visualize skill before creating or updating a visualization.
Hard rules
One Write, then the reply. Do not verify the fragment: no Bash or shell
command, no browser, no screenshot, no reading it back. The Write result
checks it; if that lists problems, fix them with one Edit, then reply.
Do not open the kit, stylesheet, or helper source to look things up; the
classes and viz API you need are in this skill. Anything missing goes in
the reply, not in another tool call.
Output contract
File
Write <title>.html (concise lowercase-hyphenated ASCII) with its
absolute path into the visualization directory named in the system
prompt, directly in that directory. No directory listed, or not
writable: answer without a visual.
Never write inline fragments into the project or a temp directory.
Fragment
Write only an HTML fragment: no <!doctype>, <html>, <head>, or
<body>. The host supplies the document, the stylesheet below, and the
runtime.
Write literal markup with real newlines, never an escaped string
(<div class=\"card\">, \n).
Write the blocks (heading, controls, visual, legend, notes) as top-level
elements; the host stacks them 12px apart. Do not wrap the whole fragment in
one container. Give scripted elements unique IDs and select them with
document.getElementById(...); never use document.currentScript.
Keep it under 1 MB: aggregate, bin, or downsample large datasets.
Write the file once, complete. Before writing, check that the script has
no undefined identifiers, every queried element exists, and the primary
interaction updates the visual. Do not read it back (see Hard rules); reply
right after the write succeeds.
Reference in the reply
Put any short explanation in the reply, then the reference as the last line of
the reply, as plain text. The line looks like this (with real values):
::visualize{"path":"/
.html","title":"<short title>"}</p>
<ul>
<li>Emit the literal ASCII prefix <code>::visualize</code> followed by a JSON object; do
not put it in a code block, backticks, or a link. Write the path with
forward slashes (<code>C:/Users/...</code> on Windows).</li>
<li>Whenever you create or update a visualization, reference it again in that
turn's final reply, even when editing an existing file.</li>
<li>Do not repeat the data as a table; add at most one short conclusion.</li>
</ul>
<h3>Sandbox</h3>
<ul>
<li>There is no network: <code>fetch</code>, XHR, WebSocket, remote scripts, fonts, images,
and map data are all blocked and fail silently. Draw with inline SVG or
<code><canvas></code>; embed small assets as <code>data:</code> URIs.</li>
<li>D3 7.9.0 (<code>d3</code>) and the <code>viz</code> helpers below are preloaded; use them
directly and never add a <code><script src></code>. Floating UI is loaded by the
runtime for tooltips. Any other library is unavailable.</li>
<li>No popups, alerts, navigation, external links, form submission, cookies,
or <code>localStorage</code>. Keep state in script variables; it resets when the card
reloads.</li>
<li>The card starts at 240px and follows content height up to 2000px. The same
fragment also opens in a larger expanded view.</li>
</ul>
<h2>Color and type</h2>
<ul>
<li>Make every fill, stroke, text, border, and canvas color theme-aware. The
host follows the app's light or dark theme; never hard-code white panels,
black text, or Tailwind color literals.</li>
<li>Theme variables: <code>--background</code>, <code>--foreground</code>, <code>--card</code>,
<code>--card-foreground</code>, <code>--popover</code>, <code>--popover-foreground</code>, <code>--primary</code>,
<code>--primary-foreground</code>, <code>--secondary</code>, <code>--secondary-foreground</code>, <code>--muted</code>,
<code>--muted-foreground</code>, <code>--accent</code>, <code>--accent-foreground</code>, <code>--destructive</code>,
<code>--border</code>, <code>--input</code>, <code>--ring</code>, and hues <code>--blue</code>, <code>--orange</code>, <code>--green</code>,
<code>--red</code>, <code>--purple</code>, <code>--yellow</code>. Use <code>currentColor</code> inside SVG.</li>
<li>In each pair the base token is a surface and <code>-foreground</code> is the content
on it. <code>--muted</code> is a fill; use <code>--muted-foreground</code> for secondary text.</li>
<li>Use <code>--viz-series-1</code> for a single measure or active state, and
<code>--viz-series-2</code> … <code>--viz-series-6</code> only for persistent category or series
identity. Keep mappings stable and pair color with labels or shapes. Keep
values and labels in <code>--foreground</code> / <code>--muted-foreground</code>.</li>
<li>Keep grids and inactive structure thin (1–2px) and neutral. Never outline
bars, progress tracks, or stacked segments.</li>
<li>Where CSS variables cannot be read (canvas), use <code>viz.color("--primary")</code>
inside a <code>viz.chart</code> draw function, which reruns on theme changes.</li>
<li>Type scales from <code>--font-size-base</code> (14px); <code>.text-small</code> is 12px. Never go
below 11px, never set custom font sizes or line heights, and use only
<code>var(--font-weight-normal)</code> and <code>var(--font-weight-medium)</code>. Use <code>.tabular-nums</code> on changing numbers.</li>
<li>Use at most one concise heading (<code>h1</code>–<code>h3</code>) per chart; do not restate the
prompt.</li>
</ul>
<h2>Composition</h2>
<p>Choose the smallest composition that fits.</p>
<ul>
<li>Prefer interaction detail over permanent panels, toolbars, repeated
legends, or long stacks. Add only requested controls; never invent search,
filter, or reset controls, or qualitative score and status cards.</li>
<li>Put live values in control labels or on the visual.</li>
<li><strong>Explainer or simulation:</strong> compact controls, one dominant visual, at most
one single-line selected-state detail. For step-throughs, add only step
controls and update one current visual.</li>
<li><strong>Graphs and plots:</strong> D3 with <code>viz</code> for data-rich plots; handwritten SVG
for a few directly labeled values.</li>
<li><strong>Dense categorical grid:</strong> one compact selected-item summary, a grid with
one readable identifier per cell, one small legend.</li>
<li><strong>Part-to-whole over time:</strong> one stacked chart of category allocation per
period.</li>
<li><strong>Maps:</strong> the sandbox cannot download geometry. Draw a map only from
coordinates or small geometry you embed yourself; otherwise choose another
form.</li>
<li><strong>UI mockups:</strong> match the product's own chrome, colors, and type. Do not use
the visualization utility classes or variables inside the mocked product;
scope product styles to the mockup with <code>light-dark(<light>, <dark>)</code>. Give
product surfaces opaque backgrounds and keep the surrounding area
transparent. Show realistic states, not filler dashboards.</li>
</ul>
<h2>Layout</h2>
<ul>
<li>Keep the top-level surface transparent and unframed, and fill the available
width. Design for about 700px and support widths down to 320px; stack
side-by-side content when it no longer fits.</li>
<li>Text, controls, and dynamic content must fit at every width without overlap
or clipping. The host sizes the frame to content, so never use fixed outer
widths, horizontal overflow, internal scrolling, <code>position: fixed</code>, or
viewport-height layouts. Use <code>.table-responsive</code> only when table columns
cannot fit.</li>
<li>Draw chart SVGs with <code>viz.chart</code> (below); never a fixed-width <code>viewBox</code>.
When <code>compact</code>, drop annotations.</li>
</ul>
<h2>Utility classes</h2>
<p>Let the utilities own geometry, appearance, and interaction; never restyle
them.</p>
<ul>
<li><strong>Surfaces:</strong> <code>.card</code> is the only card-like surface — use it for a necessary
numeric summary, a selected-item summary, or a bounded interactive field.
Never nest cards or frame charts, maps, tables, or the whole visual.
<code>.viz-stat</code> + <code>.viz-stat-value</code> inside a card for one metric.</li>
<li><strong>Layout:</strong> <code>.viz-grid</code> (equal columns that stack when narrow; 2–3 columns at
700px), <code>.viz-row</code> (wrapping inline group), <code>.viz-controls</code> (wrapping row of
controls for one visual), <code><hr></code> separator.</li>
<li><strong>Controls:</strong> <code>.btn</code>, <code>.btn-primary</code> (one main action per group),
<code>.btn-ghost</code>, <code>.btn-block</code>; <code>.form-label</code>, <code>.form-control</code>, <code>.form-select</code>,
<code>.form-range</code> (show the current value and units right before it),
<code>.form-check</code> / <code>.form-switch</code> around a native checkbox,
<code>.form-control-color</code>. Use native <code>button</code>, <code>input</code>, <code>select</code>, <code>textarea</code>;
never recreate controls or add <code>tabindex</code>.</li>
<li><strong>Tabs:</strong> <code>.nav.nav-pills[role="tablist"]</code> with <code>aria-label</code>, holding
<code>button.nav-link[role="tab"]</code> with a unique <code>id</code>, <code>type="button"</code>,
<code>aria-controls</code>, and <code>aria-selected</code>; mark the initial tab <code>.active</code>. Each
<code>[role="tabpanel"]</code> has the matching <code>id</code>, <code>aria-labelledby</code>, and <code>hidden</code>
when inactive. The runtime wires the behavior.</li>
<li><strong>Data:</strong> <code>.table</code> (add <code>.table-sm</code> for more rows; <code>.text-end</code>,
<code>.text-center</code>, <code>.text-nowrap</code> in cells), <code>.progress</code> + <code>.progress-bar</code> with
<code>role="progressbar"</code> and <code>aria-value*</code>, <code>.viz-badge</code> for a display-only
status pill, <code>.viz-tile</code> on a selectable dense-grid <code>.btn</code>.</li>
<li><strong>Text:</strong> <code>.text-small</code>, <code>.text-muted</code> (never for essential values),
<code>.text-destructive</code> (errors only), <code><code></code>, <code>.sr-only</code>.</li>
<li><strong>Tooltips:</strong> <code>data-tooltip="…"</code> on any focusable trigger or SVG mark,
optionally <code>data-tooltip-placement="top|right|bottom|left"</code>. The runtime
handles hover, focus, and touch. Never use <code>title</code> or custom tooltip markup
for these.</li>
<li>Use <code>.cursor-interaction</code> on custom interactive elements instead of
<code>cursor: pointer</code>.</li>
</ul>
<h2>Charts</h2>
<p>Preloaded <code>viz</code> helpers own sizing, redraw, axes, ticks, legends, tooltips,
and label overlap; never write that code yourself. For a standard chart,
describe it with <code>viz.render</code> instead of drawing it:</p>
<pre><code class="language-js">const c = viz.render("sales", { mark: "line", data, label: "Sales by month",
x: { field: "month", title: "Month" }, y: { field: "sales", title: "Sales (k)" },
color: "region" });
slider.oninput = () => c.update({ data: filter(slider.value) });
</code></pre>
<ul>
<li><code>mark</code>: <code>bar</code> (horizontal when <code>y</code> is categorical; <code>stack: true</code>),
<code>line</code>, <code>area</code> (stacks with <code>color</code>), <code>point</code> (<code>size</code>, <code>trend: true</code>
regression line), <code>heatmap</code> (<code>x</code>, <code>y</code>, <code>value</code>), <code>arc</code> (donut: <code>theta</code>,
<code>color</code>). Channels: a field name or <code>{ field, title, format, domain }</code>;
types are inferred (numbers, ISO dates, categories). Optional <code>tooltip: (d) => text</code>, <code>height</code>.</li>
<li><code>viz.regression(data, x, y)</code> → <code>{ slope, intercept, r }</code>.</li>
</ul>
<p>For custom visuals use <code>viz.chart(el, ({ svg, width, height, compact }) => {...}, { label })</code>,
which redraws an emptied, container-sized SVG on width or theme change
(and on <code>redraw()</code>); inside it <code>viz.plot(svg, width, height)</code> →
<code>{ g, innerWidth, innerHeight }</code>, <code>viz.axes(g, { x, y, innerWidth, innerHeight, xLabel, yLabel })</code>,
<code>viz.extent(data, accessor, { zero })</code>, <code>viz.series(i)</code>, <code>viz.duration(ms)</code>,
<code>viz.pruneOverlaps(labels)</code>.</p>
<ul>
<li>Title axes with quantity and units.</li>
<li>Custom marks get tooltips via <code>data-tooltip</code>; isolated marks need 32px
hit targets.</li>
<li>Animate only state transitions, with <code>viz.duration</code>; never loop motion.</li>
<li>Scope custom SVG styles to the chart's class.</li>
</ul>
<h2>Accessibility</h2>
<ul>
<li>Use semantic HTML, keyboard-accessible controls, and concise labels.</li>
<li>Give every chart (<code>viz.chart</code> <code>label</code>), SVG, and canvas a screen-reader
summary (<code>aria-label</code> or an <code>.sr-only</code> description).</li>
<li>Use <code>aria-live="polite"</code> for dynamic results and <code>role="alert"</code> for
validation errors; do not announce every hover or frame.</li>
<li>Keep essential content and actions available without hover, and keep
browser focus styles.</li>
<li>Keep visible text in the user's language.</li>
</ul>