<notatio-contour-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("contourplot");
const isNumber = (v: unknown): v is number => typeof v === "number" && Number.isFinite(v);
/** A 2-D numeric matrix (for data, the ListContourPlot path). */ function toMatrix(data: unknown): number[][] | undefined { if (!Array.isArray(data) || data.length === 0 || !data.every((r) => Array.isArray(r))) return undefined; const rows = (data as unknown[][]).map((r) => r.filter(isNumber)); return rows.every((r) => r.length === rows[0].length) ? rows : undefined; }
/** <notatio-contour-plot expr="x^2 - y^2" xrange="-3,3" yrange="-3,3"> -- the contour lines of a bivariate expression (Wolfram's ContourPlot): the expression is sampled on an n×n grid over xrange/yrange (substituting the two free variables) and iso-lines are extracted at several levels via marching squares. levels accepts either a level count or an explicit JSON array of level values; omitted, ~8 evenly spaced levels are chosen between the sampled min and max. filled shades the bands between levels with a sequential ramp instead of drawing lines. data (a JSON 2-D array) plots a pre-sampled grid directly, skipping expression evaluation (ListContourPlot).
Attributes
| Attribute | Type | Default | Notes |
|---|---|---|---|
expr | string | "" | The bivariate expression, in notatio. |
xvar | string | "" | The variable on the x axis; defaults to the expression's first unknown. |
yvar | string | "" | The variable on the y axis; defaults to the next unknown after xvar. |
xrange | string | "-3,3" | The x sampling range, as lo,hi. |
yrange | string | "-3,3" | The y sampling range, as lo,hi. |
n | number | 40 | Grid resolution per side. |
levels | string | "" | A contour count, or an explicit JSON list of level values. |
filled | string | "false" | Anything but "false" shades the bands between contours. |
axes | string | "true" | "false" hides the axes. |
x-label property xLabel | string | "" | Axis label for x. |
y-label property yLabel | string | "" | Axis label for y. |
label | string | "" | Caption drawn above the figure. |
data | string | "" | A pre-sampled grid as a JSON matrix, plotted instead of expr. |