Module

Hylograph.Forces

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

d3-force's forces in PureScript, with no JavaScript for the algorithms, and what the Rust kernel has that d3 does not.

Each force has its own module with an initialize and an apply; this module gathers them into one Force type and gives d3's loop: cool, apply each force, move the nodes, and then (the Rust kernel's addition) apply any hard constraint and put pinned nodes back.

The d3 forces are held to d3-force 3.0.0 bit for bit, and the others to the Rust kernel built at 64 bits, by test/differential.mjs.

tick, applyForces and the order of a tick are ported from d3-force 3.0.0, simulation.js (ISC, Copyright 2010-2021 Mike Bostock); see LICENSE.

#Force Source

data Force :: Row Type -> Typedata Force row

An initialized force of any kind.

#manyBody Source

manyBody :: forall row. Config row -> Source -> Array (Node row) -> Force row

#linkById Source

linkById :: forall id row linkRow. Ord id => Show id => (Node row -> id) -> Config (Identified id linkRow) -> Source -> Array (Node row) -> Array (Identified id linkRow) -> Either String (Force row)

The link force for links that name their nodes by id; d3's error where a link names an id no node has.

#collide Source

collide :: forall row. Config row -> Source -> Array (Node row) -> Force row

#center Source

center :: forall row. Config -> Array (Node row) -> Force row

#positionX Source

positionX :: forall row. Config row -> Array (Node row) -> Force row

#positionY Source

positionY :: forall row. Config row -> Array (Node row) -> Force row

#radial Source

radial :: forall row. Config row -> Array (Node row) -> Force row

#towards Source

towards :: forall row. Config row -> Array (Node row) -> Force row

#rectCollide Source

rectCollide :: forall row. Config row -> Array (Node row) -> Force row

#contain Source

contain :: forall row. Config row -> Array (Node row) -> Force row

#cohesion Source

cohesion :: forall row. Config row -> Array (Node row) -> Force row

#directional Source

directional :: forall row linkRow. Config row (Endpoints linkRow) -> Array (Node row) -> Array (Endpoints linkRow) -> Force row

#directionalById Source

directionalById :: forall id row linkRow. Ord id => Show id => (Node row -> id) -> Config row (Identified id linkRow) -> Array (Node row) -> Array (Identified id linkRow) -> Either String (Force row)

#applyForce Source

applyForce :: forall row. Number -> Force row -> Effect Unit

Apply one force at the given alpha: d3's force(alpha).

#applyForces Source

applyForces :: forall row. Number -> Array (Force row) -> Effect Unit

Apply forces in order, each seeing what the ones before it did.

#constrain Source

constrain :: forall row. Array (Force (Pinnable row)) -> Array (Node (Pinnable row)) -> Effect Unit

The part of the forces that runs after the nodes have moved: every hard containment clamps its nodes into their regions and every hard directional constraint projects its links, in the order the forces are listed, and then, if any force was hard, pinned coordinates are put back, so that a pin beats them all. Nothing at all where no force is hard.

#Settings Source

type Settings = { alphaDecay :: Number, alphaTarget :: Number, velocityRetention :: Number }

The settings of a tick that are not forces.

#defaultSettings Source

defaultSettings :: Settings

d3's defaults.

#tick Source

tick :: forall row. Settings -> Array (Force (Pinnable row)) -> Array (Node (Pinnable row)) -> Number -> Effect Number

One tick of d3's simulation: cool alpha, apply the forces at the cooled alpha, move the nodes; and then the Rust kernel's last step, constrain. Returns the cooled alpha, to pass to the next tick.