Module

Hylograph.Kernel.D3.Core

Package
purescript-hylograph-d3-kernel
Repository
afcondon/purescript-hylograph-d3-kernel

D3 Force Engine Core

This module provides D3-based force simulation functions. We use D3's force calculation algorithms but manage the simulation ourselves.

Key principle: Forces are just functions that mutate vx/vy on nodes. We control when they run and how alpha decays.

#ForceHandle Source

#createManyBody Source

createManyBody :: ManyBodyConfig -> ForceHandle

Create a many-body (charge) force

#createCollide Source

createCollide :: CollideConfig -> ForceHandle

Create a collision force

#createCenter Source

createCenter :: CenterConfig -> ForceHandle

Create a centering force

#createForceX Source

createForceX :: ForceXConfig -> ForceHandle

Create an X positioning force

#createForceY Source

createForceY :: ForceYConfig -> ForceHandle

Create a Y positioning force

#createRadial Source

createRadial :: RadialConfig -> ForceHandle

Create a radial force

#createManyBodyFiltered Source

createManyBodyFiltered :: forall node. ManyBodyFilteredConfig node -> ForceHandle

Create a many-body force that only applies to nodes matching a predicate

#createRadialFiltered Source

createRadialFiltered :: forall node. RadialFilteredConfig node -> ForceHandle

Create a radial force that only applies to nodes matching a predicate

#createCollideDynamic Source

createCollideDynamic :: forall node. CollideDynamicConfig node -> ForceHandle

Create a collision force with dynamic radius per-node

#createForceXDynamic Source

createForceXDynamic :: forall node. ForceXDynamicConfig node -> ForceHandle

Create an X positioning force with dynamic target per-node

#createForceYDynamic Source

createForceYDynamic :: forall node. ForceYDynamicConfig node -> ForceHandle

Create a Y positioning force with dynamic target per-node

#createLinkDynamic Source

createLinkDynamic :: forall link. LinkDynamicConfig link -> ForceHandle

Create a link force with dynamic strength per-link

#createForceXGrid Source

createForceXGrid :: Number -> ForceHandle

Create an X positioning force that reads node.gridX directly

#createForceYGrid Source

createForceYGrid :: Number -> ForceHandle

Create a Y positioning force that reads node.gridY directly

#createCollideGrid Source

createCollideGrid :: Number -> Number -> Int -> ForceHandle

Create a collision force that reads node.r directly

#initializeNodes Source

initializeNodes :: forall r. Array (Record r) -> Effect Unit

Initialize nodes with indices and default velocities

#initializeForce Source

initializeForce :: forall r. ForceHandle -> Array (Record r) -> Effect ForceHandle

Initialize a force with nodes

#initializeLinkForce Source

initializeLinkForce :: forall nodeRow linkRow. ForceHandle -> Array (Record nodeRow) -> Array (Record linkRow) -> Effect ForceHandle

Initialize a link force with nodes and links

#applyForce Source

applyForce :: ForceHandle -> Number -> Effect Unit

Apply a single force

#applyForces Source

applyForces :: Array ForceHandle -> Number -> Effect Unit

Apply multiple forces in sequence

#integratePositions Source

integratePositions :: forall r. Array (Record r) -> Number -> Effect Unit

Integrate positions: apply velocity decay and update positions

#decayAlpha Source

decayAlpha :: Number -> Number -> Number -> Number -> Number

Calculate new alpha value (the "cooling" step)

#simulationTick Source

simulationTick :: forall r. { alpha :: Number, alphaDecay :: Number, alphaMin :: Number, alphaTarget :: Number, forces :: Array ForceHandle, nodes :: Array (Record r), velocityDecay :: Number } -> Effect Number

Complete simulation tick

#AnimationHandle Source

#startAnimation Source

startAnimation :: (Number -> Effect Boolean) -> Effect AnimationHandle

Start an animation loop

#stopAnimation Source

stopAnimation :: AnimationHandle -> Effect Unit

Stop a running animation

#attachDragWithReheat Source

attachDragWithReheat :: Array Element -> Effect Unit -> Effect Unit

Attach drag with reheat callback

#attachGroupDragWithReheat Source

attachGroupDragWithReheat :: Array Element -> String -> Effect Unit -> Effect Unit

Attach drag to transformed group elements

#attachPinningDrag Source

attachPinningDrag :: Array Element -> Effect Unit -> Effect Unit

Attach drag with toggle-pinning behavior

#querySelectorElements Source

querySelectorElements :: String -> Effect (Array Element)

Query DOM elements by CSS selector

#logNodes Source

logNodes :: forall r. String -> Array (Record r) -> Effect Unit

Log node positions for debugging