chart = {
const context = DOM.context2d(width, height);
nodes.forEach(d=>{
d.r = sizeScale(d.progetti)
})
const simulation = d3.forceSimulation(nodes)
.alphaTarget(0.01)
.velocityDecay(0.3)
.force("x", d3.forceX()
.x(d=>d.pos.tipo ? d.pos.tipo.x : 0)
.strength(0.2))
.force("y", d3.forceY()
.y(d=>d.pos.tipo ? d.pos.tipo.y : 0)
.strength(0.2))
.force("collide", d3.forceCollide().radius(d => d.r + padding).iterations(5))
.on("tick", ticked);
invalidation.then(() => simulation.stop());
function ticked() {
context.clearRect(0, 0, width, height);
context.save();
for (const d of nodes) {
context.beginPath();
context.fillStyle = colors[d.tipo]
context.arc(d.x, d.y, d.r, 0, 2 * Math.PI);
context.fill();
}
context.restore();
}
setTimeout(() => {
simulation
.alphaTarget(0.3)
.velocityDecay(0.2)
.force("x", d3.forceX()
.x(d=>d.pos.delegazione ? d.pos.delegazione.x : 0)
.strength(0.1))
.force("y", d3.forceY()
.y(d=>d.pos.delegazione ? d.pos.delegazione.y : 0)
.strength(0.1))
.restart();
}, 6000);
setTimeout(() => {
nodes.forEach(d=>{
d.r = minRadius
})
simulation
.alphaTarget(0.3)
.velocityDecay(0.2)
.force("x", d3.forceX()
.x(d=>d.pos.ambito ? d.pos.ambito.x : 0)
.strength(0.1))
.force("y", d3.forceY()
.y(d=>d.pos.ambito ? d.pos.ambito.y : 0)
.strength(0.1))
.force("collide", d3.forceCollide().radius(d => d.r + padding).iterations(5))
.restart();
}, 15000);
return context.canvas;
}