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 coordinatesTiling 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
@type tile_algorithm() :: :squarify | :binary | :slice | :dice | :slice_dice
Functions
@spec generate(t(), Visualize.Layout.Hierarchy.t()) :: Visualize.Layout.Hierarchy.t()
Generates the treemap layout
@spec new() :: t()
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
@spec tile(t(), tile_algorithm()) :: t()
Sets the tiling algorithm