Macaw.Draw.Layout.Radial (macaw_draw v0.1.0)

Copy Markdown View Source

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 is start_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 at inner_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:

OptionTypeDefault
layoutone of layouts/0:tree
radiuspositive number1
inner_radiusnon-negative number below radius0
start_anglenumber0
extentnumber in (0, 2π]2π
center{cx, cy}{0, 0}
separationfunction of two nodesd3'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].

new/1 with every option at its default.

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

t()

@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

columns(root, output)

@spec columns(Macaw.Draw.Layout.Hierarchy.t(), atom() | String.t()) ::
  %{required(String.t()) => [term()]} | Macaw.Draw.Layout.error()

columns/3 with no options.

columns(root, output, opts)

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

generate(radial, root)

Every node of root positioned on the radial tree or dendrogram (§15.2).

layouts()

@spec layouts() :: [atom()]

The layouts a radial tree runs over: [:tree, :cluster].

new()

@spec new() :: {:ok, t()}

new/1 with every option at its default.

new(opts)

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

separation(a, b)

d3's radial separation: (siblings ? 1 : 2) / a.depth, a depth of 0 read as 1.