Module

DataViz.Layout.Hierarchy.Partition

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

D3 Partition Layout

Implements the D3 partition layout algorithm for hierarchical data. Creates rectangular partitions that can be rendered as:

  • Icicle charts (vertical stacked rectangles)
  • Sunburst charts (radial partitions)

Based on: https://github.com/d3/d3-hierarchy/blob/main/src/partition.js

#PartitionNode Source

data PartitionNode a

Partition node with rectangular coordinates

Constructors

Instances

#PartitionConfig Source

type PartitionConfig :: forall k. k -> Typetype PartitionConfig a = { padding :: Number, round :: Boolean, size :: { height :: Number, width :: Number } }

Configuration for partition layout

#defaultPartitionConfig Source

defaultPartitionConfig :: forall a. PartitionConfig a

Default configuration

#partition Source

partition :: forall a. PartitionConfig a -> PartitionNode a -> PartitionNode a

Apply partition layout to hierarchical data

Algorithm:

  1. Calculate number of layers (n = height + 1)
  2. Initialize root coordinates
  3. Position all nodes (pre-order traversal)
  4. Optional: round coordinates to integers

#HierarchyData Source

newtype HierarchyData a

Hierarchical data structure (can have children)

Constructors

#hierarchy Source

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

Convert hierarchical data to PartitionNode (before layout)

#sunburstArcPath Source

sunburstArcPath :: Number -> Number -> Number -> Number -> Number -> String

Convert partition coordinates to sunburst arc path (SVG path string)

Parameters:

  • x0, x1: Normalized angles [0,1] representing angular extent around the circle
  • y0, y1: Normalized radii [0,1] representing distance from center
  • radius: Total radius of the sunburst in pixels

The function handles the special case where the arc spans nearly a full circle (>99%), which SVG cannot render as a single arc, by splitting it into two semicircular arcs.

Based on D3's arc generator: https://github.com/d3/d3-shape#arc

#flattenPartition Source

flattenPartition :: forall a. PartitionNode a -> Array (PartitionNode a)

Flatten PartitionNode tree to array (pre-order traversal)

Returns all nodes in the tree as a flat array, with the root first followed by all descendants in pre-order traversal order.

#fixParallelLayout Source

fixParallelLayout :: forall a. (a -> Boolean) -> PartitionNode a -> PartitionNode a

Fix parallel layout for sunburst diagrams

Makes children of "parallel" nodes share the parent's angular extent and stack radially (same angle, different radius) instead of dividing angular space. This is useful for visualizing simultaneous/overlapping elements.

The predicate function determines which nodes should be treated as "parallel". For example: \nodeData -> nodeData.nodeType == "parallel"