Module

Hylograph.Scene.Types

Package
purescript-hylograph-simulation
Repository
afcondon/purescript-hylograph-simulation

Scene Types

Core type definitions for the scene orchestration system.

A scene represents a visualization state with:

  • A target layout (where nodes should be)
  • Rules for initialization and finalization
  • A stable mode (physics simulation or static)

The scene system supports smooth transitions between states using a tick-based interpolation engine for position animation.

#SceneConfig Source

type SceneConfig node = { finalRules :: Array node -> Array (NodeRule node), initRules :: Array (NodeRule node), layout :: Array node -> PositionMap, name :: String, stableMode :: EngineMode }

Scene configuration with three-phase lifecycle.

Phase 1: Initialize (initRules) Applied before transition starts. Use this to set up starting positions, e.g., moving tree nodes to the root for a "grow from root" animation.

Phase 2: Transition (layout) The interpolation engine smoothly moves nodes from their current positions to the target positions computed by the layout function.

Phase 3: Finalize (finalRules) Applied after transition completes. Use this to set up the stable state, e.g., unpinning nodes so forces can take over, or setting gridX/gridY.

Example:

treeFormScene :: SceneConfig MyNode
treeFormScene =
  { name: "TreeForm"
  , initRules: [ moveToRootRule ]
  , layout: \nodes -> computeTreePositions nodes
  , finalRules: \_ -> [ pinAtTreePositionsRule ]
  , stableMode: Static
  }

#TransitionState Source

type TransitionState node = { progress :: Progress, startPositions :: PositionMap, targetPositions :: PositionMap, targetScene :: SceneConfig node }

Runtime state during an active transition.

Tracks the target scene, start/end positions, and current progress. The interpolation engine updates progress each tick until complete. Uses tick-based progress (0.0 to 1.0) rather than time-based elapsed.

#EngineMode Source

data EngineMode

Engine mode determines what happens after a transition completes.

  • Physics: D3 force simulation runs, nodes settle via forces
  • Static: Nodes stay pinned at their final positions

Constructors

Instances

#PositionMap Source

type PositionMap = Object Position

Position map: node ID (as string) -> position Used for capturing current positions and specifying targets

#Position Source

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

A position in 2D space

#NodeRule Source

type NodeRule node = { apply :: node -> node, name :: String, select :: node -> Boolean }

A rule that selects nodes and applies a transform.

Rules are applied with first-match-wins semantics (like CSS cascade). If multiple rules match a node, only the first one applies.

Example:

pinPackages :: NodeRule MyNode
pinPackages =
  { name: "pinPackages"
  , select: \n -> n.nodeType == Package
  , apply: \n -> n { fx = notNull n.x, fy = notNull n.y }
  }