chart = {
replay;
const svg = d3.select(DOM.svg(width, height));
const data = d3.range(10).map((d, i) => (
{
width: 120,
height: 40,
x: Math.random() * width,
y: Math. random() * height
}));
const nodes = data;
const node = svg.append("g")
.selectAll("rect")
.data(nodes)
.join("rect")
.attr("x", d => d.x - d.width/2)
.attr("y", d => d.y - d.height/2)
.attr('width', d => d.width)
.attr('height', d => d.height)
.style('fill', (d, i) => color(i % 10));
const simulation = d3.forceSimulation(nodes)
.force("x", d3.forceX(width / 2).strength(0.05))
.force("y", d3.forceY(height / 2).strength(0.05))
.force("collide", forceCollide());
simulation.on('tick', () => {
node.attr("x", d => d.x - d.width/2)
.attr("y", d => d.y - d.height/2);
});
invalidation.then(() => simulation.stop());
return svg.node();
}