chart = {
replay;
const nodes = pack().leaves();
const simulation = d3.forceSimulation(nodes)
.force("center", d3.forceCenter(width / 2, height / 2))
.force("x", d3.forceX(width / 2).strength(0.01))
.force("y", d3.forceY(height / 2).strength(0.01))
.force("cluster", forceCluster())
.force("collide", forceCollide());
const svg = d3.select(DOM.svg(width, height));
const node = svg.append("g")
.selectAll("circle")
.data(nodes)
.join("circle")
.attr("cx", d => d.x)
.attr("cy", d => d.y)
.attr("fill", d => odss[d.data.text].color)
.call(drag(simulation)).on('click', (d,i) => switchRadius(400, i)());
node.transition()
.delay((d, i) => Math.random() * 500)
.duration(750)
.attrTween("r", d => {
const i = d3.interpolate(0, d.r);
return t => d.r = i(t);
});
simulation.on("tick", () => {
node
.attr("cx", d => d.x)
.attr("cy", d => d.y)
});
function switchRadius(newRadius, index) {
return function() {
d3.selectAll('.node')
.filter(function(d,i) { return i === index; })
.transition().duration(1000)
.tween('r', function(d) {
var that = d3.select(this);
var i = d3.interpolate(d.r, newRadius);
return function(t) {
d.radius = i(t);
that.attr('r', function(d) { return d.r; });
simulation.nodes(data)
}
});
simulation.alpha(1).restart();
}
}
function clicked(d, i) {
if (d3.event.defaultPrevented) return;
d3.select(this).transition()
.attr("r", d=> d.r * 2);
}
invalidation.then(() => simulation.stop());
return svg.node();
}