Module

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 Unit

Apply a complete simulation setup to a D3 simulation This is the main entry point for configuring/reconfiguring a simulation

Steps:

  1. Clear all existing tick functions (prevents stale callbacks)
  2. Remove all existing forces from simulation
  3. Create fresh d3 handles for each force in the setup
  4. Apply parameters to each handle (including filters)
  5. Add handles to simulation
  6. Update simulation parameters

Note: After calling applySimulationSetup, use genericUpdateSimulation to register appropriate tick functions for the new setup.

#clearAllTickFunctions Source

clearAllTickFunctions :: D3Simulation_ -> Effect Unit

Clear 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 Unit

Remove 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 Unit

Apply 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 Unit

Apply a single parameter to a force handle If a filter is provided AND this is a filterable param, apply the filter

#setParam Source

setParam :: D3ForceHandle_ -> String -> AttrValue Number -> Effect Unit

Set a parameter on a force handle Calls the appropriate FFI setter based on parameter name

#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.

#applyFilterToAttr Source

applyFilterToAttr :: (Datum_ -> Boolean) -> AttrValue Number -> AttrValue Number

Apply a filter to an attribute value Converts static values to functions that return default (0.0) for filtered-out nodes

#applySimulationParams Source

applySimulationParams :: SimulationParams -> D3Simulation_ -> Effect Unit

Apply simulation parameters to a simulation

#addForceToSimulation Source

addForceToSimulation :: ForceConfig -> D3Simulation_ -> Effect Unit

Add a single force to the simulation without removing existing forces Useful for live updates from ForceControlPanel

#removeForceFromSimulation Source

removeForceFromSimulation :: String -> D3Simulation_ -> Effect Unit

Remove a single force from the simulation

#updateForceParams Source

updateForceParams :: ForceConfig -> D3Simulation_ -> Effect Unit

Update a force's parameters without recreating it Note: This still creates a fresh handle to ensure clean state