The seven forces of the force simulation (spec/08 §9.2), each a function of the nodes,
the links, the temperature alpha and the force's options.
| Type | Options (defaults) | Effect |
|---|---|---|
:center | x (0), y (0), strength (1) | translates every position so the mean moves toward {x, y} by strength; ignores alpha |
:many_body | strength (−30), distance_min (1), distance_max (:infinity) | every pair directly: v += (other − node) · strength · alpha / d², d at least distance_min, pairs at d ≥ distance_max skipped |
:link | distance (30), strength (1), iterations (1) | per link, k = (d − distance) / d · alpha · strength over the ends' pos + vel, added to the source's velocity and taken from the target's |
:collision | radius (10, or a function of a node), strength (1), iterations (1) | each overlapping pair pushed apart equally, half of (r − d) / d · strength · alpha each, summed over every pair before any velocity changes |
:x | x (0, or a function), strength (0.1) | vx += (target − x) · strength · alpha |
:y | y (0, or a function), strength (0.1) | vy += (target − y) · strength · alpha |
:radial | radius (100, or a function), x (0), y (0), strength (0.1) | v += (node − center) · (radius − d) / d · strength · alpha |
A node is a map with x, y, vx, vy; a link a map with source and target, the
positions of its ends in the node list, and optional distance and strength that
override the link force's. This is visualize's Visualize.Layout.Force.Forces, its
links by position and an unknown force a fault where it raised CaseClauseError.
Summary
Functions
The nodes after the force type with opts at temperature alpha (§9.2). An unknown
type is {[], {:unknown, :force, type}}, a bad option a fault at [4, key], and a link
whose end is not a node position {[2, i], {:type, :link}}.
The force types: [:center, :many_body, :link, :collision, :x, :y, :radial].
Types
@type link() :: %{ :source => non_neg_integer(), :target => non_neg_integer(), optional(:distance) => number(), optional(:strength) => number() }
A link between two node positions.
@type sim_node() :: %{ :x => number(), :y => number(), :vx => number(), :vy => number(), optional(atom()) => term() }
A simulated node.
@type type() :: :center | :many_body | :link | :collision | :x | :y | :radial
A force type.
Functions
@spec apply(type(), [sim_node()], [link()], number(), keyword()) :: [sim_node()] | Macaw.Draw.Layout.error()
The nodes after the force type with opts at temperature alpha (§9.2). An unknown
type is {[], {:unknown, :force, type}}, a bad option a fault at [4, key], and a link
whose end is not a node position {[2, i], {:type, :link}}.
@spec types() :: [type()]
The force types: [:center, :many_body, :link, :collision, :x, :y, :radial].