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)
Cycles. d3-sankey throws on a cycle. Here a depth-first search sets
aside, as a back-edge, every link that returns to a node still on the
search's path: the search starts from each node in the order the rows
first name it, and follows a node's links in the same order (of their
targets' first naming). So a graph that is one cycle, with no node
without a link in, starts from the node named first, and the link back
to it is the one set aside. A link from a node to itself is always a
back-edge. The rest is a DAG and is laid out as d3-sankey would lay it
out; the back-edges keep their widths and a place on their nodes
(computeBackEdgeBreadths), and DataViz.Layout.Sankey.BackEdge routes
them under the chart.
Size. Through 0.6.0 every step looked nodes and links up by
scanning arrays (find, filter inside loops and inside sort
comparators), so relaxation was cubic or worse in practice: 677 links,
with lanes, took 20 to 30 s. They are now looked up in maps built once a
step, with the same arithmetic in the same order, so every position is
what it was, to the bit. The rows are folded in without State, and the
back-edge search keeps its own stack: both overflowed the JS stack at
about 3,000 rows or 3,000 nodes deep, which lanes reach quickly.
#computeLayout Source
computeLayout :: Array LinkCSVRow -> Number -> Number -> SankeyLayoutResultMain 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 -> SankeyLayoutResultCompute Sankey layout with custom configuration This is the main algorithm using State monad to thread the graph model
#configAtScale Source
configAtScale :: Scale -> Array LinkCSVRow -> SankeyConfig -> SankeyConfigThe 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)
which is computeLayoutAtScale scale rows config, but for reading the
graph twice. 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.
#computeLayoutAtScale Source
computeLayoutAtScale :: Scale -> Array LinkCSVRow -> SankeyConfig -> SankeyLayoutResultcomputeLayoutWithConfig rows (configAtScale scale rows config), the
same to the bit, reading the graph once.
- Modules
- DataViz.
Layout. Abacus - DataViz.
Layout. Abacus. Types - DataViz.
Layout. Adjacency - DataViz.
Layout. Adjacency. Layout - DataViz.
Layout. Adjacency. Types - DataViz.
Layout. BlockCutTree - DataViz.
Layout. Chord - DataViz.
Layout. Chord. Layout - DataViz.
Layout. Chord. Types - DataViz.
Layout. Hierarchy. Cluster - DataViz.
Layout. Hierarchy. Core - DataViz.
Layout. Hierarchy. EdgeBundle - DataViz.
Layout. Hierarchy. EdgeBundle. Bilink - DataViz.
Layout. Hierarchy. EdgeBundle. BundleCurve - DataViz.
Layout. Hierarchy. EdgeBundle. Hierarchy - DataViz.
Layout. Hierarchy. EdgeBundle. RadialCluster - DataViz.
Layout. Hierarchy. EdgeBundle. Types - DataViz.
Layout. Hierarchy. Link - DataViz.
Layout. Hierarchy. Pack - DataViz.
Layout. Hierarchy. Partition - DataViz.
Layout. Hierarchy. Placed - DataViz.
Layout. Hierarchy. Tree - DataViz.
Layout. Hierarchy. TreeStyle - DataViz.
Layout. Hierarchy. Treemap - DataViz.
Layout. Hierarchy. Types - DataViz.
Layout. Pattern - DataViz.
Layout. Pattern. Adapters - DataViz.
Layout. Pattern. Types - DataViz.
Layout. Sankey. BackEdge - DataViz.
Layout. Sankey. CSV - DataViz.
Layout. Sankey. Compute - DataViz.
Layout. Sankey. ComputeWithSteps - DataViz.
Layout. Sankey. Lanes - DataViz.
Layout. Sankey. Path - DataViz.
Layout. Sankey. Types - DataViz.
Layout. Sankey. Whole - DataViz.
Layout. StateMachine - DataViz.
Layout. StateMachine. Layout - DataViz.
Layout. StateMachine. Path - DataViz.
Layout. StateMachine. Tree - DataViz.
Layout. StateMachine. Types - DataViz.
Layout. TidyDag