group : GroupOptions -> Group
Construct a group from structural and measured geometric input.
:= []
Directed graph layout read as flow.
layout is the usual entry point. For repeated layouts of unchanged input,
call prepare once and pass the result to layout_prepared. For small,
important drawings, layout_exact searches for the layer orderings with
the fewest edge crossings under an explicit effort cap and reports whether
optimality was proven.
group : GroupOptions -> Group
Construct a group from structural and measured geometric input.
default_group_options : GroupOptions
Empty membership with inherited flow/spacing and zero reservations.
grouped_problem_to_str : GroupedProblem -> Str
Explain a grouped preparation problem. List positions and group indices start at zero; groups use root-first preorder.
default_group : Group
Empty group with inherited flow/spacing and no geometric reservations.
default_grouped_input : GroupedInput
Empty coordinated flow input. Replace nodes, edges and root by record update.
default_grouped_settings : GroupedSettings
Top-to-bottom flow with ordinary node, layer, port and label gaps.
default_grouped_run : GroupedRunArgs
Fixed seed zero, with no ambient randomness.
prepare_grouped : GroupedInput, GroupedSettings -> [Ok(GroupedPrepared), Err(List(GroupedProblem))]
Validate all structural and spatial inputs, then construct reusable hierarchy and edge indices. Geometry is computed during layout.
layout_grouped_prepared : GroupedPrepared, GroupedRunArgs -> GroupedResult
Lay out validated grouped input. This operation cannot fail.
layout_grouped : GroupedInput, GroupedSettings, GroupedRunArgs -> [Ok(GroupedResult), Err(List(GroupedProblem))]
Lay out a nested directed graph in one call. Use this when edges crossing
group boundaries should influence the groups' internal flow. For mixed
layout families and independent group composition, use Compound.
problem_to_str : Problem -> Str
Explain one validation problem in plain language. Numbers identify zero-based positions or referenced values as stated in each message.
default_input : Input
Empty flow input. Replace graph by record update.
default_settings : Settings
Settings that produce a readable top-to-bottom layout in common cases.
default_run : RunArgs
Reflow for best layout quality without previous-position hints.
Check the input and settings, then cache work reusable across layouts.
layout_prepared : Prepared, RunArgs -> Result
Lay out previously prepared input. This operation cannot fail.
Check and lay out input in one call. This is the usual entry point.
default_exact_settings : ExactSettings
Default spacing and routing with an effort cap of 100,000 ordering choices — enough to prove optimality for small drawings.
prepare_exact : Input, ExactSettings -> [Ok(ExactPrepared), Err(List(Problem))]
Check the input and settings, run the crossing search, and cache the chosen ordering with everything else reusable across layouts.
layout_exact_prepared : ExactPrepared -> ExactResult
Lay out previously prepared exact input. This operation cannot fail.
layout_exact : Input, ExactSettings -> [Ok(ExactResult), Err(List(Problem))]
Check and lay out input with the fewest edge crossings the effort cap
allows, in one call. Direction handling, layer assignment, spacing,
and routes are exactly as in layout; only the ordering of nodes
within each layer differs, chosen by exhaustive search rather than
heuristic sweeps. The search cost grows steeply with layer width, so
the effort cap bounds it: at the cap the best ordering found — never
worse than layout's — is returned with proven_optimal: False.
:= [
Group(
{
children : List([Node(U64), Nested(Group)]),
flow : [Together, Separate([Down, Up, Left, Right])],
spacing : [Inherit, Set(Spacing)],
padding : { top : F64, right : F64, bottom : F64, left : F64 },
min_width : F64,
min_height : F64,
},
),
]
Recursive ownership for coordinated directed flow. Children are Node
indices or Nested groups. Together lets edges influence placement
across group borders; Separate(direction) completes a child drawing
before arranging it with its siblings. Padding and measured labels are
geometric reservations, in the caller's units.
GroupOptions : {
children : List([Node(U64), Nested(Group)]),
flow : [Together, Separate([Down, Up, Left, Right])],
spacing : [Inherit, Set(GroupedSpacing)],
padding : { top : F64, right : F64, bottom : F64, left : F64 },
min_width : F64,
min_height : F64,
}
A group's direct members and geometric reservations. flow is
Together, or Separate(direction) to complete an independent child.
spacing is Inherit or Set(gaps). Padding reserves space inside
the frame; GroupedInput.group_reservations reserves measured exterior
space without changing the group's own dimensions.
GroupedInput : {
nodes : List({ width : F64, height : F64 }),
edges : List({ from : [Node(U64), Group(U64)], to : [Node(U64), Group(U64)] }),
edge_labels : List({ edge : U64, width : F64, height : F64 }),
end_labels : List({ edge : U64, endpoint : [From, To], width : F64, height : F64 }),
group_reservations : List({ group : U64, width : F64, height : F64 }),
root : Group,
}
Nodes and edges retain input order. Group indices are root-first preorder: group zero is the root drawing and cannot be an edge endpoint. Every node must occur exactly once in the ownership tree. Edge labels reserve measured rectangles at the middle of their routes.
GroupedSettings : { direction : [Down, Up, Left, Right], spacing : GroupedSpacing }
Flow direction and default geometric spacing. A group's Set spacing
overrides the inherited spacing for that group's contents.
GroupedSpacing : {
node_node : F64,
node_node_between_layers : F64,
edge_node : F64,
edge_node_between_layers : F64,
edge_edge : F64,
edge_edge_between_layers : F64,
edge_label : F64,
label_label : F64,
port_port : F64,
node_self_loop : F64,
ports_surrounding : F64,
}
Distances between node boxes, layers, ports, edges and measured labels.
Names ending in between_layers apply along the flow. Other gaps apply
across the flow; ports_surrounding reserves room around port positions.
GroupedRunArgs : { seed : U32 }
An explicit seed selects deterministic ordering variants. It affects solving only, so prepared input can be reused with different seeds.
:= [
InvalidNodeWidth(U64),
InvalidNodeHeight(U64),
MissingMember(U64),
MissingNode(U64),
DuplicateNode(U64),
InvalidGroupSize(U64),
InvalidGroupPadding(U64),
InvalidGroupSpacing(U64),
InvalidSpacing,
MissingEdgeStart(U64),
MissingEdgeEnd(U64),
MissingLabelEdge(U64),
InvalidLabelSize(U64),
DuplicateLabel(U64),
MissingEndLabelEdge(U64),
InvalidEndLabelSize(U64),
DuplicateEndLabel(U64),
MissingReservationGroup(U64),
InvalidReservationSize(U64),
DuplicateReservation(U64),
]
Independent input problems, reported together during preparation.
Node problems are InvalidNodeWidth(node), InvalidNodeHeight(node),
MissingMember(node), MissingNode(node) and DuplicateNode(node).
Group problems are InvalidGroupSize(group), InvalidGroupPadding(group)
and InvalidGroupSpacing(group). InvalidSpacing identifies the defaults.
MissingEdgeStart(edge) and MissingEdgeEnd(edge) include nonexistent
endpoints and attempts to connect to the root drawing.
Sparse measured inputs use their own list indices: MissingLabelEdge,
InvalidLabelSize, DuplicateLabel, MissingEndLabelEdge,
InvalidEndLabelSize, DuplicateEndLabel, MissingReservationGroup,
InvalidReservationSize and DuplicateReservation. Each carries one
index. All sizes, padding and distances must be finite and nonnegative;
every node occurs exactly once, each edge has at most one center label
and one label per endpoint, and each group has at most one reservation.
Use grouped_problem_to_str for a full explanation of one problem.
is_eq : _
:= {
diagram : Input,
setup : Setup,
labels : List({ edge : U64, width : F64, height : F64 }),
end_labels : List({ edge : U64, endpoint : [From, To], width : F64, height : F64 }),
end_sizes : List(Ends),
reservations : List({ group : U64, width : F64, height : F64 }),
min_width : F64,
min_height : F64,
}
Validated structural input and reusable hierarchical edge segmentation.
run : GroupedPrepared, RunArgs -> Result
GroupedResult : {
layout : { positions : List(Point), routes : List(Route), bounds : Rect },
nodes : List(Rect),
groups : List(Rect),
label_anchors : List(Point),
end_label_placements : List({ point : Point, port : Point }),
attachments : List({ from : { point : Point, side : [Top, Right, Bottom, Left] }, to : { point : Point, side : [Top, Right, Bottom, Left] } }),
layers : List(U64),
backward_edges : List(U64),
}
Source-aligned geometry, group rectangles in root-first preorder,
center-label anchors in label-input order, node layers local to their
containing graph, and original edge indices drawn against the flow.
attachments reports each route's actual endpoint and rectangle side;
a corner selects the first side clockwise from the top. Grouped flow
assigns ports automatically. Use Route on the resulting geometry when
a caller needs authored attachment constraints or a different router.
LayerConstraint : [SameLayer({ first : U64, second : U64 }), BeforeLayer({ first : U64, second : U64, minimum_span : U64 }), FirstLayer(U64), LastLayer(U64)]
Hard relationships between node layers. BeforeLayer follows the
selected flow direction, so it has the same meaning for every direction.
Input : {
graph : {
nodes : List({ width : F64, height : F64 }),
edges : List({ from : U64, to : U64 }),
},
edge_weights : List({ edge : U64, weight : F64 }),
min_spans : List({ edge : U64, span : U64 }),
attachments : List(AttachmentRule),
boundaries : List(BoundaryRule),
edge_labels : List(EdgeLabel),
layer_constraints : List(LayerConstraint),
order_constraints : List({ before : U64, after : U64 }),
non_ranking_edges : List(U64),
}
Directed flow input. Edge identity is its index. Most callers only set
graph; the sparse lists add labels, endpoint geometry, or authored
placement. Layer constraints describe flow-relative rows, order
constraints arrange nodes that share a row, and non-ranking edges are
routed without influencing rows or cycle breaking. In an order
constraint, before means visually left of after for vertical flow and
visually above it for horizontal flow, regardless of direction.
Routing : [Straight, Orthogonal(Settings)]
How edges are drawn once nodes are placed.
Orthogonal routes every edge with right-angled segments clear of all
node boxes, guided through its layer_points. Its settings set
clearance, edge separation, and path preferences exactly as for
Route.layout.
Straight draws each edge as straight segments from its source's
boundary through its layer points to its target's boundary. It skips
routing, which is most of the cost of laying out a large graph, and
suits callers that draw edges themselves from layer_points. A
self-loop has no straight route: it is a zero-length line at its node's
center. Straight drawings report no attachments.
Settings : { node_gap : F64, layer_gap : F64, routing : Routing, direction : [Down, Up, Left, Right], max_sweeps : U64, ordering : [Median, Average], pins : List({ node : U64, x : F64, y : F64 }) }
Space between nodes on the same layer (node_gap) and between adjacent
layers (layer_gap), the way the flow runs, how layers are ordered,
and how edges are drawn (routing).
max_sweeps caps the rounds of crossing reduction. ordering chooses
how each round orders a layer from its neighbors in the adjacent one:
Median moves each node toward the median position of its neighbors, then swaps adjacent nodes wherever that removes crossings. It usually draws the fewest crossings, and is the default.Average moves each node toward the average position of its neighbors, keeps nodes that tie in their current order (at first, the input order), and makes no swaps. Drawings follow the input order more closely, as ELK's layered layouts (used by Mermaid) do, at the cost of some crossings Median would remove.Sparse pins hold node centers exactly; preparation reports pins that cannot coexist with strict layer alignment and configured gaps.
Per-layout choices. Hints are sparse and addressed by node index; invalid
run-time entries are ignored and the final valid duplicate wins.
PreserveOrder keeps the mutual within-layer order of hinted nodes while
allowing unhinted nodes to be inserted. Authored constraints take priority.
:= [
InvalidNodeWidth(U64),
InvalidNodeHeight(U64),
MissingEdgeStart(U64, U64),
MissingEdgeEnd(U64, U64),
InvalidNodeGap,
InvalidLayerGap,
MissingEdgeWeightEdge(U64),
InvalidEdgeWeight(U64),
NonRankingEdgeWeight(U64, U64),
MissingMinimumSpanEdge(U64),
InvalidMinimumSpan(U64),
NonRankingMinimumSpan(U64, U64),
InvalidAttachmentEdge(U64),
InvalidAttachmentOffset(U64),
DuplicateAttachment(U64),
InvalidBoundaryNode(U64),
DuplicateBoundary(U64),
MissingPinNode(U64, U64),
InvalidPin(U64),
DuplicatePin(U64),
ConflictingPins,
InvalidEdgeLabelEdge(U64),
InvalidEdgeLabelWidth(U64),
InvalidEdgeLabelHeight(U64),
MissingLayerConstraintNode(U64, U64),
InvalidLayerConstraintSpan(U64),
ConflictingLayerConstraints,
MissingOrderConstraintNode(U64, U64),
OrderConstraintAcrossLayers(U64),
ConflictingOrderConstraints,
MissingNonRankingEdge(U64, U64),
DuplicateNonRankingEdge(U64),
InvalidRouting(Problem),
]
Invalid sizes, spacing, references, or authored relationships found while
checking input. NonRankingEdgeWeight and
NonRankingMinimumSpan report the sparse setting index followed by its
edge index.
Result : {
layout : {
positions : List({ x : F64, y : F64 }),
bounds : { x : F64, y : F64, width : F64, height : F64 },
routes : List(Route),
},
layers : List(U64),
backward_edges : List(U64),
label_anchors : List({ x : F64, y : F64 }),
attachments : List(EdgeAttachments),
layer_points : List(List({ x : F64, y : F64 })),
}
Geometry plus each node's layer and any edges drawn against the flow. Positions hold node centers; route endpoints lie on the source and target node boundaries.
layer_points holds, for each edge, one point on every layer strictly
between its two nodes, in order from source to target; an edge between
adjacent layers has none. Along the flow each point lies on the side of
its layer that the flow reaches first; across the flow it is spaced
from its neighbors like a node of zero width. A centered edge label
takes its edge's middle point, which is then the center of the space
reserved for the label. Straight routes pass through exactly these
points; orthogonal routes are guided by them.
attachments reports where each orthogonal route meets its two nodes.
ExactSettings : { node_gap : F64, layer_gap : F64, routing : Routing, effort_cap : U64, direction : [Down, Up, Left, Right], pins : List({ node : U64, x : F64, y : F64 }) }
Settings for layout_exact: spacing and routing exactly as in
Settings, plus effort_cap — the most ordering choices the crossing
search may try before stopping with the best ordering found so far.
Higher caps prove optimality on wider layers at higher cost; a cap of
zero still returns a deterministic best-known order. Pins have the same
exact-coordinate and preparation-conflict behavior as Settings.
0 skips the search entirely and keeps the ordering layout would
produce.
ExactResult : {
layout : {
positions : List({ x : F64, y : F64 }),
bounds : { x : F64, y : F64, width : F64, height : F64 },
routes : List(Route),
},
layers : List(U64),
backward_edges : List(U64),
proven_optimal : Bool,
label_anchors : List({ x : F64, y : F64 }),
attachments : List(EdgeAttachments),
layer_points : List(List({ x : F64, y : F64 })),
}
Everything Result reports, plus whether the crossing search proved
its ordering has the fewest crossings any ordering can achieve:
True when the search finished within the effort cap or the ordering
is crossing-free, False when the cap stopped the search early or hard
ordering rules were applied after the unconstrained search.