Module

Hylograph.Forces.Position

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

The positioning forces: pull each node towards a target x or a target y.

Ported from d3-force 3.0.0, x.js and y.js (ISC, Copyright 2010-2021 Mike Bostock); see LICENSE.

#Config Source

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

d3's forceX / forceY settings. target and strength are asked once per node when the force is initialized.

#defaultConfig Source

defaultConfig :: forall row. Config row

d3's defaults: towards zero, at strength 0.1.

#Position Source

newtype Position :: Row Type -> Typenewtype Position row

An initialized positioning force. Whether it acts along x or y is decided by which of applyX and applyY it is given to.

#initialize Source

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

d3's force.initialize(nodes). A node whose target is NaN gets strength zero, as in d3.

#applyX Source

applyX :: forall row. Position row -> Number -> Effect Unit

d3's forceX applied: node.vx += (target - node.x) * strength * alpha.

#applyY Source

applyY :: forall row. Position row -> Number -> Effect Unit

d3's forceY applied: node.vy += (target - node.y) * strength * alpha.