Module

DataViz.Layout.Sankey.Compute

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

DataViz.Layout.Sankey.Compute

Pure PureScript implementation of Sankey diagram layout computation. Uses State monad to thread graph model through all layout functions. Starts with Array SankeyLinkInput and generates nodes dynamically.

Reference: https://github.com/d3/d3-sankey (ISC License)

#computeLayout Source

computeLayout :: Array LinkCSVRow -> Number -> Number -> SankeyLayoutResult

Main entry point: Compute Sankey layout with default configuration Takes array of link inputs with named nodes (from CSV parsing)

#computeLayoutWithConfig Source

computeLayoutWithConfig :: Array LinkCSVRow -> SankeyConfig -> SankeyLayoutResult

Compute Sankey layout with custom configuration This is the main algorithm using State monad to thread the graph model

#Scale Source

type Scale = { columnPitch :: Number, pixelsPerUnit :: Number }

A scale fixed by the caller, where extent would otherwise fit the chart to a box: pixelsPerUnit is the height of one unit of value, and columnPitch the distance from the left of one column to the left of the next.

#configAtScale Source

configAtScale :: Scale -> Array LinkCSVRow -> SankeyConfig -> SankeyConfig

The configuration whose extent gives the chart that scale: it keeps extent.x0 and extent.y0 and sets extent.x1 and extent.y1, so that the fullest column is exactly full and the columns are columnPitch apart. Lay out with the result:

computeLayoutWithConfig rows (configAtScale scale rows config)

It runs the layout as far as the columns (no relaxation), which is all the extent depends on. The scale comes out to within rounding: the layout still divides the height it is given by the fullest column.