<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).
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. |
zrange | string | "" | Clamp the colour ramp, as lo,hi; empty fits the sampled values. |
n | number | 48 | Grid resolution per side. |
legend | string | "false" | Anything but "false" draws the colour ramp beside the plot. |
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. |