The third step of a flowchart's layout: each node's size in cells, and its place across the flow.
The step works in two directions of its own, whatever way the diagram is
drawn. Along the flow lie the layers. Across it lie a layer's nodes, and
a node's span is its size that way: its width when the flow runs down,
its height when the flow runs to the right. thick is its size along the
flow.
A node meets its edges at ports on the two sides that face the flow. Every edge drawn with the flow shares the centre port, so a node's edges leave as one trunk and arrive under one arrowhead. A straight edge is then two ports in one column, and the step's whole aim is to line ports up.
A layer is solved as one problem. Each node has a column it wants, the median of the ports it is linked to, and the nodes keep their order and their gaps. The least squares answer to that is an isotonic regression, found in one pass by pooling neighbours that would overlap. It centres a node over its children and a child under its parents.
Least squares shares a conflict out as a small bend in every link. A last pass moves each node onto its wanted column outright, the most linked first, so the bends gather in few links and the rest run straight.
An edge laid out against the flow, and an edge with a marker at its upper end, take a second port beside the centre. Their marker would otherwise stand on the trunk the other edges share. A box three rows tall has one row for a port, so with the flow to the right such a node grows to five.
| Name | Signature |
|---|---|
| assign | assign(layered, metrics) -> placed |
assign(
layered,metrics) ->placed
Size a layered flowchart's nodes and place each across the flow
layered is what mermaid.flowchart.order.sweep returns, and is returned
with more in it. metrics holds flow, "down" or "right", and in
cells pad, group_pad, gap, dummy_gap, node_wrap and edge_wrap.
Each layout node gains span and thick, its sizes across the flow and
along it, pos, its first cell across the flow, and port, the offset of
its centre port from pos. A real node gains its box's w and h, the
label's offset in the box dc and dr, and side_port. A real node and
an edge's text gain lines, the wrapped label, and label_cols.
A node with an edge to itself gains loop, { edge, lines, cols }, and
a span that holds the loop and its text beside the box.
A border node of a subgraph gains pos alone. All the border nodes of
one side of a subgraph share it: the frame's side is one line. A cluster
gains title, its subgraph's title on one line, and title_cols, the
title's width.
Returns nil and a reason when a subgraph's frame cannot be made a box.
placed.links lists every link between two neighbouring layers:
{ a, b, a_shift, b_shift, upper_marker, lower_marker, ledge }. A shift
is the port's offset from the centre port, at the upper node a and the
lower node b. Each edge holds its own links, first layer to last, in
links. placed.breadth is the size of the whole across the flow.