Skip to content

<notatio-density-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("densityplot");

const isNumber = (v: unknown): v is number => typeof v === "number" && Number.isFinite(v);

/** A 2-D numeric matrix (for data, the ListDensityPlot 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 && r.length > 0) ? rows : undefined; }

/** <notatio-density-plot expr="\sin(x)\cos(y)" xrange="-3,3" yrange="-3,3"> -- a bivariate function as a heatmap (Wolfram's DensityPlot): the expression is sampled on an n×n grid and each sample is shaded on a sequential ramp. legend adds a colour bar; zrange pins the colour scale so several plots can share one. data (a JSON 2-D array) shades a pre-sampled grid directly (ListDensityPlot).

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

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.
zrangestring""Clamp the colour ramp, as lo,hi; empty fits the sampled values.
nnumber48Grid resolution per side.
legendstring"false"Anything but "false" draws the colour ramp beside the plot.
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.