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 :: GroupConfigDefault 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 UnitStart the shared animation loop Only active simulations are ticked each frame
#stopGroup Source
stopGroup :: forall row linkRow. SimulationGroup row linkRow -> Effect UnitStop the animation loop
#tickGroup Source
tickGroup :: forall row linkRow. SimulationGroup row linkRow -> Effect BooleanTick all active simulations once Returns true if any simulation still has alpha > 0
#reheatAll Source
reheatAll :: forall row linkRow. SimulationGroup row linkRow -> Effect UnitReheat all active simulations
#reheatAt Source
reheatAt :: forall row linkRow. Int -> SimulationGroup row linkRow -> Effect UnitReheat a specific simulation
#setSimActive Source
setSimActive :: forall row linkRow. Int -> Boolean -> SimulationGroup row linkRow -> Effect UnitSet whether a specific simulation is active (will be ticked)
#setAllActive Source
setAllActive :: forall row linkRow. Boolean -> SimulationGroup row linkRow -> Effect UnitSet all simulations active or inactive
#isSimActive Source
isSimActive :: forall row linkRow. Int -> SimulationGroup row linkRow -> Effect BooleanCheck 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 UnitSet nodes for a specific simulation
#setLinksAt Source
setLinksAt :: forall row linkRow. Int -> Array { source :: Int, target :: Int | linkRow } -> SimulationGroup row linkRow -> Effect UnitSet 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 -> IntGet the number of simulations in the group
#applySetupAt Source
applySetupAt :: forall row linkRow. Int -> Setup (SimulationNode row) -> SimulationGroup row linkRow -> Effect UnitApply a force setup to a specific simulation
#applySetupAll Source
applySetupAll :: forall row linkRow. Setup (SimulationNode row) -> SimulationGroup row linkRow -> Effect UnitApply a force setup to all simulations
#getGroupCallbacks Source
getGroupCallbacks :: forall row linkRow. SimulationGroup row linkRow -> Maybe SimulationCallbacksGet the group's callbacks (for Halogen subscription)