Skip to content

<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.

Stories in the playground·packages/notatio-lit/src/notatio-polar-plot.ts· in Vue: <PolarPlot>

Attributes

AttributeTypeDefaultNotes
exprstring""The radius r(θ), in notatio.
tvarstring""The angle variable; defaults to the expression's first unknown, else theta.
trangestring"0,6.283185307179586"The angular sweep, as lo,hi in radians.
nnumber240Sample count across the sweep.
maxnumber0Clamp the radial axis; 0 fits the samples.
axesstring"true""false" hides the polar grid.
closedstring"false"Anything but "false" joins the last point back to the first.
filledstring"false"Anything but "false" shades the region the curve encloses.
markersstring"""false" hides the point markers on an explicit data list.
labelstring""Caption drawn above the figure.
datastring""An explicit point list — [[θ,r],…] or bare radii — plotted instead of expr.