<notatio-polar-plot>
Parse a JSON attribute defensively -- an empty/invalid value reads as undefined. */ function parseJson(value: string): unknown { const text = value.trim(); if (!text) return undefined; try { return JSON.parse(text); } catch { return undefined; } }
const log = debug("polarplot");
const isNumber = (v: unknown): v is number => typeof v === "number" && Number.isFinite(v);
/** [[θ, r], ...] (or a bare [r, ...], indexed by sample) for ListPolarPlot. */ function toPolarPoints(data: unknown, t0: number, t1: number): PolarPoint[] | undefined { if (!Array.isArray(data) || data.length === 0) return undefined; if (data.every((p) => Array.isArray(p) && p.length >= 2 && p.every(isNumber))) return (data as number[][]).map(([theta, r]) => ({ theta, r })); if (data.every(isNumber)) { const n = data.length; return (data as number[]).map((r, i) => ({ theta: n > 1 ? t0 + ((t1 - t0) * i) / (n - 1) : t0, r, })); } return undefined; }
/** <notatio-polar-plot expr="1 + \cos(\theta)" trange="0,6.283"> -- a curve r(θ) on a polar grid (Wolfram's PolarPlot). expr is sampled at n angles across trange; poles (non-finite r) break the curve rather than joining branches. data gives ListPolarPlot: a JSON list of [θ, r] pairs, or bare radii spread evenly over trange.
Attributes
| Attribute | Type | Default | Notes |
|---|---|---|---|
expr | string | "" | The radius r(θ), in notatio. |
tvar | string | "" | The angle variable; defaults to the expression's first unknown, else theta. |
trange | string | "0,6.283185307179586" | The angular sweep, as lo,hi in radians. |
n | number | 240 | Sample count across the sweep. |
max | number | 0 | Clamp the radial axis; 0 fits the samples. |
axes | string | "true" | "false" hides the polar grid. |
closed | string | "false" | Anything but "false" joins the last point back to the first. |
filled | string | "false" | Anything but "false" shades the region the curve encloses. |
markers | string | "" | "false" hides the point markers on an explicit data list. |
label | string | "" | Caption drawn above the figure. |
data | string | "" | An explicit point list — [[θ,r],…] or bare radii — plotted instead of expr. |