Hylograph.ForceEngine.WASMEngine
- Package
- purescript-hylograph-simulation
- Repository
- afcondon/purescript-hylograph-simulation
WASM Engine Adapter
High-performance force simulation using Rust/WebAssembly. Drop-in replacement for the D3.js-based simulation.
Force calculations are offloaded to compiled WebAssembly. Informally observed to be faster than the D3 kernel on large graphs; no benchmark is stored and the figure has not been re-measured.
Usage:
import Hylograph.ForceEngine.WASMEngine as WASMEngine
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
#installKernel Source
installKernel :: KernelModule -> Effect UnitInstall a kernel module loaded by other means (see
Hylograph.ForceEngine.WASM.installKernel).
#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
Re-exports from Hylograph.ForceEngine.WASM
#KernelModule Source
data KernelModuleThe kernel's wasm-bindgen module, already instantiated: what the
loader generated by wasm-pack (--target web) exports once its
default export has been awaited, with Simulation among its exports.
Made by whatever carries the module (the hylograph-wasm-kernel
package makes one from bytes it carries) and handed to
installKernel.
- Modules
- 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.
Simulation. Stepped - Hylograph.
Transition. Consumers - Hylograph.
Transition. Example