Skip to content

Circular Flows

Real systems often loop back: waste is recycled into production, a reactor sends part of its output back to the mixer, a node feeds itself. A flow whose target is not in a later column than its source is called a back flow. Sankey cannot draw it between the columns in the usual way, because the target is behind the source, so it leaves the source, runs along the bottom of the chart (the right side when vertical) and enters the target from behind. Nothing needs to be configured: this is how back flows are drawn by default.

Each back flow gets a lane after the content. Loops are nested so they do not cross, and loops that do not overlap share a lane. Nodes are placed by the flows that go forward, so the loops do not push their nodes out of line. The lanes and the turns are part of the same layout as the nodes: they take their share of the chart, and on a small chart everything, the lanes and the gaps included, shrinks together instead of the loops being dropped.

Which flows are back flows is decided from the data: the flows between the same two nodes are taken together, from the largest total to the smallest, and the one that would close a cycle is the back flow, so the biggest flows keep running forward whatever the order of the data. Use the column option to pin nodes to columns. Switch the orientation below to see how the same loops are routed when the columns run from top to bottom.

By default the back flows between the same two nodes share a lane after the content. backFlows.bundle chooses which back flows share one: pair (the default), target (all that return to a node), source (all that leave a node) or false (a lane each). The shortest flow of a lane runs innermost, and the turns at a node that several flows share go round each other. backFlows.side moves the lanes to the start of the cross axis (start, the top of a horizontal chart) or lets each lane pick the side nearer to its flows (auto). Below, Smelter gets scrap and parts back from the later columns, and Market gets back what its shop and customers return: with auto the lanes of the smelter run along the top, where its loops are, and those of the market stay at the bottom.