Hylograph.Forces.Tick
- Package
- purescript-hylograph-forces
- Repository
- afcondon/purescript-hylograph-forces
The parts of a tick that are not forces: cooling, and moving the nodes.
Ported from d3-force 3.0.0, simulation.js (ISC, Copyright 2010-2021
Mike Bostock); see LICENSE.
#defaultAlphaDecay Source
defaultAlphaDecay :: Numberd3's default cooling rate: alpha falls from 1 to 0.001 in 300 ticks.
#defaultVelocityRetention Source
defaultVelocityRetention :: NumberThe share of its velocity a node keeps from one tick to the next: what
d3 multiplies a velocity by. (d3's velocityDecay(0.4) is the share
lost; this is one minus it.)
#initializeNodes Source
initializeNodes :: forall row. Array (Node (Pinnable row)) -> Effect Unitd3's initializeNodes: give every node its index; put a pinned node on
its pin; give a node with no position a place on d3's phyllotaxis
spiral; and stop a node with no velocity.
node.index = i;
if (node.fx != null) node.x = node.fx;
if (node.fy != null) node.y = node.fy;
if (isNaN(node.x) || isNaN(node.y)) {
var radius = initialRadius * Math.sqrt(0.5 + i), angle = i * initialAngle;
node.x = radius * Math.cos(angle);
node.y = radius * Math.sin(angle);
}
if (isNaN(node.vx) || isNaN(node.vy)) node.vx = node.vy = 0;
A field that is missing reads as NaN here, as it does in d3.
#integrate Source
integrate :: forall row. Number -> Array (Node (Pinnable row)) -> Effect Unitd3's position update, after the forces of a tick:
if (node.fx == null) node.x += node.vx *= velocityDecay;
else node.x = node.fx, node.vx = 0;
and the same for y. The position is written before the velocity, and neither write changes what the other one reads.
- Modules
- Hylograph.
Forces - Hylograph.
Forces. Center - Hylograph.
Forces. Cohesion - Hylograph.
Forces. Collide - Hylograph.
Forces. Contain - Hylograph.
Forces. Directional - Hylograph.
Forces. Group - Hylograph.
Forces. Link - Hylograph.
Forces. Linkage - Hylograph.
Forces. ManyBody - Hylograph.
Forces. Measure - Hylograph.
Forces. Node - Hylograph.
Forces. Position - Hylograph.
Forces. Quadtree - Hylograph.
Forces. Radial - Hylograph.
Forces. Random - Hylograph.
Forces. RectCollide - Hylograph.
Forces. Snapshot - Hylograph.
Forces. Tick - Hylograph.
Forces. Towards