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

data TreeLayout

Tree layout orientation

Constructors

Instances

#Point Source

type Point = { x :: Number, y :: Number }

A 2D point

#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 :: LayoutConfig

Default 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:

  1. Compute layers (topological)
  2. Order nodes within layers to minimize crossings
  3. 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:

  1. Assigns layers based on longest path from sources
  2. Orders nodes to reduce crossings (barycenter heuristic)
  3. Assigns coordinates