chart = {
replay;
const context = DOM.context2d(width, height);
const nodes = logItems;
const simulation = d3
.forceSimulation(nodes)
.velocityDecay(0.2)
.force("x", d3.forceX().strength(0.002))
.force("y", d3.forceY().strength(0.002))
.force(
"collide",
d3
.forceCollide()
.radius((d) => {
return circleScale(d.count);
})
.iterations(2)
)
.on("tick", ticked);
invalidation.then(() => simulation.stop());
function ticked() {
context.clearRect(0, 0, width, height);
context.save();
context.translate(width / 2, height / 2);
for (const d of nodes) {
context.fillStyle = "#000";
context.moveTo(d.x + d.count, d.y);
context.beginPath();
context.arc(d.x, d.y, circleScale(d.count), 0, 2 * Math.PI);
context.fill();
if (d.count > 10) {
context.fillStyle = "#fff";
context.textAnchor = "center";
context.textAlign = "center";
context.beginPath();
context.fillText(d.ingredient.slice(0, 9), d.x, d.y + 2);
}
}
context.restore();
}
return context.canvas;
}