# `Macaw.Draw.Layout.Treemap`
[🔗](https://github.com/dcoai/macaw_draw/blob/v0.1.0/lib/macaw/draw/layout/treemap.ex#L1)

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.

# `t`

```elixir
@type t() :: %Macaw.Draw.Layout.Treemap{
  padding: number(),
  padding_bottom: number() | nil,
  padding_inner: number() | nil,
  padding_left: number() | nil,
  padding_right: number() | nil,
  padding_top: number() | nil,
  round: boolean(),
  size: {number(), number()},
  tile: tile()
}
```

# `tile`

```elixir
@type tile() :: :squarify | :binary | :slice | :dice | :slice_dice
```

A tiling.

# `columns`

```elixir
@spec columns(Macaw.Draw.Layout.Hierarchy.t(), atom() | String.t(), keyword()) ::
  %{required(String.t()) =&gt; [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.

# `generate`

```elixir
@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).

# `new`

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

`new/1` with every option at its default.

# `new`

```elixir
@spec new(keyword() | map()) :: {:ok, t()} | Macaw.Draw.Layout.error()
```

The layout of `opts` (§6.1): `{:ok, treemap}` or `{:error, faults}`.

# `tiles`

```elixir
@spec tiles() :: [tile()]
```

The tilings: `[:squarify, :binary, :slice, :dice, :slice_dice]`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
