Published
Edited
Apr 8, 2021
Insert cell
Insert cell
Insert cell
svg`
<svg viewBox="0 0 ${size.svg.width} ${size.svg.height}">
<g transform="translate(${size.svg.width / 2}, 50)">
${drawLinks(root.links())}
${drawNodes(root.descendants())}
</g>
</svg>
`
Insert cell
Insert cell
size = ({
svg: { width, height: width / 5 },
node: { width: 200, height: 50 },
})
Insert cell
Insert cell
root = d3.hierarchy(data)
Insert cell
Insert cell
treeGenerator = d3.tree().nodeSize([size.node.width, size.node.height])
Insert cell
Insert cell
tree = treeGenerator(root)
Insert cell
Insert cell
drawNodes = nodes => svg`
<g text-anchor="middle">
${
nodes.map(d => svg`
<g transform="translate(${d.x}, ${d.y})">
<text fill="white" stroke="white" stroke-width="10">${d.data.name}</text>
<text>${d.data.name}</text>
</g>
`)
}
</g>
`
Insert cell
Insert cell
linkGenerator = d3.linkVertical()
.x(d => d.x)
.y(d => d.y)
Insert cell
Insert cell
Insert cell
d3 = require("d3@6")
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