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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more