Circle packing layout for hierarchical data.
Enclosing circles show hierarchical containment, with the area of each leaf circle proportional to its value.
The sibling packing is a port of d3-hierarchy's packSiblings (the front-chain
algorithm of Wang et al.) and the enclosing circle of d3's packEnclose (Welzl's
algorithm over a deterministic shuffle), so a layout is a pure function of its input.
Examples
data = %{
name: "root",
children: [
%{name: "A", value: 100},
%{name: "B", value: 200},
%{name: "C", children: [
%{name: "C1", value: 50},
%{name: "C2", value: 75}
]}
]
}
root = Visualize.Layout.Hierarchy.new(data)
|> Visualize.Layout.Hierarchy.sum(fn d -> d[:value] || 0 end)
pack = Visualize.Layout.Pack.new()
|> Visualize.Layout.Pack.size([400, 400])
|> Visualize.Layout.Pack.padding(3)
positioned = Visualize.Layout.Pack.generate(pack, root)
# Each node now has x, y (center) and r (radius)
Summary
Functions
Generates the pack layout
Creates a new pack layout
Sets the padding between circles, in output units.
Sets a custom radius function.
Sets the size of the pack layout
Types
@type t() :: %Visualize.Layout.Pack{ padding: number() | (Visualize.Layout.Hierarchy.t() -> number()), radius: (Visualize.Layout.Hierarchy.t() -> number()) | nil, size: {number(), number()} }
Functions
@spec generate(t(), Visualize.Layout.Hierarchy.t()) :: Visualize.Layout.Hierarchy.t()
Generates the pack layout
@spec new() :: t()
Creates a new pack layout
@spec padding(t(), number() | (Visualize.Layout.Hierarchy.t() -> number())) :: t()
Sets the padding between circles, in output units.
Can be a number or a function that takes a node and returns padding.
@spec radius(t(), (Visualize.Layout.Hierarchy.t() -> number())) :: t()
Sets a custom radius function.
If not set, radius is computed from the node's value.
Sets the size of the pack layout