Module

Hylograph.Forces.Link

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

The link force: each link is a spring that pulls its two nodes towards a set distance apart.

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

A link names its nodes by their place in the node array (initialize) or by an id read off each node (initializeById, which is d3's force.id(...) and gives d3's error for a link to a node that is not there).

#Config Source

type Config link = { distance :: link -> Number, iterations :: Int, strength :: Strength link }

d3's forceLink settings. distance is asked once per link.

#Strength Source

data Strength link

How stiff each spring is.

#strengthFromDegree Source

strengthFromDegree :: forall link. Strength link

d3's default: 1 / min(degree of source, degree of target), so that links to heavily connected nodes are weaker.

#defaultConfig Source

defaultConfig :: forall link. Config link

d3's defaults: distance 30, strength from degree, one iteration.

#initialize Source

initialize :: forall row linkRow. Config (Endpoints linkRow) -> Source -> Array (Node row) -> Array (Endpoints linkRow) -> Link row

d3's force.initialize(nodes, random) together with force.links(links), for links that name their nodes by place in the node array. A link naming a place outside the array is dropped.

#initializeById Source

initializeById :: 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 (Link row)

The same for links that name their nodes by id, as d3's force.id(...) has it and as Hylograph's links do. A link naming an id that no node has is d3's error, node not found: <id>.

#apply Source

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

d3's force(alpha): move the velocities of each link's nodes so that the link comes closer to its distance. Links are taken in order and each sees what the ones before it did.

Re-exports from Hylograph.Forces.Linkage

#Identified Source

type Identified :: Type -> Row Type -> Typetype Identified id row = { source :: id, target :: id | row }

A link, by the ids of its two nodes.

#Endpoints Source

type Endpoints :: Row Type -> Typetype Endpoints row = { source :: Int, target :: Int | row }

A link, by the places of its two nodes in the node array.