Visualize.Layout.Cluster (Visualize v0.2.25)

Copy Markdown View Source

Cluster layout algorithm for dendrogram visualizations.

Similar to the tree layout, but all leaves are placed at the same depth, creating a dendrogram effect useful for hierarchical clustering visualizations.

Examples

data = %{
  name: "root",
  children: [
    %{name: "A", children: [%{name: "A1"}, %{name: "A2"}]},
    %{name: "B", children: [%{name: "B1"}, %{name: "B2"}, %{name: "B3"}]}
  ]
}

root = Visualize.Layout.Hierarchy.new(data)

cluster = Visualize.Layout.Cluster.new()
  |> Visualize.Layout.Cluster.size([400, 200])

positioned = Visualize.Layout.Cluster.generate(cluster, root)

Summary

Functions

Generates the cluster layout, positioning all nodes.

Creates a new cluster layout

Sets the fixed node size.

Sets the separation function between nodes.

Sets the size of the layout.

Types

t()

@type t() :: %Visualize.Layout.Cluster{
  node_size: {number(), number()} | nil,
  separation:
    (Visualize.Layout.Hierarchy.t(), Visualize.Layout.Hierarchy.t() -> number())
    | nil,
  size: {number(), number()} | nil
}

Functions

generate(cluster, root)

Generates the cluster layout, positioning all nodes.

Unlike tree layout, all leaves are placed at the same y coordinate.

new()

@spec new() :: t()

Creates a new cluster layout

node_size(cluster, arg2)

@spec node_size(t(), [number()] | {number(), number()}) :: t()

Sets the fixed node size.

Unlike size/2, this sets a fixed spacing between nodes.

separation(cluster, func)

@spec separation(t(), (Visualize.Layout.Hierarchy.t(),
                 Visualize.Layout.Hierarchy.t() ->
                   number())) ::
  t()

Sets the separation function between nodes.

The function receives two leaf nodes and returns the desired separation.

size(cluster, arg2)

@spec size(t(), [number()] | {number(), number()}) :: t()

Sets the size of the layout.

The cluster will be scaled to fit within [width, height].