Published unlisted
Edited
Oct 19, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
households_per_settlement_grouped = d3.group(household_data, d => d.municipality, d => d.settlement_name, d => d.household_total)
Insert cell
Insert cell
Insert cell
function nest(rollup) {
return Array.from(rollup, ([key, value]) =>
value instanceof Map
? { name: key, children: nest(value) }
: { name: key, value: value.length}
);
}
Insert cell
households_per_settlement_nested = ({name: "Villages", children: nest(households_per_settlement_grouped)})
Insert cell
Insert cell
Insert cell
md`
[I've faced this challenge before](https://talk.observablehq.com/t/how-to-move-from-d3-group-to-a-format-that-works-for-a-sunburst-chart/3931/4), and as a result Mike created a [different version of the chart that accepts rolled data](https://observablehq.com/d/08d45f2703b4cb7f). Somehow I'm not quite there yet.
`
Insert cell
households_per_settlement_rollup = {
const data = household_data
const rollup = d3.rollup(data, group => group.length, d => d.municipality, d => d.settlement_name, d => d.households_total,);
return d3.hierarchy(rollup).sum(([, value]) => value);
}
Insert cell
Insert cell
households_per_settlement_rolled = d3.rollup(
household_data,
(v) => d3.sum(v, (e) => e.household_total),
(d) => d.municipality,
(d) => d.settlement_name
)
Insert cell
households_per_settlement_re_rolled = {
const data = household_data
const rollup = d3.rollup(
household_data,
(v) => d3.sum(v, (e) => e.household_total),
(d) => d.municipality,
(d) => d.settlement_name);
return d3.hierarchy(rollup).sum(([, value]) => value);
}
Insert cell
Insert cell
import {chart as village_households_sunburst}
with {households_per_settlement_re_rolled as data}
from "08d45f2703b4cb7f"
Insert cell
village_households_sunburst
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more