Public
Edited
Sep 13, 2023
Insert cell
Insert cell
Insert cell
animation = {
const n = 50;
const pad = 2;
const data = d3.range(n).map((i) => ({ r: i }));

const simulation = d3
.forceSimulation(data)
.force("x", d3.forceX())
.force("y", d3.forceY())
.force(
"collide",
d3.forceCollide((d) => d.r)
)
.stop();

let s = 500;
let svg = d3.create("svg").attr("width", s).attr("height", s);
let g = svg.append("g").attr("transform", `translate(${s / 2}, ${s / 2})`);

let circs = g
.selectAll("circle")
.attr("fill", "black")
.data(data)
.join("circle")
// .attr("cx", (c) => c.x)
// .attr("cy", (c) => c.y)
.attr("r", (c) => 0.9 * c.r);

for (let i = 0; i * steps_per_tick < 300; i++) {
simulation.tick(steps_per_tick);
circs.attr("cx", (c) => c.x).attr("cy", (c) => c.y);
yield svg.node();
}
}
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