Prism visualizations in Obsidian
Prism renders ```viz code blocks inline in notes: sandboxed iframe, bundled offline libraries, Obsidian theme colors, automatic height. Your loop: plan → write the block → render it from the command line → read errors and look at the snapshot → fix, until the render is clean.
0. Before you start
Vault root: the nearest ancestor of the working directory that contains
.obsidian/plugins/prism-viz/. If there is none, use{{VAULT}}. If Prism is not installed there, tell the user and do not write viz blocks.Skill version: compare the version in the first lines of
reference.md("Prism … v0.7.0") with"version"in<vault>/.obsidian/plugins/prism-viz/manifest.json. If they differ, tell the user the skill is outdated and give them this command to update it (Node.js and git needed; replace <version> with the manifest version), then continue with this skill:d="$(mktemp -d)" && (git clone --depth 1 --branch <version> https://github.com/floorianmb/prism-viz.git "$d" 2>/dev/null || (rm -rf "$d" && git clone --depth 1 https://github.com/floorianmb/prism-viz.git "$d")) && node "$d/scripts/install-skill.mjs" --vault '{{VAULT}}' && rm -rf "$d"On Windows, or to copy the command with everything filled in, use the Obsidian command Prism: Install agent skill. Restart the agent afterwards so it loads the new skill.
Reference: read
reference.mdnext to this file before writing the first block of a session. It has the full syntax, thewindow.prismAPI, design rules and the error format.Design: read
design.mdnext to this file before the first block of a session. It sets the quality bar (composition, color, controls, motion) and the polish pass in step 3.Vault conventions win: follow the vault's own
AGENTS.md/CLAUDE.mdfor notes (frontmatter, indexes, logs, language). Prism blocks are content like any other paragraph.Never edit or delete anything in
<vault>/.prism/(Prism owns these files) or the plugin'sdata.json(user settings and widget state).
1. Plan
Where: as a new section in the note the user means, or a new note if asked. Do not change other existing blocks unless that is the task.
Data source: pick exactly one per block:
| Data | Use | Never |
|---|---|---|
| Note metadata (type, status, tags, dates, folders) | a declarative ```viz chart / ```viz table with source: notes (folder, tag, aggregate: count), or prism.notes({ folder, tag, limit }) for custom layouts |
copying note lists into the block |
| Tasks across notes (open per project, done per day, overdue) | a declarative ```viz chart / ```viz table with source: tasks (folder, tag, filter: { done: false }, aggregate: count) |
parsing note text yourself |
| Links, backlinks, headings, or tasks in a custom layout | prism.notes({ include: ["tasks"] }) (also "links", "backlinks", "headings") |
parsing note text yourself |
| A small table the reader should see and edit | a Markdown table in the note + ^id line, charted with a declarative ```viz chart block (source: ^id) or (await prism.note()).table("^id") |
duplicating the numbers inside the block |
| Parameters of this note (e.g. a coefficient in frontmatter) | (await prism.note()).frontmatter |
hard-coding the value in several blocks |
| CSV / TSV / JSON / YAML / TXT files in the vault | prism.data("path/file.csv") |
pasting the file content into the block |
| A few values the user gives you | inline array in the script | – |
| Web APIs / websites | only if the user enabled Settings → Prism → Online access: prism.http(url) / prism.http.json(url) for APIs, ```viz web for a website (see reference); otherwise not available – never ask the user to enable it as a workaround |
fetch, CDN <script src>, remote images, API keys in the block |
For prism.data: check settings.dataFolders in <vault>/.obsidian/plugins/prism-viz/data.json (read only). If the file's folder is not listed, ask the user to add it under Settings → Prism → Data folders – do not change the setting yourself.
Performance of a note ("how heavy is this page", RAM/CPU of a note or block): add an empty ```viz monitor block – it shows RAM in MB and CPU in % of the whole machine for that page. For per-block figures or a custom view use prism.perf.watch(cb). Say that block figures are estimates (script time, graphics buffers) while web views and the Obsidian process are measured by the operating system, and that process figures need the desktop app. A command-line render only shows the first second.
Online data (APIs, websites): read settings.online in <vault>/.obsidian/plugins/prism-viz/data.json (read only) – http (prism.http allowed), httpConfirm (requests wait for the reader's "Run requests" click; default), web (```viz web and iframes allowed). Build the block for what is enabled and make every other state readable (off / waiting for click / loading / error / data); follow "Live data from web APIs" in reference.md (states, caching in prism.state, parameters in frontmatter, no keys in blocks). If the needed switch is off, say so and offer a vault-file alternative (a CSV the user or a script updates, read with prism.data) – never change the setting yourself.
Library (fence keywords): chart for standard charts (bar, line, pie, scatter) – prefer the declarative YAML form (no HTML, see reference) when the data is a table, CSV, frontmatter or tasks; in the same form type: calendar for one value per day (journal, habits, tasks done – "how often / which days") and type: map for values per region from a GeoJSON file in a data folder (Prism ships no map data: ask for the file if there is none, never invent coordinates); type: kpi for big numbers with change to the last period and a goal bar (add x + group for the trend); type: timeline for plans and Gantt charts from tasks or notes with start/end dates; type: sankey for flows (budget, funnel) from from/to/y rows; type: graph with source: links for the link network of notes; group: month (or day, week, quarter, year) to count or sum dates per period; goal: N or lines: [...] for target lines on bar/line charts; compute: { name: "expr" } for derived columns; d3 for custom layouts and maps with special needs; mermaid for flowcharts, sequence diagrams, Gantt, mind maps written as text; math (KaTeX) for formulas – a ```viz math block with plain LaTeX, or $…$ inside HTML blocks; plain SVG without keyword for architecture and box-and-arrow diagrams; three only for explicit 3D requests.
Clicking a chart without select opens what is behind it (the table row in this note, the note, the task's line), so a chart over notes or tasks needs no handler. Add select only to filter other blocks.
Dashboards that filter by clicking (cross-filter): give the overview chart select: <key> and the detail charts/tables filter: { <column>: $shared.<key> } – a click on a bar, segment, day or region filters the others, a second click shows all again. No JavaScript needed; prefer this over hand-written click handlers. Say in the note text above the blocks that a click filters (and clicks again to reset).
Interactive explanations: put controls (sliders, selects) in one block and bind them with prism.shared.bind("#slider", "key", default, onValue); other blocks of the same note read prism.shared.get("key") and redraw in prism.shared.onChange(draw). Text between the blocks explains what changes.
Scenes and animations: use the building blocks instead of hand-written boilerplate – prism.canvas (crisp, resizing canvas), prism.animate (frame loop that pauses off screen and respects reduced motion), prism.segmented (mode switch), and the classes .toolbar, .stage, .hud, button.chip, button.icon-button, .caption. Blocks stay short, which also makes them faster to write.
Widgets that change the note (habit trackers, checklists, task boards, quick-entry forms): keep the data in the note as tasks, a Markdown table with ^id or frontmatter, and change it with prism.edit.setTask / setCell / addRow / setProperty. Update the clicked element at once and redraw from prism.note() in prism.onNoteChange. Tell the user that the block asks once ("Allow edits") before its first change. A command-line render never edits, so the snapshot shows the unchanged note.
Sharing outside Obsidian (Publish, GitHub, other apps show viz blocks as code): tell the user about the command Prism: Bake blocks as images, which links a PNG below each block that only shows where Prism does not run. Do not write ![Prism snapshot…] lines yourself.
Several views of the same data: prism.variants (e.g. bar / line / table) instead of picking one.
Scrollytelling (a visual that follows the text): one block above a few short sections reacts to prism.onSection(cb), which reports the heading the reader is at. Name the sections so the block can map them (e.g. "Step 1: …").
Tables of data (e.g. CSV files with source/confidence columns): a ```viz table block with source: path/file.csv gives search, sorting, number formatting and clickable sources without code.
Diagrams that navigate: in Mermaid labels write A["[[Note name]]"]; clicking the node opens the note.
Bases: for a chart over a filtered set of notes the user maintains as a .base file, suggest the built-in Bases view "Prism chart" (no code) instead of a viz block.
2. Write
Checklist for every block:
- Fence:
```viz <libraries> title="Short caption". Addid=<slug>whenever the block usesprism.state(otherwise state is keyed by block position; Prism moves it along when blocks are inserted or removed, but only an id is reliable). Adding an id to an existing block keeps its state. - Do not add
eager: it disables lazy rendering, so every block of the note runs at once. Use it only when a block must run before it is scrolled into view, and say why. - Colors only from Obsidian CSS variables (
var(--text-normal),var(--interactive-accent),var(--color-blue)…) orprism.palette. No hex colors, no white or black backgrounds; the page background stays transparent; use.card,.grid,.row,.kpi,.label,.muted. Only exception: a dark stage for scenes such as simulations (seedesign.md). - Chart.js: put the canvas in a container with explicit height, e.g.
<div style="height:280px"><canvas id="c"></canvas></div>, and setmaintainAspectRatio: false. Leave dataset colors unset; Prism applies the theme palette. - No
100vh, noheight:100%on html/body, noposition:fixed. SVG:viewBoxpluswidth:100%; height:auto, styled through a<style>block, notfill="var(...)"attributes. - Handle empty or missing data with a visible message instead of an empty chart.
- With
prism.notes,prism.dataorprism.note, redraw onprism.onNotesChange(draw),prism.onDataChange(draw)orprism.onNoteChange(draw)and destroy old Chart instances before redrawing (chart?.destroy()). Declarative charts redraw by themselves. - In the note text before the block: one sentence on what it shows and, for file data, a relative Markdown link to the data file as its source. Labels and text in the note's language.
3. Verify (mandatory after every edit)
First the offline check. It needs no running Obsidian and finds YAML errors, unknown keys, missing tables and columns and syntax errors in scripts in a second:
node "<vault>/.obsidian/plugins/prism-viz/scripts/prism-render.mjs" --lint "<note path relative to the vault>"
Same JSON shape as the render (status, per block errors[{ kind, line, message }]); --lint --all [folder] checks every note. Exit 0 = ok/warning, 1 = errors, 4 = file not found. It is static: nothing runs, so runtime errors and the picture are not checked. Fix every error, then render:
node "<vault>/.obsidian/plugins/prism-viz/scripts/prism-render.mjs" "<note path relative to the vault>"
The note does not need to be open; Obsidian stays in the background. Output is JSON: status and per block status, errors[{ kind, line, message }], snapshotFile.
- Exit 0 (ok/warning): read any warnings and fix the ones you caused.
- Exit 1 (block errors):
lineis the 1-based line in the note. Fix each error, then render again. - Exit 2 (failed): read
message(wrong path, no viz blocks). - Exit 3 (Obsidian not reachable): ask the user to open Obsidian with this vault and Prism enabled, then retry. If that is not possible, tell the user the block is unverified; after they open the note,
.prism/errors.json→blocks["<note path>#<id>"]for a block withid=, otherwiseblocks["<note path>#<index>"](0-based position among the note's viz blocks) shows the result (check thatrenderedAtis newer than your edit). - Look at every
snapshotFile(open the PNG): Is the chart empty? Labels cut off or overlapping? Legend covering data? Text unreadable against the background? Fix the layout and render again. - Polish pass: once the render is clean, run the checklist at the end of
design.mdon the snapshot and do one improvement round. For interactive blocks, also render the other states (temporarily change the defaults, then restore them). - API blocks: with
httpConfirmon (default) a command-line render sends no request, so the block shows its waiting (or cached) state. That is correct – check that state, then tell the user to click "Run requests" in Obsidian. Do not addeageror work around the click. - Stop after three fix rounds and report what is still wrong instead of looping.
change(blocks that were rendered with a snapshot before):pixelsis how much of the snapshot changed in percent,before/afterthe sizes. Expect a change only in the blocks you edited. A big change or a size jump in another block, or a much larger change than your edit explains, means something broke: look at its snapshot and fix it.- To check the whole vault (e.g. after a Prism update), run the script with
--all --snapshot; it prints one line per note (with the number of changed blocks) and a JSON summary whosechangedlists the blocks that look different than last time.
Common errors:
| Message | Cause | Fix |
|---|---|---|
Chart is not defined / d3 / mermaid / THREE |
library keyword missing | add chart / d3 / mermaid / three to the fence |
csp … Blocked by Content-Security-Policy |
network access | use prism.data / prism.notes or inline the data |
prism.http is off |
Online access → API requests disabled | the block must show this as a readable message; tell the user, do not enable it |
prism.data is off / outside the data folders |
folder not allowlisted | ask the user to add the folder in Prism settings |
.md files are not readable |
prism.data on a note |
use prism.notes for metadata, prism.note() for tables/frontmatter of the block's own note |
prism.note().table(…): no such table |
wrong id/heading, or ^id not on its own line after the table |
the message lists the tables; put ^id on its own line after a blank line |
prism.chart: column "…" not found |
YAML spec names a column that is not in the header | use the exact header text (case-sensitive); with source: notes the columns are title, the frontmatter properties, folder, path, modified, tags |
prism.chart: group must be one of … / N rows have no date in … |
unknown period, or x is not a date column |
day, week, month, quarter or year; set x to a column with YYYY-MM-DD values |
prism.chart: compute "…": … |
syntax error or unknown column in an expression | names of columns exactly as in the header (backticks for spaces); only + - * / %, round floor ceil abs min max days today |
prism.chart: type sankey cannot show cycles |
a flow leads back to an earlier node | remove or rename the returning link (the warning lists the dropped ones) |
prism.chart: lines must be a list … / "lines" and "goal" do not apply |
wrong shape, or a pie/radar/calendar/map | lines: [{ y: 30, label: "Goal" }] on bar, line, area, scatter, bubble only |
prism.chart: aggregate must be one of … |
unknown aggregate value |
use count, sum, avg, min or max |
| Calendar shows "No data: no dates (YYYY-MM-DD) in …" | x is not a date column |
set x to a column with YYYY-MM-DD values (doneDate/due for tasks, a date property, or title for daily notes) |
prism.chart: type map needs "geo" / contains no Polygon or MultiPolygon features |
no or wrong GeoJSON file | geo: a .geojson/.json file with region polygons in a data folder |
prism.chart: no region of … matches "…" |
names/codes in x differ from the GeoJSON properties |
use the exact names, or set geoKey to the property that holds them (open the GeoJSON to see its properties) |
prism.chart: "folder" and "tag" only apply to source: notes, tasks and links |
folder/tag with a table or file source |
remove them, or use filter |
prism.edit: notes are never changed in command-line renders … |
expected in a command-line render | not an error of the block: make sure the block catches it and still shows the note's current state |
prism.edit is off / the reader did not allow … |
the user switched edits off or clicked "Don't allow" | the block must show the message; tell the user, do not work around it |
prism.edit: no column … / no table … / row N does not exist / no task … |
wrong table ref, header or row index | use the header text and ^id from the note; rows are 0-based like note.table() rows |
KaTeX: … |
LaTeX syntax | fix the formula; \ and {} must be balanced |
Mermaid: Parse error on line N |
Mermaid syntax | N counts lines inside the block (note line = fence line + N); quote labels with special characters: A["Label (x)"] |
Auto-height stopped |
100vh / height:100% |
remove it, or set height=N on the fence |
Prism stopped a loop |
loop never ends or blocks > 2 s | fix the loop condition; split heavy work |
timeout |
slow or blocking code | simplify, reduce data, avoid synchronous heavy work |
4. Report
Tell the user briefly: what you added and where (note and section), the data source, the final render status and the snapshot path. Interactive behavior (clicks, sliders) is not covered by the snapshot – say so if the block is interactive. For API blocks say which host is called, whether a click on "Run requests" is needed, and how long the cache lasts. For blocks that use prism.edit say what they change in the note, that the first click asks "Allow edits" (again after the block's code changes), and that Cmd/Ctrl+Z undoes a change.
Patterns
Chart from a CSV file:
```viz chart title="Units per year"
<div style="height:280px"><canvas id="c"></canvas></div>
<p class="muted" id="msg"></p>
<script>
let chart;
async function draw() {
const rows = await prism.data("Projects/data/units.csv");
if (!rows.length) { document.getElementById("msg").textContent = "No data."; return; }
chart?.destroy();
chart = new Chart(document.getElementById("c"), {
type: "line",
data: { labels: rows.map(r => r.year), datasets: [{ label: "Units", data: rows.map(r => r.units) }] },
options: { maintainAspectRatio: false },
});
}
draw();
prism.onDataChange(draw);
</script>
```
Chart from note metadata, no code (source: notes):
```viz chart title="Projects by status"
type: doughnut
source: notes
folder: Projects
x: status
aggregate: count
sort: -count
```
Days at a glance, no code (daily notes named YYYY-MM-DD with a mood property; a click opens the day's note):
```viz chart title="Mood per day"
type: calendar
source: notes
folder: Journal
y: mood
```
Revenue per month with a goal line, and KPI tiles, no code (^umsatz is a table of the note with date and Umsatz):
```viz chart title="Revenue per month"
type: bar
source: ^umsatz
x: date
y: Umsatz
group: month
goal: 40000
```
```viz chart
type: kpi
source: ^umsatz
x: date
y: Umsatz
group: month
format: eur
```
Plan from tasks, no code (tasks with ⏳ start and 📅 due dates):
```viz chart title="Plan"
type: timeline
source: tasks
folder: Projects
start: scheduled
end: due
```
Open tasks per project, no code:
```viz chart title="Open tasks"
type: hbar
source: tasks
folder: Projects
filter: { done: false }
x: note
aggregate: count
sort: -count
```
Cross-filter: a click on a genre filters the table (click again to show all):
```viz chart title="Books per genre"
type: doughnut
source: ^books
x: genre
aggregate: count
select: genre
```
```viz table title="Books"
source: ^books
filter: { genre: $shared.genre }
```
Widget that edits its note (checklist over the tasks of this note):
```viz title="Checklist"
<div id="list" class="stack"></div>
<p class="caption" id="msg"></p>
<script>
async function draw() {
const { tasks } = await prism.note();
const msg = document.getElementById("msg");
if (!tasks.length) { msg.textContent = "No tasks in this note yet."; return; }
msg.textContent = `${tasks.filter(t => t.done).length} of ${tasks.length} done`;
document.getElementById("list").replaceChildren(...tasks.map(t => {
const label = Object.assign(document.createElement("label"), { className: "row" });
const box = Object.assign(document.createElement("input"), { type: "checkbox", checked: t.done });
// The checkbox shows the change at once; the edit asks "Allow edits" on first use.
box.onchange = () => prism.edit.setTask(t, box.checked).catch(e => { box.checked = !box.checked; msg.textContent = e.message; });
label.append(box, document.createTextNode(t.text));
return label;
}));
}
draw();
prism.onNoteChange(draw); // right after an edit, and while the user types
</script>
```
Overview from note metadata with a custom layout:
```viz title="Open drafts"
<div class="grid" id="cards"></div>
<script>
async function draw() {
const notes = (await prism.notes({ folder: "Projects" })).filter(n => n.frontmatter.status === "draft");
document.getElementById("cards").replaceChildren(...notes.slice(0, 12).map(n => {
const card = Object.assign(document.createElement("div"), { className: "card" });
const link = Object.assign(document.createElement("a"), { href: "#", textContent: n.title });
link.onclick = e => { e.preventDefault(); prism.openNote(n.path); };
card.append(link, Object.assign(document.createElement("div"), { className: "label", textContent: n.folder }));
return card;
}));
}
draw();
prism.onNotesChange(draw);
</script>
```
Animated scene with a mode switch (building blocks):
```viz id=scene title="Short caption"
<div class="toolbar"><div id="mode"></div><button class="icon-button" id="play"></button></div>
<div class="stage" id="stage"><div class="hud"><span id="hud"></span></div></div>
<p class="caption">What the reader should notice.</p>
<script>
const scene = prism.canvas("#stage");
let mode = "A", loop; // declared before segmented(): onChange runs at once
prism.segmented("#mode", ["A", "B"], { key: "mode", onChange: (v) => { mode = v; loop?.redraw(); } });
loop = prism.animate((dt, t) => {
const { ctx, width, height } = scene;
scene.clear();
// draw the frame for `mode` at time t (dt = 0 on the first call)
document.getElementById("hud").innerHTML = `t = <b>${prism.format(t, "number", 1)}</b>`;
});
const play = document.getElementById("play");
const icon = (on) => (play.innerHTML = on ? '<svg viewBox="0 0 16 16"><path d="M4 2.5h3v11H4zM9 2.5h3v11H9z"/></svg>' : '<svg viewBox="0 0 16 16"><path d="M4.5 2.5v11l9-5.5z"/></svg>');
loop.onChange(icon); icon(loop.playing); play.onclick = () => loop.toggle();
scene.onResize(() => loop.redraw());
</script>
```
Diagram as text:
```viz mermaid
flowchart LR
A[Source] --> B{Check} -->|ok| C[Publish]
B -->|error| A
```