Module
Data.Graph.Layout
- Package
- purescript-hylograph-graph
- Repository
- afcondon/purescript-hylograph-graph
Layout algorithms for graph and tree visualization
Provides pure layout algorithms that compute node positions. Works with any node identifier type.
#TreeLayout Source
#LayoutNode Source
type LayoutNode node = { id :: node, layer :: Int, x :: Number, y :: Number }A node with computed layout position
#LayoutConfig Source
type LayoutConfig = { nodeHeight :: Number, nodeWidth :: Number, orientation :: TreeLayout, reversed :: Boolean }Configuration for layout algorithms
#treeLayout Source
treeLayout :: forall node. Ord node => LayoutConfig -> node -> TreeAdj node -> Array (LayoutNode node)Compute tree layout with the given root node
Uses a simple recursive algorithm:
- Children are placed side by side
- Parent is centered above its children
#layeredTreeLayout Source
layeredTreeLayout :: forall node. Ord node => LayoutConfig -> Array (LayeredInput node) -> Array (LayoutNode node)Layout nodes that already have layer assignments
Useful when you've computed layers separately (e.g., from topological sort).
#defaultLayoutConfig Source
defaultLayoutConfig :: LayoutConfigDefault layout configuration
#dagLayout Source
dagLayout :: forall node. Ord node => LayoutConfig -> Array node -> GraphAdj node -> Array (LayoutNode node)Layout a DAG using Sugiyama-style algorithm
Steps:
- Compute layers (topological)
- Order nodes within layers to minimize crossings
- Assign x coordinates
#sugiyamaLayout Source
sugiyamaLayout :: forall node. Ord node => LayoutConfig -> Array node -> GraphAdj node -> Array (LayoutNode node)Sugiyama hierarchical layout algorithm
A simplified version that:
- Assigns layers based on longest path from sources
- Orders nodes to reduce crossings (barycenter heuristic)
- Assigns coordinates