<notatio-vector-plot>
Split a field attribute into its two components. Handles an optional \{...\}, {...} or (...) wrapper and only splits on a comma at brace / paren depth zero, so \{\frac{y}{2}, -x\} survives intact. / export function splitField(raw: string): [string, string] | undefined { let s = raw.trim(); const unwrap: [string, string][] = [ ["\\{", "\\}"], ["\\left(", "\\right)"], ["{", "}"], ["(", ")"], ["[", "]"], ]; for (const [open, close] of unwrap) { if (s.startsWith(open) && s.endsWith(close)) { s = s.slice(open.length, s.length - close.length).trim(); break; } } let depth = 0; for (let i = 0; i < s.length; i++) { const c = s[i]; if (c === "{" || c === "(" || c === "[") depth++; else if (c === "}" || c === ")" || c === "]") depth--; else if (c === "," && depth === 0) { const u = s.slice(0, i).trim(); const v = s.slice(i + 1).trim(); if (u && v) return [u, v]; return undefined; } } return undefined; }
const log = debug("vectorplot");
/** <notatio-vector-plot u="-y" v="x" xrange="-2,2" yrange="-2,2"> -- a planar vector field (Wolfram's VectorPlot): u/v are the two components in notatio, or field="-y, x" gives both at once. Arrows sit on an n×n grid of cell centres, their length and colour scaling with |F|.
type="stream" switches to StreamPlot: streamlines traced from the same grid by fixed-step RK4 on the normalised field -- deterministic, so the same field always draws the same picture (no random seeding).
Attributes
| Attribute | Type | Default | Notes |
|---|---|---|---|
u | string | "" | The x component of the field, in notatio. |
v | string | "" | The y component of the field, in notatio. |
field | string | "" | Both components at once, comma-separated — "-y, x". |
xvar | string | "x" | The variable on the x axis; defaults to the expression's first unknown. |
yvar | string | "y" | The variable on the y axis; defaults to the next unknown after xvar. |
xrange | string | "-2,2" | The x sampling range, as lo,hi. |
yrange | string | "-2,2" | The y sampling range, as lo,hi. |
n | number | 0 | Arrows (or streamline seeds) per side. |
type | "vector" | "stream" | "vector" | vector for arrows, stream for RK4 streamlines. |
steps | number | 60 | Streamline integration steps taken in each direction from a seed. |
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. |