Module

Hylograph.Forces.Cohesion

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

Group cohesion: pull each node toward the centroid of its group.

Not in d3. The rule is the Rust kernel's (apply_cohesion in force-kernel/src/forces.rs), and the two are held to each other bit for bit by test/differential.mjs.

The centroid of a group is the mean position of its members whose position is finite, summed in node order. For every node in a group whose position is finite:

v += (centroid - position) * strength * alpha

A node in no group is left alone and counts toward no centroid. A strength of NaN counts as zero, and such a node still counts toward its group's centroid.

#Config Source

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

group and strength are asked once per node when the force is initialized.

#Cohesion Source

newtype Cohesion :: Row Type -> Typenewtype Cohesion row

An initialized cohesion force: the members of each group, in node order.

#initialize Source

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

#apply Source

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

The force only changes velocities, so each group's centroid can be taken just before its members are pulled.