Module

Hylograph.Kernel.D3.SimulationGroup

Package
purescript-hylograph-d3-kernel
Repository
afcondon/purescript-hylograph-d3-kernel

Simulation Group - Multiple Synchronized Simulations

Manages multiple force simulations with a single shared animation loop. Each simulation can be individually activated/deactivated.

Use cases:

  • Multiple graph visualizations that need synchronized updates
  • Comparative views (same data, different force configurations)
  • Puzzle games with multiple interacting graphs

Example:

-- Create 6 simulations
group <- createGroup (Array.replicate 6 defaultConfig)

-- Set nodes for each
for_ (Array.range 0 5) \i -> do
  setNodesAt i myNodes group

-- Subscribe to tick events (single subscription for all 6)
emitter <- subscribeToGroup group
void $ H.subscribe $ emitter <#> \_ -> SimTick

-- Start the shared animation loop
startGroup group

-- Pause simulation 2 while others continue
setSimActive 2 false group

#SimulationGroup Source

type SimulationGroup :: Row Type -> Row Type -> Typetype SimulationGroup row linkRow = { activeFlags :: Ref (Array Boolean), callbacks :: Maybe SimulationCallbacks, cancelAnimation :: Ref (Effect Unit), running :: Ref Boolean, simulations :: Array (Simulation row linkRow) }

A group of simulations sharing a single animation loop

#GroupConfig Source

type GroupConfig = { count :: Int, simConfig :: SimConfig }

Configuration for creating a group

#defaultGroupConfig Source

defaultGroupConfig :: GroupConfig

Default group configuration

#createGroup Source

createGroup :: forall row linkRow. Int -> SimConfig -> Effect (SimulationGroup row linkRow)

Create a group of simulations (without callbacks)

#createGroupWithCallbacks Source

createGroupWithCallbacks :: forall row linkRow. Int -> SimConfig -> SimulationCallbacks -> Effect (SimulationGroup row linkRow)

Create a group with callbacks (for Halogen subscription)

#startGroup Source

startGroup :: forall row linkRow. SimulationGroup row linkRow -> Effect Unit

Start the shared animation loop Only active simulations are ticked each frame

#stopGroup Source

stopGroup :: forall row linkRow. SimulationGroup row linkRow -> Effect Unit

Stop the animation loop

#tickGroup Source

tickGroup :: forall row linkRow. SimulationGroup row linkRow -> Effect Boolean

Tick all active simulations once Returns true if any simulation still has alpha > 0

#reheatAll Source

reheatAll :: forall row linkRow. SimulationGroup row linkRow -> Effect Unit

Reheat all active simulations

#reheatAt Source

reheatAt :: forall row linkRow. Int -> SimulationGroup row linkRow -> Effect Unit

Reheat a specific simulation

#setSimActive Source

setSimActive :: forall row linkRow. Int -> Boolean -> SimulationGroup row linkRow -> Effect Unit

Set whether a specific simulation is active (will be ticked)

#setAllActive Source

setAllActive :: forall row linkRow. Boolean -> SimulationGroup row linkRow -> Effect Unit

Set all simulations active or inactive

#isSimActive Source

isSimActive :: forall row linkRow. Int -> SimulationGroup row linkRow -> Effect Boolean

Check if a simulation is active

#getActiveFlags Source

getActiveFlags :: forall row linkRow. SimulationGroup row linkRow -> Effect (Array Boolean)

Get all active flags

#setNodesAt Source

setNodesAt :: forall row linkRow. Int -> Array (SimulationNode row) -> SimulationGroup row linkRow -> Effect Unit

Set nodes for a specific simulation

#setLinksAt Source

setLinksAt :: forall row linkRow. Int -> Array { source :: Int, target :: Int | linkRow } -> SimulationGroup row linkRow -> Effect Unit

Set links for a specific simulation

#getNodesAt Source

getNodesAt :: forall row linkRow. Int -> SimulationGroup row linkRow -> Effect (Maybe (Array (SimulationNode row)))

Get nodes from a specific simulation

#getSimulationAt Source

getSimulationAt :: forall row linkRow. Int -> SimulationGroup row linkRow -> Maybe (Simulation row linkRow)

Get a simulation by index (for direct access)

#getSimulationCount Source

getSimulationCount :: forall row linkRow. SimulationGroup row linkRow -> Int

Get the number of simulations in the group

#applySetupAt Source

applySetupAt :: forall row linkRow. Int -> Setup (SimulationNode row) -> SimulationGroup row linkRow -> Effect Unit

Apply a force setup to a specific simulation

#applySetupAll Source

applySetupAll :: forall row linkRow. Setup (SimulationNode row) -> SimulationGroup row linkRow -> Effect Unit

Apply a force setup to all simulations

#getGroupCallbacks Source

getGroupCallbacks :: forall row linkRow. SimulationGroup row linkRow -> Maybe SimulationCallbacks

Get the group's callbacks (for Halogen subscription)