Phoenix LiveView function components for hierarchies (spec/10 §3): a node-link tree, a treemap and a sunburst.
Each is a preset design of Visualize.Chart.Presets plus an assign mapping (spec/14
§15.4, D-64, D-70): the nested data — a map whose children are under :children or
"children" — is flattened to one row per node, the design's transforms (:tree,
:treemap or :partition, then the :filter steps that keep what spec/10 §3 draws)
lay the rows out, the marks draw them through Visualize.Chart.Frame.generate/2, and
the component prints the elements in the markup spec/10 §3 declares, reading the rows
beside them for what follows the node — the tree's circle-and-text group. The
treemap's and the sunburst's labels are their marks', fitted and inked by the layer.
Node labels default to the :name or "name" of a node's data; leaf values to its
:value or "value".
Usage
use Phoenix.Component
import Visualize.Components.Tree
<.tree_diagram data={@hierarchy} width={800} height={600} />Conventions
- A root-only hierarchy is the empty case: the tree draws its one node, the treemap
one cell, the sunburst nothing but the
<svg>(the root is never an arc). colorsis a scheme atom ofVisualize.Scale.Color.schemes/0or an explicit colour list, taken by index and cycled, as inVisualize.Components; an unknown scheme or an empty list raisesArgumentError.animate={true}putsstyle="transition: all 0.3s ease-in-out;"on every mark;classlands on the<svg>; coordinates print with at most four decimals.- The defaults below are
Visualize.Chart.Presets.defaults/1.
Summary
Functions
Renders a sunburst: the radial partition of the :partition transform
(Visualize.Layout.Partition) with one arc per node below the root.
Renders a node-link tree laid out by the :tree transform (Visualize.Layout.Tree).
Renders a treemap of the hierarchy's leaves laid out by the :treemap transform
(Visualize.Layout.Treemap).
Functions
Renders a sunburst: the radial partition of the :partition transform
(Visualize.Layout.Partition) with one arc per node below the root.
Assigns
data- the nested map with leaf values (required)width,height- pixels (default 600 by 600); the radius is half the smallervalue- astreemap_chart/1label- astree_diagram/1; drawn at the arc's centroid, cut with…to the arc's length there, and inked the theme's text or background, whichever reads on the arccolors- astreemap_chart/1animate,class,responsive,theme,title,description- per the module conventions
Angles are Visualize.Layout.Partition over {2π, radius}: the root spans the full
turn, each child a share of its parent's arc proportional to its summed value, and a
node of value 0 a zero-width slot that draws nothing. Ring radii are
depth / (height + 1) · radius. Each arc is Visualize.Shape.Arc — angles clockwise
from 12 o'clock — as a <path fill={colour} stroke={:background} stroke-width="1">.
Attributes
data(:map) (required)width(:integer) - Defaults to600.height(:integer) - Defaults to600.value(:any) - Defaults tonil.label(:any) - Defaults tonil.colors(:any) - Defaults to:category10.animate(:boolean) - Defaults tofalse.class(:string) - Defaults tonil.responsive(:boolean) - Defaults tofalse.theme(:any) - Defaults tonil.title(:string) - Defaults tonil.description(:string) - Defaults tonil.
Renders a node-link tree laid out by the :tree transform (Visualize.Layout.Tree).
Assigns
data- the nested map (required)width,height- pixels (default 800 by 600)margin- merged over%{top: 20, right: 120, bottom: 20, left: 120}, which leaves room for the labels of the root and of the leavesorientation-:horizontal(root at the left, depth along x) or:vertical(root at the top) (default:horizontal)node_radius- (default 6)node_fill- fill of leaf circles (defaultnil: the theme's:background)node_stroke- circle stroke, and the fill of internal nodes (defaultnil: the theme's:series_1)link_stroke- (defaultnil: the theme's:grid)label- accessor of a node's data;nilreads:nameor"name"animate,class,responsive,theme,title,description- per the module conventions
Links are cubic Béziers between parent and child with both control points at the
midpoint of the depth axis. Horizontal labels sit at x = −10, anchored end, for
internal nodes and at x = 10, anchored start, for leaves; vertical labels are
centred at x = 0.
Attributes
data(:map) (required)width(:integer) - Defaults to800.height(:integer) - Defaults to600.margin(:map) - Defaults to%{left: 120, right: 120, top: 20, bottom: 20}.orientation(:atom) - Defaults to:horizontal.node_radius(:integer) - Defaults to6.node_fill(:string) - Defaults tonil.node_stroke(:string) - Defaults tonil.link_stroke(:string) - Defaults tonil.label(:any) - Defaults tonil.animate(:boolean) - Defaults tofalse.class(:string) - Defaults tonil.responsive(:boolean) - Defaults tofalse.theme(:any) - Defaults tonil.title(:string) - Defaults tonil.description(:string) - Defaults tonil.
Renders a treemap of the hierarchy's leaves laid out by the :treemap transform
(Visualize.Layout.Treemap).
Assigns
data- the nested map with leaf values (required)width,height- pixels (default 800 by 600); the layout fills the whole<svg>value- leaf value accessor;nilreads:valueor"value", missing is 0label- astree_diagram/1tile- aVisualize.Layout.Treemap.tile/2algorithm (default:squarify)padding- uniform cell padding (default 2)colors- per the module conventions; each child of the root takes the next colour and every leaf beneath it that colour (default:category10)animate,class,responsive,theme,title,description- per the module conventions
A :label_size label is drawn at the centre of its cell, inked the theme's text or
background, whichever reads on the cell, and cut with … to the cell's width; a cell
shorter than the label's font size, a zero-area one among them, draws none.
Attributes
data(:map) (required)width(:integer) - Defaults to800.height(:integer) - Defaults to600.value(:any) - Defaults tonil.label(:any) - Defaults tonil.tile(:atom) - Defaults to:squarify.padding(:integer) - Defaults to2.colors(:any) - Defaults to:category10.animate(:boolean) - Defaults tofalse.class(:string) - Defaults tonil.responsive(:boolean) - Defaults tofalse.theme(:any) - Defaults tonil.title(:string) - Defaults tonil.description(:string) - Defaults tonil.