Macaw.Frame.Transforms.Force (macaw_frame v0.1.0)

Copy Markdown View Source

The force step (spec/04 §7.2, spec/05 §5.3): a force-directed layout of the flows, a Macaw.Draw.Layout.Force simulation in the plot (needs: [:frame]).

fields: [source, target], and field the flow's value (1 by default; the layout reads only the links); the nodes are the distinct ids in order of first appearance, or the nodes table's rows keyed by id, a node row with numeric x and y starting there. strength (-30) is the many-body force, distance (30) the links', centered on the middle of size (the plot by default). output: "nodes" answers one row per node, id, x, y; "links" one row per flow, source, target, both ends and the straight path.

One simulation per graph (prepare/3). Every layer reading one graph (the same node but for output) reads one simulation: prepare/3 lays out each distinct graph of the nodes it is given, and run/3 reads its own from the context's prepared, else lays it out cold. Cold is d3's 300 ticks from alpha 1. Warm, from the simulation the last delivery prepared (the context's warm, as prepare/3 answered it), the graph starts where it was, rescaled to a new plot size, reheated to alpha (0.3) for ticks (3) (spec/03 §9.2, Macaw.Draw.Layout.Force.warm/3).

Summary

Types

One graph's layout: the simulation, the plot size it is in, and its key.

Functions

The graph a node lays out, whatever it outputs: the key its simulation is prepared and carried under.

What the frame is called when a data layer's rows are laid out by this step (spec/11 §2.2).

Every distinct graph of nodes laid out once over table (spec/05 §5.3): a map from each graph's key/1 to its prepared/0, or the first graph's fault. A graph the context's warm holds (the map an earlier prepare/3 answered) continues from it.

Types

prepared()

@type prepared() :: %{
  key: map(),
  simulation: Macaw.Draw.Layout.Force.t(),
  size: {number(), number()}
}

One graph's layout: the simulation, the plot size it is in, and its key.

Functions

key(node)

@spec key(map()) :: map()

The graph a node lays out, whatever it outputs: the key its simulation is prepared and carried under.

phrase()

@spec phrase() :: String.t()

What the frame is called when a data layer's rows are laid out by this step (spec/11 §2.2).

prepare(nodes, table, context)

@spec prepare([map()], Macaw.Data.Table.t(), map()) ::
  %{required(map()) => prepared()} | {:error, {String.t(), term()}}

Every distinct graph of nodes laid out once over table (spec/05 §5.3): a map from each graph's key/1 to its prepared/0, or the first graph's fault. A graph the context's warm holds (the map an earlier prepare/3 answered) continues from it.