Package

purescript-hylograph-layout

Repository
afcondon/purescript-hylograph-layout
License
MIT
Uploaded by
pacchettibotti
Published on
2026-11-28T09:26:56Z

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 Gallery Demo

Overview

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.

Installation

spago install hylograph-layout

Available Layouts

Hierarchical Layouts

  • 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

Graph Layouts

  • 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

Example

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 coordinates

Modules

  • DataViz.Layout.Hierarchy.Tree - Tree layout
  • DataViz.Layout.Hierarchy.Pack - Circle packing
  • DataViz.Layout.Hierarchy.Partition - Partition/sunburst
  • DataViz.Layout.Hierarchy.Treemap - Treemap
  • DataViz.Layout.Hierarchy.Cluster - Dendrogram
  • DataViz.Layout.Hierarchy.EdgeBundle - Edge bundling
  • DataViz.Layout.Sankey.Compute - Sankey diagrams
  • DataViz.Layout.Sankey.Lanes - lanes for links that span more than one column
  • DataViz.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 chart
  • DataViz.Layout.Sankey.Whole - the chart with its back-edges routed and the nodes no link mentions on a shelf; optionally at a fixed scale
  • DataViz.Layout.Abacus - the abacus diagram: nodes of counted units, wires and their lanes, a unit's worth (types in DataViz.Layout.Abacus.Types)
  • DataViz.Layout.Chord - Chord diagrams
  • DataViz.Layout.Adjacency - Adjacency matrix

The abacus diagram

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 a kind on each: kindedBy adds one, ofOneKind when 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: niceWorth and niceWorthFor give 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 Empty unit (draw it open); a total under one unit is one Part (draw it smaller); otherwise there are round (total / worth) units, all Whole, 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 is Arising. A source is all Arising. A unit's mark says which: Whole Carried kind, Whole Arising kind (and Part likewise), 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, and tally: 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, nodeSort mean what they mean there). nodeGap, layerGap, labelRoom and nodeMinWidth leave 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 is Laned (lanes, on by default: WithLanes { gap }, or WithoutLanes): it has a place kept for it in each column it passes, between the nodes there (DataViz.Layout.Sankey.Lanes gives 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. wireSegments gives a wire's line piece by piece, wirePath as an SVG path.
  • Cycles - a link the Sankey sets aside as a back-edge is a wire whose course is TurningBack: down the space after its source's column, back along a channel of its own below every node and name (stacked by Sankey.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 has returnsToItself, 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.

Part of Hylograph

  • 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.

License

MIT

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
Dependencies