Circle packing (spec/08 §4): every node a circle, leaves sized by value and internal nodes enclosing their children.
iex> alias Macaw.Draw.Layout.{Hierarchy, Pack}
iex> {:ok, root, []} = Hierarchy.stratify(~w(r a b), [nil, "r", "r"], [])
iex> {:ok, pack} = Pack.new(size: {100, 100})
iex> laid = Pack.generate(pack, Hierarchy.count(root))
iex> {laid.x, laid.y, laid.r}
{50.0, 50.0, 50.0}Options (§4.1), checked by new/1:
| Option | Type | Default |
|---|---|---|
size | {w, h} of non-negative numbers | {1, 1} |
padding | non-negative number, or function of an internal node answering one | 0 |
radius | function of a leaf answering a number, or nil | nil |
generate/2 expects value set by sum/2 or count/1 unless radius is given; a leaf
radius below 0 is clamped to 0. Siblings are packed by d3-hierarchy's packSiblings, in
child order, against the front chain; the enclosing circle is Welzl's over a shuffle
driven by d3's linear congruential generator from seed 1, so the result is fixed.
Padding is d3's two passes; the root is scaled into the box and centered in it. This is
visualize's Visualize.Layout.Pack, its setters replaced by new/1.
Summary
Functions
The columns of a packed hierarchy (§3.5): :nodes with "x", "y", "r", or :links,
each link the straight line between the centers whatever its shape:.
The minimal circle enclosing circles, each {x, y, r} (§4.2): Welzl's algorithm over a
Fisher–Yates shuffle driven by d3's linear congruential generator (a = 1664525,
c = 1013904223, m = 2^32, seed 1), so the answer is fixed. {0, 0, 0} for []; a
list holding a term that is no circle is {[], {:type, :circles}}.
Every node of root placed as a circle, x, y and r (§4.2). A root of radius 0 or
nil is answered without scaling and with leaf positions unset.
The layout of opts (§4.1): {:ok, pack} or {:error, faults}.
Types
A circle: center and radius.
@type t() :: %Macaw.Draw.Layout.Pack{ padding: number() | (Macaw.Draw.Layout.Hierarchy.t() -> number()), radius: (Macaw.Draw.Layout.Hierarchy.t() -> number()) | nil, size: {number(), number()} }
Functions
@spec columns(Macaw.Draw.Layout.Hierarchy.t(), atom() | String.t(), keyword()) :: %{required(String.t()) => [term()]} | Macaw.Draw.Layout.error()
The columns of a packed hierarchy (§3.5): :nodes with "x", "y", "r", or :links,
each link the straight line between the centers whatever its shape:.
@spec enclose([circle()]) :: circle() | Macaw.Draw.Layout.error()
The minimal circle enclosing circles, each {x, y, r} (§4.2): Welzl's algorithm over a
Fisher–Yates shuffle driven by d3's linear congruential generator (a = 1664525,
c = 1013904223, m = 2^32, seed 1), so the answer is fixed. {0, 0, 0} for []; a
list holding a term that is no circle is {[], {:type, :circles}}.
iex> Macaw.Draw.Layout.Pack.enclose([{0, 0, 1}, {4, 0, 1}])
{2.0, 0.0, 3.0}
@spec generate(t(), Macaw.Draw.Layout.Hierarchy.t()) :: Macaw.Draw.Layout.Hierarchy.t() | Macaw.Draw.Layout.error()
Every node of root placed as a circle, x, y and r (§4.2). A root of radius 0 or
nil is answered without scaling and with leaf positions unset.
@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 (§4.1): {:ok, pack} or {:error, faults}.