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 aPartition node with rectangular coordinates
Constructors
PartNode { children :: Array (PartitionNode a), data_ :: a, depth :: Int, height :: Int, value :: Number, x0 :: Number, x1 :: Number, y0 :: Number, y1 :: Number }
Instances
(Eq a) => Eq (PartitionNode a)(Ord a) => Ord (PartitionNode a)Functor PartitionNode(Show a) => Show (PartitionNode a)
#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 aDefault configuration
#partition Source
partition :: forall a. PartitionConfig a -> PartitionNode a -> PartitionNode aApply partition layout to hierarchical data
Algorithm:
- Calculate number of layers (n = height + 1)
- Initialize root coordinates
- Position all nodes (pre-order traversal)
- Optional: round coordinates to integers
#HierarchyData Source
newtype HierarchyData aHierarchical data structure (can have children)
Constructors
HierarchyData { children :: Maybe (Array (HierarchyData a)), data_ :: a, value :: Maybe Number }
#hierarchy Source
hierarchy :: forall a. HierarchyData a -> PartitionNode aConvert hierarchical data to PartitionNode (before layout)
#sunburstArcPath Source
sunburstArcPath :: Number -> Number -> Number -> Number -> Number -> StringConvert 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 aFix 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"
- Modules
- DataViz.
Layout. Adjacency - DataViz.
Layout. Adjacency. Layout - DataViz.
Layout. Adjacency. Types - 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. Tree - DataViz.
Layout. Hierarchy. TreeStyle - DataViz.
Layout. Hierarchy. Treemap - DataViz.
Layout. Hierarchy. Types - DataViz.
Layout. Pattern - DataViz.
Layout. Pattern. Types - DataViz.
Layout. Sankey. CSV - DataViz.
Layout. Sankey. Compute - DataViz.
Layout. Sankey. ComputeWithSteps - DataViz.
Layout. Sankey. Path - DataViz.
Layout. Sankey. Types - DataViz.
Layout. StateMachine - DataViz.
Layout. StateMachine. Layout - DataViz.
Layout. StateMachine. Path - DataViz.
Layout. StateMachine. Types