diagram

A diagram is wdoc's drawing surface. It declares a width / height and holds shapes that break down into primitives and render as SVG. Connect two shapes by id with an a -> b edge; set pan_zoom = true for an interactive viewport; set a layout (:layered / :radial / :force) to place shapes automatically (see layout modes). Higher-level families (flowcharts, charts, trees, maps, tilemaps, wireframes) are shapes that live inside a diagram too. The primitive shapes are catalogued below; see also the connections concept.

Preview

Example

diagram {
  width = 320
  height = 160
  pan_zoom = true
  zoom_min = 0.5
  zoom_max = 4.0
  rect {
    id = a
    x = 20.0
    y = 30.0
    width = 80.0
    height = 50.0
    fill = "#88c0d0"
  }
  rect {
    id = b
    x = 210.0
    y = 90.0
    width = 80.0
    height = 50.0
    fill = "#a3be8c"
  }
  a -> b
}
PropertyTypeRequiredDescription
widthi64yesDiagram canvas width in pixels.
heighti64yesDiagram canvas height in pixels.
ididentifiernoOptional explicit HTML id.
classlist<utf8>noOptional style classes.
layoutsymbolnoLayout mode: :free (default, manual x/y) / :grid / :layered / :force / :radial.
directionsymbolnoFlow direction for :layered: :top_to_bottom (default) / :left_to_right.
layer_gapf64noSpacing between ranks (layers) in :layered layout.
node_gapf64noSpacing between nodes within a rank in :layered layout.
cell_widthf64noGrid cell width for :grid layout.
cell_heightf64noGrid cell height for :grid layout.
columnsi64noNumber of columns for :grid layout.
gapf64noGap between cells in :grid layout.
iterationsi64no:force relaxation steps (default 300).
repulsionf64no:force node repulsion strength (default 9000).
link_distancef64no:force ideal edge-to-edge length (default 60).
gravityf64no:force centering pull (default 0.05).
seedi64no:force random seed for reproducible layouts (default 1).
hubidentifierno:radial hub shape id (defaults to the highest-degree shape).
radiusf64no:radial radius of the first ring (default: auto-fit to shape sizes).
ring_gapf64no:radial added radius per successive ring (default 120).
start_anglef64no:radial angle (radians) of the first shape on each ring (default -PI/2, i.e. top).
routingsymbolnoEdge routing: :elbow (default) / :straight.
edge_separationf64noNudge step that separates parallel edges (default 4).
pan_zoomboolnoWhen true, wrap in an interactive viewport with wheel-zoom, drag-pan, and +// controls.
zoom_minf64noMinimum zoom scale; 1.0 = fitted view (default 1.0).
zoom_maxf64noMaximum zoom scale (default 4.0).
pan_marginf64noExtra overscroll past the content bounds, in px (default 0).
descutf8noAccessible description: becomes the SVG's <title> and aria-label, so screen readers can announce the diagram.
edgeslist<Edge>yesEdges connecting shapes (a -> b).

Child blocks

SlotAcceptsMultipleDescription
childrenSvgBlockyesThe shapes drawn in the diagram.

§ 1Shapes

A diagram holds shapes that break down into primitives. They split across three pages:

Higher-level families (flowcharts, charts, trees, maps, tilemaps, wireframes) are shapes that live inside a diagram too; wiring is covered by the connections concept and placement by the layout modes.