Pure PureScript implementations of layout algorithms for hierarchies and flow diagrams.
Live demo: the Layout Gallery, every layout in this library drawn interactively. It is one of the suite of Hylograph library demos.
Layout algorithms for hierarchical and graph data, implemented in pure PureScript. Many of these layouts are familiar to users of D3 but here they are implemented without FFI dependencies using FP implementations in 100% PureScript. The hierarchical ones work with the rose-tree data structure from purescript-tree-rose.
spago install hylograph-layout- Tree - Tidy tree layout (Reingold-Tilford algorithm)
- Pack - Circle packing for hierarchical data
- Partition - Sunburst/icicle partition layout
- Treemap - Multiple tiling algorithms: squarify (default), slice, dice, sliceDice, binary
- Cluster - Dendrogram layout
- Sankey - Flow diagram layout, d3-sankey's algorithm; a graph with cycles has the links that close them set aside as back-edges (depth-first, in the order the rows name the nodes) and routed under the chart. Beyond D3: a column by node, a fixed order within columns, a least height by node, a fixed scale. Hundreds of links with lanes lay out in well under a second.
- Abacus - A flow drawn with counted units where a Sankey has ribbons of a width: each node is a grid of equal units, ten to a line, one unit worth a declared amount and of the kind of what flows; the links are thin wires. Its columns, its order and its handling of cycles are the Sankey's. See The abacus diagram.
- EdgeBundle - Hierarchical edge bundling
- Chord - Chord diagram layout
- Adjacency - Adjacency matrix layout
import DataViz.Layout.Hierarchy.Tree (tree, defaultTreeConfig)
import Data.Tree (mkTree)
myTree = mkTree "root" [mkTree "a" [], mkTree "b" []]
config = defaultTreeConfig { size = { width: 400.0, height: 300.0 } }
positioned = tree config myTree
-- Each node now has x, y coordinatesDataViz.Layout.Hierarchy.Tree- Tree layoutDataViz.Layout.Hierarchy.Pack- Circle packingDataViz.Layout.Hierarchy.Partition- Partition/sunburstDataViz.Layout.Hierarchy.Treemap- TreemapDataViz.Layout.Hierarchy.Cluster- DendrogramDataViz.Layout.Hierarchy.EdgeBundle- Edge bundlingDataViz.Layout.Sankey.Compute- Sankey diagramsDataViz.Layout.Sankey.Lanes- lanes for links that span more than one columnDataViz.Layout.Sankey.BackEdge- the links that close a cycle (a link from a node to itself among them): which they are, where they stand on their nodes, a route under the chartDataViz.Layout.Sankey.Whole- the chart with its back-edges routed and the nodes no link mentions on a shelf; optionally at a fixed scaleDataViz.Layout.Abacus- the abacus diagram: nodes of counted units, wires and their lanes, a unit's worth (types inDataViz.Layout.Abacus.Types)DataViz.Layout.Chord- Chord diagramsDataViz.Layout.Adjacency- Adjacency matrix
A Sankey shows a quantity by the width of a ribbon. The abacus shows it by counting: each node is a small grid of equal units, one unit is worth an amount that the picture states, and a unit's kind (drawn as its colour) is the kind of what flows through the node. It is Neurath's rule for Isotype, that more of a thing is shown by more signs and never by a bigger sign, on a Sankey's graph. A small node stays visible and countable beside a large one, and a node shows what it is made of.
import DataViz.Layout.Abacus (computeLayout, defaultAbacusConfig, kindedBy, niceWorthFor, wirePath)
links = kindedBy _.s rows -- a Sankey's rows, each given a kind (here: where it comes from)
worth = niceWorthFor 40 links -- 1, 2 or 5 times a power of ten; the largest node at most 40 units
laid = computeLayout links (defaultAbacusConfig worth)
-- laid.nodes: each with its box and its units, a unit being { x, y, size, mark }, a mark Whole Carried kind, say
-- laid.wires: each with its two ends; `wirePath` gives a line to stroke- Input - a Sankey's rows (
s,t,v) with akindon each:kindedByadds one,ofOneKindwhen there is nothing to tell apart. - A unit's worth -
UnitWorth, in the measure of the quantities. It is the reader's choice, as a map's scale is:niceWorthandniceWorthForgive a default, and a picture should say what it is. - A node's units - its total is the larger of what comes in and what goes out. A total of nothing is one
Emptyunit (draw it open); a total under one unit is onePart(draw it smaller); otherwise there areround (total / worth)units, allWhole, shared between the kinds by largest remainder, so that they add up and no share is more than one unit from its amount. - A node's kinds, and what arises -
composition.IncomingAndArising(the default): what comes in, by kind, at its own amounts,Carried; if more goes out than comes in, the rest arises in the node, is shared among the kinds of what goes out in their proportions, and isArising. A source is allArising. A unit's mark says which:Whole Carried kind,Whole Arising kind(andPartlikewise), so a picture can draw what arose in a node differently from what was carried into it.IncomingScaled: the kinds of what comes in, scaled to the total.LargerSide: the kinds of whichever side is larger. - The grid -
unitsPerLine(ten),unitSize,unitGap, andtally:TalliedBy { every: 5, gap: 2.0 }sets the units in fives, across and down, so that many can still be counted. - Columns and order - the Sankey's own, from
config.sankey(alignment,nodeLayer,nodeSortmean what they mean there).nodeGap,layerGap,labelRoomandnodeMinWidthleave room for names. - Wires keep clear - every wire runs from its source's right side to its target's left, and starts level, to the edge of its source's column. A wire to the next column is
Onward: one S across the space between. A wire that passes over one or more columns isLaned(lanes, on by default:WithLanes { gap }, orWithoutLanes): it has a place kept for it in each column it passes, between the nodes there (DataViz.Layout.Sankey.Lanesgives the waypoints). The line of each goes through no node and no node's room for a name; two wires may still cross or run together in the space between columns.wireSegmentsgives a wire's line piece by piece,wirePathas an SVG path. - Cycles - a link the Sankey sets aside as a back-edge is a wire whose
courseisTurningBack: down the space after its source's column, back along a channel of its own below every node and name (stacked bySankey.BackEdge.routeUnder), and up the space before its target's column, so it too goes through no node; the extent grows to hold it. A link from a node to itself is no wire: its node hasreturnsToItself, to be drawn as a small mark. A link of no quantity joins nothing: it is no wire, and from a node to itself it is no mark either.
What a Sankey still does better: that what goes in comes out, seen at a glance in the widths; and how much went along each path. A wire here says only that two nodes are joined.
- hylograph-layout - Layout algorithms (this package)
- hylograph-graph - Graph algorithms and DAG support
- hylograph-selection - D3 selection library
- hylograph-simulation - Force simulation
Uses tree-rose for rose tree data structures.
MIT