Module
Hylograph.Kernel.WASM.Engine
- Package
- purescript-hylograph-wasm-kernel
- Repository
- afcondon/purescript-hylograph-wasm-kernel
WASM Engine Adapter
High-performance force simulation using Rust/WebAssembly. Drop-in replacement for the D3.js-based simulation.
Provides 3-4x speedup over D3.js for large graphs (10,000+ nodes) by offloading force calculations to compiled WebAssembly.
Usage:
import Hylograph.Kernel.WASM.Engine as WASMEngine
import Hylograph.Simulation.Core.Engine as Engine
main = do
-- Initialize WASM module (once at app startup)
WASMEngine.initWasm "./pkg/force_kernel.js"
-- Create WASM simulation with nodes
wasmSim <- WASMEngine.create nodes links config
-- Create adapter for Scene Engine
let adapter = WASMEngine.mkAdapter wasmSim
-- Use with Scene Engine
engine <- Engine.createEngine adapter
#WASMSimConfig Source
type WASMSimConfig = { center :: CenterConfig, enableCenter :: Boolean, enableLinks :: Boolean, enableManyBody :: Boolean, links :: LinkConfig, manyBody :: ManyBodyConfig }Configuration for creating a WASM simulation
#defaultConfig Source
defaultConfig :: WASMSimConfigDefault simulation configuration
#isWasmReady Source
isWasmReady :: Effect BooleanCheck if WASM is initialized and ready
#create Source
create :: forall r. Array (SimulationNode r) -> Array { source :: Int, target :: Int } -> WASMSimConfig -> Effect (WASMSim r)Create a new WASM simulation with nodes and links.
#mkAdapter Source
mkAdapter :: forall r. WASMSim r -> EngineAdapter (SimulationNode r)Create an EngineAdapter for use with the Scene Engine.
This is the key integration point - allows WASMEngine to be used as a drop-in replacement for D3-based simulation in scene transitions.
#getNodes Source
getNodes :: forall r. WASMSim r -> Effect (Array (SimulationNode r))Get current nodes with positions
#configureManyBody Source
configureManyBody :: forall r. WASMSim r -> ManyBodyConfig -> Effect UnitConfigure many-body (charge) force
#configureLinks Source
configureLinks :: forall r. WASMSim r -> LinkConfig -> Effect UnitConfigure link (spring) force
#configureCenter Source
configureCenter :: forall r. WASMSim r -> CenterConfig -> Effect UnitConfigure center force