Module

Hylograph.Forces.Towards

Package
purescript-hylograph-forces
Repository
afcondon/purescript-hylograph-forces

The towards force: a spring from each node to its own target point.

Not in d3. The rule is the Rust kernel's (apply_towards in force-kernel/src/forces.rs), and the two are held to each other bit for bit by test/differential.mjs. For every node with a target whose coordinates are both numbers:

vx += (targetX - x) * strength * alpha
vy += (targetY - y) * strength * alpha

A node whose target has a NaN in it is left alone, and a strength of NaN counts as zero.

#Config Source

type Config :: Row Type -> Typetype Config row = { strength :: Node row -> Number, target :: Node row -> { x :: Number, y :: Number } }

target and strength are asked once per node when the force is initialized. To move the targets, initialize again.

#Towards Source

newtype Towards :: Row Type -> Typenewtype Towards row

An initialized towards force.

#initialize Source

initialize :: forall row. Config row -> Array (Node row) -> Towards row

#apply Source

apply :: forall row. Towards row -> Number -> Effect Unit