Module

DataViz.Layout.Sankey.BackEdge

Package
purescript-hylograph-layout
Repository
afcondon/purescript-hylograph-layout

Back-edges, with a place. A link that closes a cycle (and every link from a node to itself is one) is set aside by the layout: it gives no node its column. It is still part of the picture. This module says which of the caller's links were set aside, by the caller's own names, where each stands on its two nodes, and gives one way to draw them: out of the source's right side, down to a channel under the chart, back along it, and up into the target's left side.

let laid = computeLayoutWithConfig rows config
let under = routeUnder { top: chartBottom + 10.0, gap: 5.0 } (backEdges laid)
under.routed <#> \r -> generateBackEdgePath 30.0 r   -- stroke r.backEdge.width wide

#BackEdge Source

type BackEdge = { index :: Int, source :: String, target :: String, value :: Number, width :: Number, x0 :: Number, x1 :: Number, y0 :: Number, y1 :: Number }

A link the layout set aside. index: its place in the caller's rows. source, target: the names the caller gave (the same name twice for a link from a node to itself). width: value at the chart's scale. It leaves its source at (x0, y0), on the node's right side, and enters its target at (x1, y1), on the node's left side; both are the centre of the link, which stands width / 2 either side, inside the node and below the node's links that go forward.

#RoutedBackEdge Source

type RoutedBackEdge = { backEdge :: BackEdge, channel :: Number }

A back-edge with the channel it runs back along: channel is the y of the channel's centre.

#backEdges Source

backEdges :: SankeyLayoutResult -> Array BackEdge

The back-edges of a layout, in the order of the caller's rows.

#backEdgesAmong Source

backEdgesAmong :: Array SankeyNode -> CycleAnalysis -> Array BackEdge

The same, from the parts: for a layout whose nodes are held apart from the result (Lanes). index is the link's own number.

#routeUnder Source

routeUnder :: { gap :: Number, top :: Number } -> Array BackEdge -> { bottom :: Number, routed :: Array RoutedBackEdge }

A channel for each back-edge, one under another in the order given, the first with its upper edge at top and gap between one and the next. bottom is the lower edge of the last channel (top where there are none), so what is drawn under the channels starts there.

#generateBackEdgePath Source

generateBackEdgePath :: Number -> RoutedBackEdge -> String

The centre line of a routed back-edge, to be stroked width wide: out of the source's right side, round and down to the channel, back along it, and round and up into the target's left side. reach: how far each turn swings out beyond the node's side.