GSX
GraphSX Playground
GraphSX, Markdown fences, and live editor widgets

Editor

Rendered Graph

100%
0 nodes

Documentation

Supported tags and examples

GraphSX Reference

GraphSX has two entry points. Use a standalone <Plot> for one scientific plot. Use <Graph> as a figure canvas for diagrams, subplots, mixed plot-and-diagram figures, and port-to-port links.

Use GraphSX directly in VS Code Markdown previews and Jupyter notebook Markdown cells with the GraphSX VS Code extension.
The syntax is intentionally JSX-like. If you already understand JSX, the shape should feel familiar: tags define components, props configure them, children nest inside parents, braces hold static values or arithmetic expressions, and backtick strings support template substitution.
Most visible components can be styled either inline with style={{ ... }} or through reusable style libraries: define <Style id="wire" stroke="#111" />, then apply it with useStyle="wire". Plot-specific boxes can also use dedicated props such as frameStyle, boxStyle, textStyle, and labelStyle.

Top-Level Documents

<Graph>

Auto-sized figure canvas for nodes, links, paths, reusable shapes, repeats, and nested plots.

<Plot>

Fixed-size plot figure with axes, ticks, data, lines, markers, legends, annotations, and optional animation.

Coordinates, Ports, And Addresses

at Places Things

In Graph, at uses figure screen units. It can be a literal point, a referenced port, or a referenced port plus vector arithmetic. Inside a Plot, annotation at uses data units by default; use atUnit="screen" for plot-pixel placement.

// Graph placement
<Rect id="A" at={[80, 120]} size={[100, 60]} />
<Rect id="B" at={A.right + [80, -20]} size={[100, 60]} />
<Rect id="C" at={B.top} anchor="bottom" size={[80, 40]} />

// Plot annotation placement
<Circle id="m" at={[2, 4]} r={5} />
<Text at={[2, 4]} label="peak" />
<Rect id="note" at={[430, 86]} atUnit="screen" size={[90, 28]} />

from / to Connect Ports

Link connects ports by quoted address in both Graph and plot annotations. This keeps links semantic: "A.right" means a port address, while {A.right} means a coordinate expression and is used for placement. Plot annotation shapes can expose ports just like graph nodes.

// Graph links
<Link from="A.right" to="B.left" />
<Link from="P1.child.out" to="P2.in" headArrow />

// Plot annotation links
<Rect id="note" at={[3.2, 7.8]} size={[80, 28]}>
  <Port id="tip" left />
</Rect>
<Circle id="peak" at={[3, 7]} r={5} />
<Link from="note.tip" to="peak.top" headArrow />

Repeat Syntax

Linear Repeat

Repeat expands its children count times. The variable named by as is available inside braces and backtick strings. step offsets repeated graph children.

<Repeat count={4} as="i" step={[90, 0]}>
  <Rect id={`box${i}`} at={[80, 120]} size={[60, 40]} label={`$A_${i}$`} />
</Repeat>

Links Inside Repeat

Links can be generated too. Use backtick strings when a port address depends on the repeat index.

<Repeat count={3} as="i">
  <Link from={`box${i}.right`} to={`box${i+1}.left`} />
</Repeat>

Nested Repeat

Nested repeats are useful for grids. Give each level a different variable name.

<Repeat count={3} as="row" step={[0, 80]}>
  <Repeat count={4} as="col" step={[90, 0]}>
    <Rect id={`n${row}_${col}`} at={[60, 60]} size={[52, 36]} />
  </Repeat>
</Repeat>

Routing And Layout

Routing

route controls link geometry. Use straight for direct segments, orthogonal for right-angle turns, bypass for residual-style side detours, and auto for simple obstacle-aware orthogonal routing. Straight routes can use a signed offset for connected parallel detours. Per-link props override graph defaults.

<Graph route="orthogonal" corner={8}>
  <Link from="A.right" to="B.left" />
  <Link from="A.right" to="B.left" route="straight" offset={12} />
  <Link from="A.top" to="B.left" route="bypass" side="left" offset={48} />
  <Link from="B.bottom" to="C.top" route="auto" grid={20} padding={18} />
</Graph>

Layout

Explicit at positions always win. When positions are omitted, layout="row" places nodes in source order, while layout="dag" uses links to rank connected nodes.

<Graph layout="dag" direction="right" rankGap={180} nodeGap={80}>
  <Rect id="A" size={[90, 50]} />
  <Rect id="B" size={[90, 50]} />
  <Rect id="C" size={[90, 50]} />
  <Link from="A.right" to="B.left" />
  <Link from="A.right" to="C.left" />
</Graph>

Ports And Angles

Side ports provide default routing directions. Custom ports can set angle, which gives orthogonal and auto routes a preferred direction as they leave or enter the shape.

<Port id="tap" at={[60, 20]} angle={35} />
<Link from="A.tap" to="B.left" route="orthogonal" />

Data Tag

Literal Data

Use points for explicit pairs, or separate x and y arrays when that is clearer.

<Data id="raw" points={[[0, 1], [1, 2], [2, 4]]} />
<Data id="xy" x={[0, 1, 2]} y={[1, 2, 4]} />
<Line data="raw" fmt=".-" />

Function Data

A string y expression generates sampled data over domain. The default variable is x, and the sampled domain value is stored as the point's x field. Constants and math helpers include pi, sin, cos, exp, sqrt, and pow.

<Data id="sin" y="sin(x)" domain={[0, 2*pi]} samples={160} />
<Line data="sin" label="$\sin(x)$" />

Parametric Data

When both x and y are expressions, GraphSX samples a parameter and stores the evaluated expressions as fields named x and y. The default variable is t; override it with variable.

<Data
  id="heart"
  x="16 * pow(sin(t), 3)"
  y="13*cos(t) - 5*cos(2*t) - 2*cos(3*t) - cos(4*t)"
  domain={[0, 2*pi]}
  samples={420}
/>

Parameters

params declares extra symbols used in generated data. This makes expressions explicit and gives animation a known starting value. Parameter values can also be complex strings such as "1j".

<Data
  id="fit"
  y="a * exp(-b*x)"
  params={{ a: 2.6, b: 0.28 }}
  domain={[0, 10]}
/>

Complex Values And Maps

Generated data may store complex x or y values. Plot coordinates use the real part by default. Use xMap and yMap on a series to project stored point fields into plotted coordinates.

<Data id="phase" y="exp(1j*t)" variable="t" domain={[0, 2*pi]} />
<Line data="phase" xMap="real(y)" yMap="imag(y)" />

<Data id="root" y="sqrt(x)" domain={[-1, 1]} />
<Line data="root" yMap="imag(y)" />

Animation

Animated Series

Animation belongs to the rendered series. The series references a Data object, then animates one or more declared data parameters.

<Data id="wave" y="sin(x - phase)" params={{ phase: 0 }} domain={[0, 2*pi]} />
<Line
  data="wave"
  animate={{ phase: [0, 2*pi], duration: 2.6 }}
/>

How It Updates

The plot is rendered once with animation metadata. During playback, GraphSX regenerates the affected series data for the current frame and updates that SVG series, leaving unrelated page DOM alone.

Multiple Parameters

Each animated series owns its own parameter values. Different lines can animate the same parameter name independently because the values are scoped to their data source and series.

<Line data="waveA" animate={{ phase: [0, 2*pi] }} />
<Line data="waveB" animate={{ phase: [pi, 3*pi] }} />

Supported Tags And Children

Tag Where Allowed Children Key Props Purpose
GraphTop levelStyle, Shape, Rect, Circle, Point, Anchor, Plot, Link, Path, Repeatroute, layout, direction, x, y, gap, rankGap, nodeGap, grid, padding, cornerGeneral diagram and figure canvas.
RectGraph, Shape, plot annotationsPortid, at, x, y, size, w, h, label, corner, anchor, origin, rotate, flipX, flipY, style, useStyleRectangle node with default side ports.
CircleGraph, Shape, plot annotationsPortid, at, x, y, r, label, anchor, origin, rotate, flipX, flipY, style, useStyleCircle node with default side ports.
Point, AnchorGraph, ShapePortid, at, x, y, label, r, style, useStyleShapeless anchor with default center port.
PlotTop level, GraphPort in graph use; plot children such as Data, Axis, Line, Legend, annotation tagsid, at, width, height, padding, xDomain, yDomain, frame, frameStyle, box, styleStandalone plot or placed subplot panel.
Port, LegNodes, shapes, nested graph plotsNoneid, left, right, top, bottom, side, at, x, y, angle, target, label, r, style, useStyleDefines a connection point.
LinkGraph, Shape, plot annotationsNonefrom, to, route, side, offset, grid, padding, corner, headArrow, tailArrow, arrowSize, style, useStyleConnects quoted port addresses such as "A.right".
PathGraph, Shape, plot annotationsNoneid, points, d, at, corner, closed, headArrow, tailArrow, arrowSize, rotate, flipX, flipY, style, useStyleExplicit geometry from points or SVG d.
ShapeGraph, librariesGraph node tags, Port, Link, Path, Repeatid, from, groupBox, plus user-defined props forwarded to childrenReusable composite shape definition.
RepeatGraph, ShapeAny repeatable graph or shape childcount, as, stepExpands repeated nodes, links, and paths with an index variable.
StyleGraph, Plot, librariesNoneid, plus SVG style props such as fill, stroke, strokeWidth, opacity, strokeDasharrayReusable style referenced by useStyle.
DataPlotNoneid, points, x, y, domain, samples, params, variableNamed data from points, x/y arrays, generated functions, or parametric expressions.
AxisPlotTicksx, y, label, ticks, grid, labelGap, tickLabelGap, tickSize, style, labelStyleX or Y axis with labels, ticks, and grid.
TicksAxisNonevalues, labels, grid, labelGap, tickLabelGap, tickSize, style, labelStyleExplicit tick values and optional labels.
Line, CurvePlotNonedata, points, x, y, xMap, yMap, fmt, label, animate, stroke, strokeWidth, fill, r, style, useStyleDraws data as connected series.
Mark, Point, ScatterPlotNonedata, at, points, x, y, xMap, yMap, r, label, animate, fill, stroke, style, useStyleDraws data as markers.
Text, LabelPlotNoneat, label, fontSize, anchor, baseline, rotate, style, useStyleText or KaTeX label at data coordinates.
LegendPlotNoneposition, box, padding, margin, fontSize, textStyle, boxStyleLegend generated from labeled series.
Canonical tags use PascalCase. Accepted aliases include rect/Rec/rec for Rect, circle/Circ/circ for Circle, point, anchor, path, Dataset, XAxis, YAxis, ticks, Series, and legend. New examples should prefer the canonical form.
For generated Data, y="..." samples the variable x by default and stores that sampled value as the point's x. Parametric data uses both x="..." and y="...", samples t by default, and stores the evaluated expressions as fields named x and y. Complex expressions use numeric imaginary literals such as 1j; bare j is a normal parameter name.

Common Patterns

Placed Subplot

<Graph>
  <Plot id="p" at={[0, 0]} width={360} height={240} frame box>
    <Port id="out" right />
    <Axis x ticks />
    <Axis y ticks />
    <Line points={[[0, 0], [1, 1]]} />
  </Plot>
</Graph>

Generated Function Data

<Plot width={560} height={340} xDomain={[0, 2*pi]} yDomain={[-1, 1]} box>
  <Data id="sin" y="sin(x)" domain={[0, 2*pi]} samples={160} />
  <Line data="sin" label="$\sin(x)$" />
</Plot>

Reusable Shape

<Shape id="Tensor" groupBox={false}>
  <Rect id="box" size={[56, 56]} label={label} />
  <Port id="left" target="box.left" />
</Shape>

<Tensor id="A0" label="$A$" />