Skip to content

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

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

Attributes

AttributeTypeDefaultNotes
exprstring""The bivariate expression, in notatio.
xvarstring""The variable on the x axis; defaults to the expression's first unknown.
yvarstring""The variable on the y axis; defaults to the next unknown after xvar.
xrangestring"-3,3"The x sampling range, as lo,hi.
yrangestring"-3,3"The y sampling range, as lo,hi.
nnumber40Grid resolution per side.
levelsstring""A contour count, or an explicit JSON list of level values.
filledstring"false"Anything but "false" shades the bands between contours.
axesstring"true""false" hides the axes.
x-label
property xLabel
string""Axis label for x.
y-label
property yLabel
string""Axis label for y.
labelstring""Caption drawn above the figure.
datastring""A pre-sampled grid as a JSON matrix, plotted instead of expr.