Published
Edited
Feb 9, 2019
8 forks
23 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
chart = {
const root = pack();

const svg = d3.select(DOM.svg(width, height));

if (grouped) svg.append("g")
.attr("fill", "none")
.attr("stroke", "#ccc")
.selectAll("circle")
.data(root.descendants().filter(d => d.height === 1))
.join("circle")
.attr("cx", d => d.x)
.attr("cy", d => d.y)
.attr("r", d => d.r);

svg.append("g")
.selectAll("circle")
.data(root.leaves())
.join("circle")
.attr("cx", d => d.x)
.attr("cy", d => d.y)
.attr("r", d => d.r)
.attr("fill", d => color(d.data.group));

return svg.node();
}
Insert cell
pack = () => d3.pack()
.size([width, height])
.padding(1)
(d3.hierarchy(data)
.sum(d => d.value))
Insert cell
data = ({
children: Array.from(
d3.group(
Array.from({length: n}, (_, i) => ({
group: Math.random() * m | 0,
value: -Math.log(Math.random())
})),
d => d.group
),
([, children]) => ({children})
)
})
Insert cell
color = d3.scaleOrdinal(d3.range(m), d3.schemeCategory10)
Insert cell
height = 600
Insert cell
d3 = require("d3@5", "d3-array@2")
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