Hylograph.Config.Apply
- Package
- purescript-hylograph-simulation
- Repository
- afcondon/purescript-hylograph-simulation
Configuration Application Module
This module bridges the gap between immutable PureScript configurations and the mutable d3-force JavaScript simulation.
Key functions:
- createForceHandle: Create a fresh d3 force handle from configuration
- applySimulationSetup: Apply a complete setup to a simulation
Design principle: d3 force handles are ephemeral runtime artifacts. They are created from configurations and discarded when no longer needed.
#applySimulationSetup Source
applySimulationSetup :: SimulationSetup -> D3Simulation_ -> Effect UnitApply a complete simulation setup to a D3 simulation This is the main entry point for configuring/reconfiguring a simulation
Steps:
- Clear all existing tick functions (prevents stale callbacks)
- Remove all existing forces from simulation
- Create fresh d3 handles for each force in the setup
- Apply parameters to each handle (including filters)
- Add handles to simulation
- Update simulation parameters
Note: After calling applySimulationSetup, use genericUpdateSimulation to register appropriate tick functions for the new setup.
#clearAllTickFunctions Source
clearAllTickFunctions :: D3Simulation_ -> Effect UnitClear all tick functions from a simulation This prevents stale tick callbacks from running during setup changes D3 tick functions are namespaced like "tick.nodes", "tick.links"
#removeAllForces Source
removeAllForces :: D3Simulation_ -> Effect UnitRemove all forces from a simulation Gets the force names that are currently in the simulation and removes them
#createForceHandle Source
createForceHandle :: ForceConfig -> D3ForceHandle_Create a fresh d3 force handle from a configuration This creates a new JavaScript object with default parameters
#applyForceParams Source
applyForceParams :: D3ForceHandle_ -> Maybe ForceFilter -> ForceParams -> Effect UnitApply parameters to a force handle This calls the d3 setter methods (.strength(), .radius(), etc.) Filters are applied by converting static values to filter functions
#applyParam Source
applyParam :: D3ForceHandle_ -> Maybe ForceFilter -> String -> AttrValue Number -> Effect UnitApply a single parameter to a force handle If a filter is provided AND this is a filterable param, apply the filter
#attrValueToJS Source
attrValueToJS :: AttrValue Number -> D3Attr_Convert an AttrValue to a JavaScript value (Number or Function) This is what actually gets passed to d3's setter methods IMPORTANT: DynamicIndexedValue functions are curried in PureScript but D3 expects uncurried JavaScript functions. We use mkFn2 to convert.
#applySimulationParams Source
applySimulationParams :: SimulationParams -> D3Simulation_ -> Effect UnitApply simulation parameters to a simulation
#addForceToSimulation Source
addForceToSimulation :: ForceConfig -> D3Simulation_ -> Effect UnitAdd a single force to the simulation without removing existing forces Useful for live updates from ForceControlPanel
#removeForceFromSimulation Source
removeForceFromSimulation :: String -> D3Simulation_ -> Effect UnitRemove a single force from the simulation
#updateForceParams Source
updateForceParams :: ForceConfig -> D3Simulation_ -> Effect UnitUpdate a force's parameters without recreating it Note: This still creates a fresh handle to ensure clean state
- Modules
- Hylograph.
Config. Apply - Hylograph.
Config. Force - Hylograph.
Config. Scene - Hylograph.
ForceEngine - Hylograph.
ForceEngine. Core - Hylograph.
ForceEngine. Demo - Hylograph.
ForceEngine. Events - Hylograph.
ForceEngine. Links - Hylograph.
ForceEngine. Registry - Hylograph.
ForceEngine. Render - Hylograph.
ForceEngine. Setup - Hylograph.
ForceEngine. Setup. WASM - Hylograph.
ForceEngine. Simulation - Hylograph.
ForceEngine. Types - Hylograph.
ForceEngine. WASM - Hylograph.
ForceEngine. WASMEngine - Hylograph.
Scene. Engine - Hylograph.
Scene. Handle - Hylograph.
Scene. Rules - Hylograph.
Scene. Types - Hylograph.
Simulation - Hylograph.
Simulation. Emitter - Hylograph.
Simulation. HATS - Hylograph.
Simulation. Scene - Hylograph.
Transition. Consumers - Hylograph.
Transition. Example