Module

DataViz.Layout.Hierarchy.Cluster

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

DataViz.Layout.Hierarchy.Cluster

Cluster (dendrogram) layout using Data.Tree Uses Reingold-Tilford algorithm for x-positioning (like Tree) But positions nodes by height (distance from leaves) instead of depth Result: All leaf nodes appear at the same level (y = 0)

#ClusterConfig Source

type ClusterConfig = { minSeparation :: Number, size :: { height :: Number, width :: Number } }

Configuration for cluster layout

#defaultClusterConfig Source

defaultClusterConfig :: ClusterConfig

Default configuration

#cluster Source

cluster :: forall r. ClusterConfig -> Tree { height :: Int, x :: Number, y :: Number | r } -> Tree { height :: Int, x :: Number, y :: Number | r }

Cluster layout in 4 steps:

  1. addHeight: Bottom-up pass computing height (distance from deepest leaf)
  2. sortByHeight: Sort children by height to minimize crossovers (D3 pattern)
  3. render: Bottom-up pass assigning sequential x to leaves, mean x to parents
  4. addY: Add y coordinates based on height (leaves at 0)
  5. scale: Scale abstract coordinates to pixel coordinates

Key difference from Tree:

  • All leaves get sequential x positions (not contour-based)
  • y is based on height (distance from leaves) not depth
  • All leaves appear at y = 0 (dendrogram)
  • Children sorted by height (descending) to minimize crossovers

Input must have x, y, height fields (initial values don't matter, they'll be overwritten)