state_diagram

A state_diagram draws an entity lifecycle coordinate-free: states auto-rank by longest path from the transition graph (back-edges and self-loops route around), initial = true draws the filled entry dot, final = true the double border, and each transition carries a trigger [guard] edge label. It is a page-level block, not a diagram shape.

A page-level block drawing an entity lifecycle; states auto-rank along direction and transitions carry trigger [guard] labels.

Preview

PendingPaidShippedCancelledpayment captureddispatched [stock reserved]customer cancelspartial refund
PendingPaidShippedCancelledpayment captureddispatched [stock reserved]customer cancelspartial refund

Example

state_diagram {
  width = 640
  direction = :left_to_right
  state "pending" {
    name = "Pending"
    initial = true
  }
  state "paid" {
    name = "Paid"
  }
  state "shipped" {
    name = "Shipped"
    final = true
  }
  state "cancelled" {
    name = "Cancelled"
    final = true
  }
  transition "t1" {
    from = "pending"
    to = "paid"
    trigger = "payment captured"
  }
  transition "t2" {
    from = "paid"
    to = "shipped"
    trigger = "dispatched"
    guard = "stock reserved"
  }
  transition "t3" {
    from = "pending"
    to = "cancelled"
    trigger = "customer cancels"
  }
  transition "t4" {
    from = "paid"
    to = "paid"
    trigger = "partial refund"
  }
}
PropertyTypeRequiredDescription
widthf64noRendered width in pixels; the height follows the content.
directionsymbolnoFlow direction: :top_to_bottom (default) / :left_to_right.
layer_gapf64noSpacing between ranks (layers).
node_gapf64noSpacing between states within a rank.
ididentifiernoOptional explicit HTML id.
classlist<utf8>noOptional style classes on the <svg>.
descutf8noAccessible description (aria-label + <title>).

Child blocks

SlotAcceptsMultipleDescription
statesstateyesStates; auto-ranked from the transition graph in declaration order.
transitionstransitionyesTransitions between states (trigger [guard] edge labels).

§ 1States and transitions

A transition is a block (not an a -> b edge) because it carries payload: the trigger event and an optional guard. The same from and to renders a self-loop arc. States rank along direction (default :top_to_bottom); a state with explicit x and y opts out of auto-layout.

A lifecycle state; initial = true draws the entry dot, final = true the double border, and explicit x and y opt out of auto-layout.

PropertyTypeRequiredDescription
idutf8yesStable id transitions reference via from / to.
nameutf8noDisplay name shown in the box (defaults to the id).
initialboolnoEntry state: draws the filled-dot pseudo-state with an arrow into the box.
finalboolnoFinal state: draws the double-border marker.
linkutf8noLink the box to an in-site page (bare page name, or site:page).
xf64noManual x placement (with y, opts this state out of auto-layout).
yf64noManual y placement (with x, opts this state out of auto-layout).
widthf64noBox width.
heightf64noBox height.
classlist<utf8>noStyle classes for the box (replaces the theme defaults).

An edge between two states carrying a trigger event and an optional guard; the same from and to renders a self-loop.

PropertyTypeRequiredDescription
idutf8yesStable id.
fromutf8yesSource state id.
toutf8yesDestination state id (same as from for a self-loop).
triggerutf8noThe event that fires the transition (the edge label).
guardutf8noGuard condition, rendered as trigger [guard].

Like every @children slot, states / transitions accept computed splices, so a state-machine model can generate its figure. See data views.