function visualizeTree(tree, {inset = 10, insetLeft = 10, insetRight = 160, ...options} = {}) {
const nodes = [];
(function recurse(node, names) {
for (const name in node.children) {
if (name === "..") continue;
const child = node.children[name];
if (child.type === "dir") recurse(child, names.concat(name));
nodes.push({
name: name,
path: names.concat(name).join("/"),
size: child.type === "dir" ? sumTree(child) : child.size
});
}
})(tree, []);
return Plot.plot({
axis: null,
inset,
insetLeft,
insetRight,
...options,
marks: [
Plot.tree(nodes, {
path: "path",
text: d => `${d.name} ${d.size.toLocaleString("en")}`
})
]
});
}