The radial tree and radial dendrogram (spec/08 §15): a tree drawn in polar coordinates,
the root at the center, depth outward, siblings around, over Macaw.Draw.Layout.Tree
(§3.2) and Macaw.Draw.Layout.Cluster (§3.3).
iex> alias Macaw.Draw.Layout.{Hierarchy, Radial}
iex> {:ok, root, []} = Hierarchy.stratify(~w(r a b), [nil, "r", "r"], [])
iex> {:ok, radial} = Radial.new(radius: 10)
iex> radial |> Radial.generate(root) |> Hierarchy.descendants() |> Enum.map(&Float.round(&1.angle, 4))
[3.1416, 1.5708, 4.7124]The chosen layout runs in raw mode with d3's radial separation, (siblings ? 1 : 2) / a.depth (a depth of 0 read as 1). With left and right its least and greatest x
and s = separation(left, right):
- on a full circle (
extent == 2π) the angle isstart_angle + extent · (x − left.x + s / 2) / (right.x − left.x + s), so the first and last leaves are one separation apart across the start (spec/08 decision 13); - on a partial span
start_angle + extent · (x − left.x) / (right.x − left.x); - the radius is
inner_radius + (radius − inner_radius) · y / max_y, the root atinner_radius; - the position is
{cx + r · sin(angle), cy − r · cos(angle)}.
Every node gains angle, radius, x and y.
Options (§15.1), checked by new/1:
| Option | Type | Default |
|---|---|---|
layout | one of layouts/0 | :tree |
radius | positive number | 1 |
inner_radius | non-negative number below radius | 0 |
start_angle | number | 0 |
extent | number in (0, 2π] | 2π |
center | {cx, cy} | {0, 0} |
separation | function of two nodes | d3's radial separation |
Summary
Functions
columns/3 with no options.
The columns of a radial tree (§15.3). :nodes, one row per node in pre-order: "row",
"id", "depth", "value", "angle", "radius", "x", "y", and the label's
suggested "anchor", "start" for an angle in [0, π) and "end" otherwise, so labels
read outward. :links, one row per parent-child pair: "row" (the child's),
"source", "target", "path" (Links.radial/4 of the shape: option, :curve by
default). A root generate/2 did not lay out is {[], :not_radial}.
Every node of root positioned on the radial tree or dendrogram (§15.2).
The layouts a radial tree runs over: [:tree, :cluster].
The layout of opts (§15.1): {:ok, radial} or {:error, faults}. An inner_radius not
below radius is {[:inner_radius], {:type, :below_radius}}, an extent outside
(0, 2π] {[:extent], {:type, :extent}}, a center that is not two numbers
{[:center], {:type, :point}}.
d3's radial separation: (siblings ? 1 : 2) / a.depth, a depth of 0 read as 1.
Types
@type t() :: %Macaw.Draw.Layout.Radial{ center: {number(), number()}, extent: number(), inner_radius: number(), layout: :tree | :cluster, radius: number(), separation: (Macaw.Draw.Layout.Hierarchy.t(), Macaw.Draw.Layout.Hierarchy.t() -> number()) | nil, start_angle: number() }
Functions
@spec columns(Macaw.Draw.Layout.Hierarchy.t(), atom() | String.t()) :: %{required(String.t()) => [term()]} | Macaw.Draw.Layout.error()
columns/3 with no options.
@spec columns(Macaw.Draw.Layout.Hierarchy.t(), atom() | String.t(), keyword() | map()) :: %{required(String.t()) => [term()]} | Macaw.Draw.Layout.error()
The columns of a radial tree (§15.3). :nodes, one row per node in pre-order: "row",
"id", "depth", "value", "angle", "radius", "x", "y", and the label's
suggested "anchor", "start" for an angle in [0, π) and "end" otherwise, so labels
read outward. :links, one row per parent-child pair: "row" (the child's),
"source", "target", "path" (Links.radial/4 of the shape: option, :curve by
default). A root generate/2 did not lay out is {[], :not_radial}.
@spec generate(t(), Macaw.Draw.Layout.Hierarchy.t()) :: Macaw.Draw.Layout.Hierarchy.t() | Macaw.Draw.Layout.error()
Every node of root positioned on the radial tree or dendrogram (§15.2).
@spec layouts() :: [atom()]
The layouts a radial tree runs over: [:tree, :cluster].
@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 (§15.1): {:ok, radial} or {:error, faults}. An inner_radius not
below radius is {[:inner_radius], {:type, :below_radius}}, an extent outside
(0, 2π] {[:extent], {:type, :extent}}, a center that is not two numbers
{[:center], {:type, :point}}.
@spec separation(Macaw.Draw.Layout.Hierarchy.t(), Macaw.Draw.Layout.Hierarchy.t()) :: float() | Macaw.Draw.Layout.error()
d3's radial separation: (siblings ? 1 : 2) / a.depth, a depth of 0 read as 1.