Module

Hylograph.Forces.ThreeD.Radial

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

The radial force in three dimensions: pull each node towards a sphere.

Ported from d3-force-3d 3.0.6, radial.js (MIT, Copyright 2017 Vasco Asturiano; itself from d3-force, ISC, Mike Bostock); see LICENSE.

Besides the third coordinate, d3-force-3d reads y and z as zero where they are NaN ((node.y || 0) - y); x is read as it is, as in d3-force.

#Config Source

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

forceRadial settings. radius and strength are asked once per node when the force is initialized.

#defaultConfig Source

defaultConfig :: forall row. Config row

d3's defaults for everything but the radius, which d3 requires: here a sphere of radius 100 about the origin, at strength 0.1.

#Radial Source

newtype Radial :: Row Type -> Typenewtype Radial row

An initialized radial force.

#initialize Source

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

force.initialize(nodes). A node whose radius is NaN gets strength zero.

#apply Source

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

d3-force-3d's force(alpha):

dx = node.x - x || 1e-6,
dy = (node.y || 0) - y || 1e-6,
dz = (node.z || 0) - z || 1e-6,
r = Math.sqrt(dx * dx + dy * dy + dz * dz),
k = (radiuses[i] - r) * strengths[i] * alpha / r;
node.vx += dx * k; node.vy += dy * k; node.vz += dz * k;