The tidy tree, for node-link diagrams (spec/08 §3.2).
iex> alias Macaw.Draw.Layout.{Hierarchy, Tree}
iex> {:ok, root, []} = Hierarchy.stratify(~w(r a b), [nil, "r", "r"], [])
iex> {:ok, tree} = Tree.new(size: {100, 50})
iex> tree |> Tree.generate(root) |> Hierarchy.descendants() |> Enum.map(&{&1.x, &1.y})
[{50.0, 0.0}, {0.0, 50.0}, {100.0, 50.0}]generate/2 sets x and y on every node: y the depth, x by the Reingold–Tilford
algorithm in the linear-time form of Buchheim, Jünger and Leipert, ported from
d3-hierarchy's tree. Children of one parent are placed left to right with the gap
separation gives, each parent centered over its first and last child, and no two nodes
at one depth closer than separation allows.
Options (§3.1), checked by new/1:
| Option | Type | Default |
|---|---|---|
size | {w, h} or [w, h] of non-negative numbers | nil |
node_size | {dx, dy} or [dx, dy] of positive numbers | nil |
separation | function of two nodes answering a non-negative number | siblings 1, otherwise 2 |
size and node_size are exclusive. Without either, x is in separation units with the
root at 0 and y in depth levels; size normalizes both into the box, node_size
multiplies them. This is visualize's Visualize.Layout.Tree, its setters replaced by
new/1 (spec/08 §17).
Summary
Functions
The columns of a laid-out tree (§3.5): :nodes, one row per node in pre-order ("row",
"id", "depth", "height", "value", "x", "y"), or :links, one row per
parent-child pair ("row" the child's, "source", "target", "x0", "y0", "x1",
"y1", "path") with options shape: and orientation: (Macaw.Draw.Layout.Links).
Every node of root positioned by the tidy tree, then scaled (§3.1, §3.2).
The layout of opts (§3.1): {:ok, tree}, or {:error, faults} with every bad option
at its path, {[:node_size], {:exclusive, :size}} when both sizes are given.
Types
@type t() :: %Macaw.Draw.Layout.Tree{ node_size: {number(), number()} | nil, separation: (Macaw.Draw.Layout.Hierarchy.t(), Macaw.Draw.Layout.Hierarchy.t() -> number()), size: {number(), number()} | nil }
Functions
@spec columns(Macaw.Draw.Layout.Hierarchy.t(), atom() | String.t(), keyword()) :: %{required(String.t()) => [term()]} | Macaw.Draw.Layout.error()
The columns of a laid-out tree (§3.5): :nodes, one row per node in pre-order ("row",
"id", "depth", "height", "value", "x", "y"), or :links, one row per
parent-child pair ("row" the child's, "source", "target", "x0", "y0", "x1",
"y1", "path") with options shape: and orientation: (Macaw.Draw.Layout.Links).
@spec generate(t(), Macaw.Draw.Layout.Hierarchy.t()) :: Macaw.Draw.Layout.Hierarchy.t() | Macaw.Draw.Layout.error()
Every node of root positioned by the tidy tree, then scaled (§3.1, §3.2).
@spec new() :: {:ok, t()}
new/1 with every option at its default.
@spec new(keyword() | map()) :: {:ok, t()} | Macaw.Draw.Layout.error()
The layout of opts (§3.1): {:ok, tree}, or {:error, faults} with every bad option
at its path, {[:node_size], {:exclusive, :size}} when both sizes are given.