Public
Edited
Dec 6, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function buildTree(nodes, links) {
// https://stackoverflow.com/a/68209716
const map = new Map(nodes.map((o) => [o.name, { ...o, children: [] }]));
for (let { source, target } of links)
map.get(source).children.push(JSON.stringify(map.get(target)));
return map;
}
Insert cell
tree = buildTree(nodes, links)
Insert cell
pack = (data) =>
d3.pack().size([width, 100]).padding(5)(
d3
.hierarchy(data)
.sum((d) => d.value)
.sort((a, b) => b.value - a.value)
)
Insert cell
root = tree.get("Overheid")
Insert cell
pack(root)
Insert cell
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