Published
Edited
Mar 30, 2020
Importers
Insert cell
Insert cell
Insert cell
original = d3.csv(link, function(row) {
row.size = parseInt(row.size);
return row;
});
Insert cell
Insert cell
Insert cell
nodes = new Set(original.map(row => row.name))
Insert cell
processed = original.map(function(row) {
// get name of parent node
let parent = row.name.substring(0, row.name.lastIndexOf("."));
return {
name: row.name,
// if there isn't a parent node set the paren to java directly
parent: nodes.has(parent) || row.name === "java" ? parent : "java",
size: row.size
};
})
Insert cell
Insert cell
root = d3.stratify()
.id(function(row) { return row.name; })
.parentId(function(row) {
return row.parent;
})
(processed);
Insert cell
Insert cell
Insert cell
java11 = {
root.count()
root.each(function(node) {
// copy this calculation since value is sometimes overwritten
node.data.leaves = node.value;
})
root.sum(row => row.size)
root.each(function(node) {
// copy this calculation since value is sometimes overwritten
node.data.total = node.value;
})
return root;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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