Treemaps: nested rectangles whose areas are proportional to value (spec/08 §6).
iex> alias Macaw.Draw.Layout.{Hierarchy, Treemap}
iex> {:ok, root, []} = Hierarchy.stratify(~w(r a b), [nil, "r", "r"], [])
iex> {:ok, treemap} = Treemap.new(size: {10, 4}, tile: "dice")
iex> laid = Treemap.generate(treemap, Hierarchy.count(root))
iex> Enum.map(laid.children, &{&1.x0, &1.y0, &1.x1, &1.y1})
[{0.0, 0.0, 5.0, 4.0}, {5.0, 0.0, 10.0, 4.0}]Options (§6.1), checked by new/1:
| Option | Type | Default |
|---|---|---|
size | {w, h} | {1, 1} |
tile | one of tiles/0, an atom or its spelling | :squarify |
padding | non-negative number | 0 |
padding_top, padding_right, padding_bottom, padding_left | non-negative number or nil | nil |
padding_inner | non-negative number or nil | nil (0) |
round | boolean | false |
generate/2 gives the root {0, 0, w, h}; every node with children has its rectangle
shrunk by the four paddings (a side they invert collapsing to its midpoint, as d3's
positionNode does) and its children tiled into it, then laid out in turn. A child's
weight is its value when that is a number above 0, else 0; a child of weight 0 gets a
zero-area rectangle where it would sit. With no weight or no area, every child sits at
the inner rectangle's top-left corner. Each tile is inset by padding_inner / 2; a
rectangle that inverts collapses to its midpoint. This is visualize's
Visualize.Layout.Treemap, its tiling read by spelling.
Summary
Functions
The columns of a treemap (§3.5): :nodes with "x0", "y0", "x1", "y1"; a treemap
has no :links output, and asking for one is a fault.
Every node of root given its rectangle, x0, y0, x1, y1 (§6.2).
The layout of opts (§6.1): {:ok, treemap} or {:error, faults}.
The tilings: [:squarify, :binary, :slice, :dice, :slice_dice].
Types
@type tile() :: :squarify | :binary | :slice | :dice | :slice_dice
A tiling.
Functions
@spec columns(Macaw.Draw.Layout.Hierarchy.t(), atom() | String.t(), keyword()) :: %{required(String.t()) => [term()]} | Macaw.Draw.Layout.error()
The columns of a treemap (§3.5): :nodes with "x0", "y0", "x1", "y1"; a treemap
has no :links output, and asking for one is a fault.
@spec generate(t(), Macaw.Draw.Layout.Hierarchy.t()) :: Macaw.Draw.Layout.Hierarchy.t() | Macaw.Draw.Layout.error()
Every node of root given its rectangle, x0, y0, x1, y1 (§6.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 (§6.1): {:ok, treemap} or {:error, faults}.
@spec tiles() :: [tile()]
The tilings: [:squarify, :binary, :slice, :dice, :slice_dice].