Macaw.Draw.Layout.Force.Forces (macaw_draw v0.1.0)

Copy Markdown View Source

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.

TypeOptions (defaults)Effect
:centerx (0), y (0), strength (1)translates every position so the mean moves toward {x, y} by strength; ignores alpha
:many_bodystrength (−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
:linkdistance (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
:collisionradius (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
:xx (0, or a function), strength (0.1)vx += (target − x) · strength · alpha
:yy (0, or a function), strength (0.1)vy += (target − y) · strength · alpha
:radialradius (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

Types

A link between two node positions.

A simulated node.

A force type.

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

link()

@type link() :: %{
  :source => non_neg_integer(),
  :target => non_neg_integer(),
  optional(:distance) => number(),
  optional(:strength) => number()
}

A link between two node positions.

sim_node()

@type sim_node() :: %{
  :x => number(),
  :y => number(),
  :vx => number(),
  :vy => number(),
  optional(atom()) => term()
}

A simulated node.

type()

@type type() :: :center | :many_body | :link | :collision | :x | :y | :radial

A force type.

Functions

apply(type, nodes, links, alpha, opts)

@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}}.

types()

@spec types() :: [type()]

The force types: [:center, :many_body, :link, :collision, :x, :y, :radial].