Module

DataViz.Layout.Hierarchy.Pack

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

Circle packing layout algorithm.

Implements the front-chain circle packing algorithm for laying out hierarchical data as nested circles. Each node's area is proportional to its value, with children packed inside their parent's circle.

The algorithm:

  1. Build hierarchy from input data with hierarchy
  2. Pack sibling circles using packSiblingsMap (front-chain algorithm)
  3. Compute enclosing circle with packEnclose
  4. Recursively pack all levels with pack

Based on Wang et al.'s "Visualization of Large Hierarchical Data by Circle Packing" and the D3.js implementation.

#CircleId Source

type CircleId = Int

Circle ID for map-based storage

#Circle Source

type Circle = { r :: Number, x :: Number, y :: Number }

Circle type for geometric operations

#PackState Source

type PackState = { circles :: Map CircleId Circle, frontChain :: Array CircleId, nextId :: CircleId }

State for map-based pack algorithm

#enclosesWeak Source

enclosesWeak :: Circle -> Circle -> Boolean

Does circle a enclose circle b (with tolerance)?

#intersects Source

intersects :: Circle -> Circle -> Boolean

Do circles a and b intersect?

#place Source

place :: Circle -> Circle -> Circle -> Circle

Position circle c tangent to circles a and b

#packSiblingsMap Source

packSiblingsMap :: Array Circle -> { circles :: Array Circle, radius :: Number }

Pack siblings using map-based front-chain algorithm

#PackNode Source

data PackNode a

Pack node extends hierarchy with circle coordinates

Constructors

Instances

#PackConfig Source

type PackConfig a = { padding :: Number, radius :: Maybe (a -> Number), size :: { height :: Number, width :: Number } }

Configuration for pack layout

#defaultPackConfig Source

defaultPackConfig :: forall a. PackConfig a

Default pack configuration

#HierarchyData Source

newtype HierarchyData a

Simple hierarchy node for testing

Constructors

#hierarchy Source

hierarchy :: forall a. HierarchyData a -> PackNode a

Create a hierarchy from data

#pack Source

pack :: forall a. PackConfig a -> PackNode a -> PackNode a

Apply pack layout to a hierarchy using the map-based algorithm Implements D3's two-pass algorithm for proper padding