Layout & Styling

Kinematic Layout Engine (layout)

Declarative spatial intent via the Kinematic Assembly Triad (reference, branch, joint), inferred frames, autonomous rails/flanks, and per-arrow routing.

Dhi models 2D and 1.5D layout through the Kinematic Overlapping Framework rather than brittle absolute coordinates. You describe structural spines, branches, and shared-node joints inside layout { ... }, and the solver computes collision-free positions and orthogonal routes deterministically.

The Kinematic Assembly Triad

  • reference (Ground Datum Anchor): Establishes the primary spine pinned at canvas origin (0, 0). At most one reference anchor is permitted per diagram (E196); if omitted, the first assembly becomes the implicit anchor.
  • branch (Independent Sub-Assembly): Defines a secondary cluster or parallel track in local space until anchored to the reference via a joint.
  • joint (Shared-Node Hinge Bridge): Connects two assemblies by sharing at least one common @Identifier hinge node (W044 if unshared, E195 on cycles), locking their relative alignment and gap clearance.
Kinematic Triad locking a branch to the reference spine via a shared hinge node
layout {
  let TRACK_GAP = 60;

  reference spine: column [gap: 40, align: center] {
    state @Idle;
    state @Active;
    state @Terminated;
  }

  branch recovery: column [gap: 30, align: center] {
    state @Diagnostics;
    state @Recovering;
  }

  // Shares @Active (spine) and @Diagnostics (recovery) to lock clearance
  joint bridge_east: row [gap: TRACK_GAP, align: middle] {
    state @Active;
    state @Diagnostics;
  }
}

Strategies, Grids & Elasticity

StrategyPrimary AxisSupported Attributes
columnVertical (Y)gap: <f64>, align: left | center | right
rowHorizontal (X)gap: <f64>, align: top | middle | bottom
grid2D Matrix (X, Y)columns: <int>, gap: [col: <f64>, row: <f64>] or uniform gap: <f64>

Assemblies support Rigid elasticity (monolithic fixed spacing, ideal for class and flat state diagrams) as well as Telescopic elasticity (internal gaps stretch smoothly like springs under cross-assembly joint tension without overconstraining swimlanes or orthogonal regions).

Frames, Sub-Tiers & Macro Joints

Visual frames (frame @Name) and imported modules participate directly in the triad. Terminate a frame layout with ; to infer all member declarations in AST order, nest layout <id>: row { ... } sub-tiers inside a vertical column frame, or join disjoint frames directly as macro containers.

Inferred semicolon frames, nested sub-tier row, and macro frame-to-frame joint
layout {
  reference frame @Ordering: column [gap: 30] {
    layout order_pair: row [gap: 20, align: top] {
      class @Order;
      class @OrderItem;
    }
    class @OrderAuditLog;
  }

  // Autonomous member inference via semicolon form
  branch frame @Billing: column [gap: 30];

  // Macro container joint for disjoint subsystems
  joint domain_gap: row [gap: 100, align: top] {
    frame @Ordering;
    frame @Billing;
  }
}

Autonomous Rails & Peripheral Flanks

Without inspecting node names, the solver automatically derives collector rails and flank sinks from formal AST types and graph degree: vertical join/fork bars with fan-in >= 2 stretch dynamically into collector rails across feeder ranks (H018), while terminal/zero-out-degree fault nodes align cleanly into the lateral flank gutter (H019).

Diagram Projections (2D vs. 1.5D)

State Machine, Class, Activity, Component, and Generic diagrams project onto a full 2D plane. Sequence Diagrams use a 1.5D kinematic projection where X allocates lifeline tracks and Y is driven chronologically by flow { ... }—so sequence lifeline assemblies strictly use row (E194 if column is used).

Arrow Routing, Port Sorting & Notes

The router automatically picks optimal perimeter faces and sorts multi-port exits by target coordinate to guarantee zero boundary crossings. When fine-tuning is needed, address explicit arrow IDs (-[id: @arrowId]->) or named card notes inside layout { ... }:

Per-arrow docking, obstacle detour policy, and card note placement
layout {
  arrow @resetLoop {
    dock: left -> right;
    obstacle: detour outer; // or: detour shortest
  }

  arrow @retryEdge {
    dock: bottom -> top;
    offset: 16.0;
  }

  note @securityReview {
    offset_x: 24
    offset_y: -12
    display_state: "expanded"
  }
}