Published
Edited
Dec 24, 2020
2 forks
15 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = {
const root = {};
const map = new Map([[".", root]]);
function get(path) {
if (map.has(path)) return map.get(path);
const i = path.lastIndexOf("/");
const node = {name: path.substring(i + 1)};
const parent = get(path.substring(0, i));
if (parent.children) parent.children.push(node);
else parent.children = [node];
map.set(path, node);
return node;
}
for (let [value, path] of source.trim()
.split(/\r?\n/g)
.map(line => line.trim().split(/\s+/g))) {
if (path === "total") continue;
if (!/^\.\//.test(path)) path = `./${path}`;
get(path).value = +value;
}
return root;
}
Insert cell
pack = data => d3.pack()
.size([width, height])
.padding(3)
(d3.hierarchy(data)
.sum(d => d.children ? 0 : isNaN(d.value) ? 1 : d.value)
.sort((a, b) => b.value - a.value))
Insert cell
format = d3.format(",d")
Insert cell
width = 960
Insert cell
height = width
Insert cell
radius = Math.min(width, height) / 2
Insert cell
fileColor = "#e4e4e4"
Insert cell
folderColor = "#aaa"
Insert cell
d3 = require("d3@5")
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