Public
Edited
May 12
1 fork
1 star
Insert cell
Insert cell
import * as d3 from "https://cdn.jsdelivr.net/npm/d3@7";
import * as Plot from "https://cdn.jsdelivr.net/npm/@observablehq/plot@0.6";
import {autoType, csv} from "https://cdn.jsdelivr.net/npm/d3-dsv@3";
import {hierarchy, treemap} from "https://cdn.jsdelivr.net/npm/d3-hierarchy@3";
import {scaleOrdinal} from "https://cdn.jsdelivr.net/npm/d3-scale@4";
Insert cell
data = FileAttachment("keeping-track-of-the-big-picture-radial4.csv").csv({ typed: true })
Insert cell
function nest(data, keys) {
if (!keys.length) return data;
const [first, ...rest] = keys;
return Object.values(data.reduce((acc, row) => {
const key = row[first];
if (!acc[key]) {
acc[key] = { name: key, children: [] };
}
acc[key].children.push(rest.length ? row : {...row, name: row.Item}); // Ensure leaf nodes have a name
return acc;
}, {}));
}
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