figure Card

Figure Cards

A figure is a small, embeddable interactive graphic that demonstrates one thing — a p5.js sketch, a three.js scene, a D3/SVG graphic, or a canvas-loop TEA sketch.

The card's markdown body describes what the figure demonstrates (its intent). The runnable code does not live in the body — it lives in a .ts file inside the card's attach scope, and the entry field points to it.

Making a good figure usable

Whatever a figure is for, these make it usable and clear:

Frontmatter

The source (entry)

The entry module is authored in the runtime's own style (not React) and default-exports (lib, { mount, figure }) => teardown:

(The mount element and figure context travel together in the second argument because positional params are capped at two.)

// attach/sketch.ts  (p5js)
export default function (p5, { mount, figure }) {
  const width = () => Math.min(mount.clientWidth || 360, 640);
  const instance = new p5((p) => {
    p.setup = () => p.createCanvas(width(), Math.round(width() * 0.75));
    p.draw = () => { /* derive layout from p.width / p.height, not a constant */ };
  }, mount);
  const ro = new ResizeObserver(() => {
    if (instance.width !== width()) instance.resizeCanvas(width(), Math.round(width() * 0.75));
  });
  ro.observe(mount);
  return () => { ro.disconnect(); instance.remove(); };
}

Embedding

Embed a figure inline in a card or document body with the image/embed syntax![caption](…figure.card) (a plain box path, like an image) — passing parameters in the query string. It renders frameless (just the figure) in place. A plain [label](…figure.card) link (no !) stays a navigable link, not an embed.

caffeine

The sketch reads those values from figure.params; the caption (alt text) shows beneath the figure.

canvas-loop figures (deterministic TEA sketches)

For runtime: canvas-loop the entry is a TEA sketch module — canvas-loop's Elm-style contract: named exports params/init/update/draw (+ optional canvas) — plus a one-line default figure factory beneath them:

export default (cl, { mount, figure }) =>
  cl.mountSketch(mount, { module: { params, init, update, draw }, initialParams: figure.params });

The contains: field

Give this card a one-sentence contains: — the prime retrieval field for bbx search and listings. How to write a good one (carry the information when it's concise, never a list of parts, under 200 characters) is in the agent guide's ABOUT_CARDS section.

Templates

figure

An embeddable interactive figure (p5.js / three.js / D3 / canvas-loop); scaffolds a runnable starter sketch

bbx create <path>.figure.card -t figure

Template: figure Description: An embeddable interactive figure (p5.js / three.js / D3 / canvas-loop); scaffolds a runnable starter sketch Card types: figure

Arguments: runtime: Runtime: p5js | three | d3 | canvas-loop title (optional): Display title