Unlisted
Edited
Jul 19, 2023
Insert cell
Insert cell
data = d3.csvParse(`path,visits
/root/something,1
/root/gallery,4
/root/gallery/chart-a,2
/root/gallery/chart-b,1`)
Insert cell
import { Treemap } from "@d3/treemap@483" // DEPRECATED
Insert cell
Treemap(data, {path: (d) => d.path, value: (d) => d?.visits, label: (d) => d.path, height: 200})
Insert cell
Insert cell
Treemap(data, {path: (d) => d.path + "/\0", value: (d) => d?.visits, label: (d) => d.path, height: 200})
Insert cell
Insert cell
import { Treemap as TreemapR } from "@d3/treemap@489"
Insert cell
TreemapR(data, {path: d => d.path, value: (d) => d.visits, label: (d) => d.path, height: 200})
Insert cell
stratify = (data, path) =>
(d3.stratify().path(path))(data)
.each((node) => {
if (node.children?.length && node.data != null) {
const child = new d3.Node(node.data);
node.data = null;
child.depth = node.depth + 1;
child.height = 0;
child.parent = node;
child.id = node.id + "/";
node.children.unshift(child);
}
})
Insert cell
Insert cell
d3P207 = require(await FileAttachment("d3-hierarchy.min.js").url())
Insert cell
d3.stratify().path(d => d)(["a", "a/b"])
Insert cell
d3P207.stratify().path(d => d)(["a", "a/b"])
Insert cell
d3P207.stratify().imputeLeaf(true).path(d => d)(["a", "a/b"])
Insert cell
view(d3P207.stratify().imputeLeaf(false).path(d => d.path)([{path:"a", value: 4}, {path:"a/b", value: 1}]))
Insert cell
view(d3P207.stratify().imputeLeaf(true).path(d => d.path)([{path:"a", value: 4}, {path:"a/b", value: 1}]))
Insert cell
view = (root) => md`${root.descendants().map(d => `*${" ".repeat(d.depth)} ${d.id} ${d.data?.value ? ` (${d.data.value})` : ""}`).join("\n")}`
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