chart = {
const scale = 1.7;
const center = [width / 2, height / 2];
const rescale = isNaN(nodes[0].x);
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
const node = svg.append("g")
.selectAll("circle")
.data(nodes)
.join("circle")
.attr("r", 4)
.attr("fill", d => d.color);
const simulation = d3.forceSimulation(nodes)
.on("tick", tick)
.force("collide", d3.forceCollide().radius(d => 1 + d.r))
.force("x", d3.forceX(center[0]).strength(0.001))
.force("y", d3.forceY(center[1]).strength(0.001))
.stop();
setTimeout(() => {
simulation.restart();
node.transition().attr("r", d => d.r);
}, 2000);
if (rescale) {
for (const node of nodes) {
node.x = node.x * scale + center[0];
node.y = node.y * scale + center[1];
}
}
function tick() {
node.attr("cx", d => d.x).attr("cy", d => d.y);
}
tick();
return svg.node();
}