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

The dendrogram: a node-link diagram whose leaves all sit at one depth (spec/08 §3.3).

    iex> alias Macaw.Draw.Layout.{Cluster, Hierarchy}
    iex> {:ok, root, []} = Hierarchy.stratify(~w(r a b a1), [nil, "r", "r", "a"], [])
    iex> {:ok, cluster} = Cluster.new()
    iex> cluster |> Cluster.generate(root) |> Hierarchy.leaves() |> Enum.map(&{&1.x, &1.y})
    [{0, 2}, {2, 2}]

`generate/2` places every leaf first, left to right in pre-order, at `x = 0, s1, s1 + s2,
…`, each `s` being `separation.(leaf, previous_leaf)`; every internal node at the
midpoint of its first and last child. `y` is `root.height` for every leaf and the depth
for every internal node. The options and their scaling are the tree's
(`Macaw.Draw.Layout.Tree`, §3.1). This is visualize's `Visualize.Layout.Cluster`, its
setters replaced by `new/1`.

# `t`

```elixir
@type t() :: %Macaw.Draw.Layout.Cluster{
  node_size: {number(), number()} | nil,
  separation: (Macaw.Draw.Layout.Hierarchy.t(),
               Macaw.Draw.Layout.Hierarchy.t() -&gt;
                 number()),
  size: {number(), number()} | nil
}
```

# `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 laid-out cluster, as the tree's (§3.5): `:nodes` with `"x"`, `"y"`, or
`:links` with `shape:` and `orientation:`.

# `generate`

```elixir
@spec generate(t(), Macaw.Draw.Layout.Hierarchy.t()) ::
  Macaw.Draw.Layout.Hierarchy.t() | Macaw.Draw.Layout.error()
```

Every node of `root` positioned as a dendrogram, then scaled (§3.3). Leaves are matched to
their positions by `{data, depth}`; with `stratify/3`'s rows as data no two share one.

# `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`, the tree's options (§3.1): `{:ok, cluster}` or `{:error, faults}`.

---

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