Concepts
Drill-down & hierarchies
New in 0.6. SquarifiedTreemap and SunburstChart drill down under your control: the chart keeps no root of its own, it tells you which node was asked for and draws the one you pass back.
Try it
Click a rectangle or a ring, or focus a chart and press Enter or Space. Both charts read the same root, so they drill down together. Click the centre of the sunburst, or the frame of the treemap, to go back up.
| node | amount |
|---|---|
| City budget | 69,364 |
| City budget › Public works | 19,197, 27.7% of City budget |
| City budget › Public works › Street lighting | 8,015, 41.8% of Public works |
| City budget › Public works › Bridges | 6,154, 32.1% of Public works |
| City budget › Public works › Water mains | 2,878, 15% of Public works |
| City budget › Public works › Water mains › Water mains: staff | 2,069, 71.9% of Water mains |
| City budget › Public works › Water mains › Water mains: materials | 809, 28.1% of Water mains |
| City budget › Public works › Roads | 2,150, 11.2% of Public works |
| City budget › Public works › Roads › Roads: staff | 1,760, 81.9% of Roads |
| City budget › Public works › Roads › Roads: materials | 390, 18.1% of Roads |
| City budget › Administration | 18,611, 26.8% of City budget |
| City budget › Administration › IT services | 8,252, 44.3% of Administration |
| City budget › Administration › Payroll | 6,768, 36.4% of Administration |
| City budget › Administration › Records | 3,591, 19.3% of Administration |
| City budget › Administration › Records › Records: staff | 3,281, 91.4% of Records |
| City budget › Administration › Records › Records: materials | 310, 8.6% of Records |
| City budget › Safety | 13,294, 19.2% of City budget |
| City budget › Safety › Emergency planning | 6,265, 47.1% of Safety |
| City budget › Safety › Lifeguards | 5,224, 39.3% of Safety |
| City budget › Safety › Lifeguards › Lifeguards: materials | 2,953, 56.5% of Lifeguards |
| City budget › Safety › Lifeguards › Lifeguards: staff | 2,271, 43.5% of Lifeguards |
| City budget › Safety › Fire service | 1,805, 13.6% of Safety |
| City budget › Parks | 10,626, 15.3% of City budget |
| City budget › Parks › Playgrounds | 5,030, 47.3% of Parks |
| City budget › Parks › Playgrounds › Playgrounds: materials | 2,865, 57% of Playgrounds |
| City budget › Parks › Playgrounds › Playgrounds: staff | 2,165, 43% of Playgrounds |
| City budget › Parks › Tree care | 2,835, 26.7% of Parks |
| City budget › Parks › Sports fields | 2,761, 26% of Parks |
| City budget › Parks › Sports fields › Sports fields: staff | 2,455, 88.9% of Sports fields |
| City budget › Parks › Sports fields › Sports fields: materials | 306, 11.1% of Sports fields |
| City budget › Culture | 7,636, 11% of City budget |
| City budget › Culture › Libraries | 3,177, 41.6% of Culture |
| City budget › Culture › Libraries › Libraries: materials | 2,265, 71.3% of Libraries |
| City budget › Culture › Libraries › Libraries: staff | 912, 28.7% of Libraries |
| City budget › Culture › Museum | 2,999, 39.3% of Culture |
| City budget › Culture › Festivals | 1,460, 19.1% of Culture |
| City budget › Culture › Festivals › Festivals: staff | 1,275, 87.3% of Festivals |
| City budget › Culture › Festivals › Festivals: materials | 185, 12.7% of Festivals |
| node | amount |
|---|---|
| City budget | 69,364 |
| City budget › Public works | 19,197, 27.7% of City budget |
| City budget › Public works › Street lighting | 8,015, 41.8% of Public works |
| City budget › Public works › Bridges | 6,154, 32.1% of Public works |
| City budget › Public works › Water mains | 2,878, 15% of Public works |
| City budget › Public works › Water mains › Water mains: staff | 2,069, 71.9% of Water mains |
| City budget › Public works › Water mains › Water mains: materials | 809, 28.1% of Water mains |
| City budget › Public works › Roads | 2,150, 11.2% of Public works |
| City budget › Public works › Roads › Roads: staff | 1,760, 81.9% of Roads |
| City budget › Public works › Roads › Roads: materials | 390, 18.1% of Roads |
| City budget › Administration | 18,611, 26.8% of City budget |
| City budget › Administration › IT services | 8,252, 44.3% of Administration |
| City budget › Administration › Payroll | 6,768, 36.4% of Administration |
| City budget › Administration › Records | 3,591, 19.3% of Administration |
| City budget › Administration › Records › Records: staff | 3,281, 91.4% of Records |
| City budget › Administration › Records › Records: materials | 310, 8.6% of Records |
| City budget › Safety | 13,294, 19.2% of City budget |
| City budget › Safety › Emergency planning | 6,265, 47.1% of Safety |
| City budget › Safety › Lifeguards | 5,224, 39.3% of Safety |
| City budget › Safety › Lifeguards › Lifeguards: materials | 2,953, 56.5% of Lifeguards |
| City budget › Safety › Lifeguards › Lifeguards: staff | 2,271, 43.5% of Lifeguards |
| City budget › Safety › Fire service | 1,805, 13.6% of Safety |
| City budget › Parks | 10,626, 15.3% of City budget |
| City budget › Parks › Playgrounds | 5,030, 47.3% of Parks |
| City budget › Parks › Playgrounds › Playgrounds: materials | 2,865, 57% of Playgrounds |
| City budget › Parks › Playgrounds › Playgrounds: staff | 2,165, 43% of Playgrounds |
| City budget › Parks › Tree care | 2,835, 26.7% of Parks |
| City budget › Parks › Sports fields | 2,761, 26% of Parks |
| City budget › Parks › Sports fields › Sports fields: staff | 2,455, 88.9% of Sports fields |
| City budget › Parks › Sports fields › Sports fields: materials | 306, 11.1% of Sports fields |
| City budget › Culture | 7,636, 11% of City budget |
| City budget › Culture › Libraries | 3,177, 41.6% of Culture |
| City budget › Culture › Libraries › Libraries: materials | 2,265, 71.3% of Libraries |
| City budget › Culture › Libraries › Libraries: staff | 912, 28.7% of Libraries |
| City budget › Culture › Museum | 2,999, 39.3% of Culture |
| City budget › Culture › Festivals | 1,460, 19.1% of Culture |
| City budget › Culture › Festivals › Festivals: staff | 1,275, 87.3% of Festivals |
| City budget › Culture › Festivals › Festivals: materials | 185, 12.7% of Festivals |
rootId:
nullHow it works
- The data is one row per node, linked to its parent:
idKey,parentKey(nullfor the root),labelKeyandvalueKeyon the leaves. TreeChart reads the same rows. - Activating a node emits its id; activating the drawn root emits its parent's id, and
nullat the top. - Store it and pass it back as
rootId. Without a handler the chart does not drill: there is no hidden state, so a server render with arootIdis exactly the client's. depthlimits the levels drawn below the root.- By keyboard the hierarchy walks as a WAI-ARIA tree, and each node is announced with its path, its value and its share of its parent.
- Rows that do not make a valid hierarchy warn SP020 in development.
The event
| React | Vue | Angular | Reflex | |
|---|---|---|---|---|
| Root in | rootId | :root-id | [rootId] | root_id |
| Root asked for | onRootChange | @root-change | (rootChange) | on_root_change |
In your code
import { useState } from 'react';
import { SquarifiedTreemap } from '@silverpoint/react/squarified-treemap';
import { SunburstChart } from '@silverpoint/react/sunburst-chart';
// One row per node: { id, parent, name, amount }; the root's parent is null.
export function Budget({ data }: { data: Node[] }) {
const [root, setRoot] = useState<string | null>(null);
const keys = { idKey: 'id', parentKey: 'parent', labelKey: 'name', valueKey: 'amount' } as const;
return (
<>
<SquarifiedTreemap data={data} {...keys} rootId={root} onRootChange={setRoot} title="City budget" />
<SunburstChart data={data} {...keys} rootId={root} onRootChange={setRoot} title="City budget" />
</>
);
}<script setup lang="ts">
import { ref } from 'vue';
import { SpSquarifiedTreemap } from '@silverpoint/vue/squarified-treemap';
import { SpSunburstChart } from '@silverpoint/vue/sunburst-chart';
defineProps<{ data: Node[] }>();
const root = ref<string | null>(null);
</script>
<template>
<SpSquarifiedTreemap
:data="data" id-key="id" parent-key="parent" label-key="name" value-key="amount"
:root-id="root" @root-change="root = $event" title="City budget"
/>
<SpSunburstChart
:data="data" id-key="id" parent-key="parent" label-key="name" value-key="amount"
:root-id="root" @root-change="root = $event" title="City budget"
/>
</template>import { Component, input, signal } from '@angular/core';
import { SpSquarifiedTreemap } from '@silverpoint/angular/squarified-treemap';
import { SpSunburstChart } from '@silverpoint/angular/sunburst-chart';
@Component({
selector: 'app-budget',
imports: [SpSquarifiedTreemap, SpSunburstChart],
template: `
<sp-squarified-treemap
[data]="data()" idKey="id" parentKey="parent" labelKey="name" valueKey="amount"
[rootId]="root()" (rootChange)="root.set($event)" title="City budget"
/>
<sp-sunburst-chart
[data]="data()" idKey="id" parentKey="parent" labelKey="name" valueKey="amount"
[rootId]="root()" (rootChange)="root.set($event)" title="City budget"
/>
`,
})
export class Budget {
readonly data = input.required<Node[]>();
protected readonly root = signal<string | null>(null);
}import reflex as rx
from reflex_silverpoint_react import squarified_treemap, sunburst_chart
class Budget(rx.State):
root: str | None = None
@rx.event
def drill(self, node_id: str | None):
self.root = node_id
KEYS = {"id_key": "id", "parent_key": "parent", "label_key": "name", "value_key": "amount"}
rx.hstack(
squarified_treemap(data=ROWS, **KEYS, root_id=Budget.root, on_root_change=Budget.drill),
sunburst_chart(data=ROWS, **KEYS, root_id=Budget.root, on_root_change=Budget.drill),
)