mermaid.flowchart.rank

index · mermaid.flowchart

Overview

The first step of a flowchart's layout: which layer each node stands in. The flow runs from layer 1 down, whatever direction the diagram is drawn in; a later step turns it.

Every edge then joins neighbouring layers. An edge that spans more gets a dummy node in each layer it crosses, so the steps after this one meet short links alone.

An edge's text needs room between two layers. A gap that holds a text becomes a layer of its own, and the text a node in it. A gap with no text gets no layer, so a diagram with no edge text is no taller for the rule.

Functions

NameSignature
layerslayers(graph) -> layered

layers(graph) -> layered

Put a flowchart's nodes into layers

graph is what mermaid.flowchart.parser.parse returns.

The result:

FieldHolds
graphthe graph
nodesa layout node per graph node, in the graph's order
layersthe layout nodes of each layer, dummies included
edges{ edge, from, to, reversed, chain, from_sub, to_sub }
loops{ node, edge } for each edge from a node to itself
clusters{ sub, path, lo, hi, left, right } for each subgraph that holds a node

A layout node is { id, kind, rank, path, up, down }. kind is "node", "dummy", "label" or "border". path lists the subgraphs the node lies in, the outermost first. up and down list the nodes it is linked to in the layer above and below. A real node holds its graph node in node; a label node holds the text's lines in label; both dummies hold their layout edge in edge.

A cluster spans the layers lo to hi, and holds in left and right a border node for each of them, by layer. A border node marks where the subgraph's frame stands in its layer: the nodes of the subgraph lie between the two.

An edge's chain runs from its upper end to its lower end through its dummies. reversed marks an edge laid out against its direction because it closed a cycle: its chain starts at to. from_sub and to_sub hold the subgraph an end named; the edge is laid out to that subgraph's first node. The parser refuses an edge to a subgraph with no node, and one between a subgraph and its own member. Each end then comes to a node, and both to one node only for an edge from a node to itself.

A layer's order here is the order of mention. mermaid.flowchart.order sets the order a layout uses.