Visualize.Layout.Treemap (Visualize v0.2.25)

Copy Markdown View Source

Treemap layout for hierarchical data as nested rectangles.

Treemaps display hierarchical data as a set of nested rectangles, where the area of each rectangle is proportional to its value.

Examples

data = %{
  name: "root",
  children: [
    %{name: "A", value: 100},
    %{name: "B", value: 200},
    %{name: "C", children: [
      %{name: "C1", value: 50},
      %{name: "C2", value: 75}
    ]}
  ]
}

# Build hierarchy and compute values
root = Visualize.Layout.Hierarchy.new(data)
  |> Visualize.Layout.Hierarchy.sum(fn d -> d[:value] || 0 end)

# Apply treemap layout
treemap = Visualize.Layout.Treemap.new()
  |> Visualize.Layout.Treemap.size([400, 300])
  |> Visualize.Layout.Treemap.padding(2)

positioned = Visualize.Layout.Treemap.generate(treemap, root)

# Each node now has x0, y0, x1, y1 coordinates

Tiling Algorithms

  • :squarify - Squarified treemap (default, good aspect ratios)
  • :binary - Binary split (recursive halving)
  • :slice - Horizontal slices
  • :dice - Vertical slices
  • :slice_dice - Alternating slice/dice by depth

Summary

Functions

Generates the treemap layout

Creates a new treemap layout

Sets uniform padding on all sides

Sets the bottom padding

Sets the inner padding between siblings

Sets the left padding

Sets the right padding

Sets the top padding

Enables rounding of coordinates to integers

Sets the size of the treemap

Sets the tiling algorithm

Types

t()

@type t() :: %Visualize.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_algorithm()
}

tile_algorithm()

@type tile_algorithm() :: :squarify | :binary | :slice | :dice | :slice_dice

Functions

generate(treemap, root)

Generates the treemap layout

new()

@spec new() :: t()

Creates a new treemap layout

padding(treemap, p)

@spec padding(t(), number()) :: t()

Sets uniform padding on all sides

padding_bottom(treemap, p)

@spec padding_bottom(t(), number()) :: t()

Sets the bottom padding

padding_inner(treemap, p)

@spec padding_inner(t(), number()) :: t()

Sets the inner padding between siblings

padding_left(treemap, p)

@spec padding_left(t(), number()) :: t()

Sets the left padding

padding_right(treemap, p)

@spec padding_right(t(), number()) :: t()

Sets the right padding

padding_top(treemap, p)

@spec padding_top(t(), number()) :: t()

Sets the top padding

round(treemap, round?)

@spec round(t(), boolean()) :: t()

Enables rounding of coordinates to integers

size(treemap, arg2)

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

Sets the size of the treemap

tile(treemap, algorithm)

@spec tile(t(), tile_algorithm()) :: t()

Sets the tiling algorithm