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.font(`9px sans-serif`);
// context.fillText(d.ingredient, d.x, d.y);
context.fill();
// context.moveTo(d.x + d.count, d.y);
// context.font(`6px arial`);
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.fill();
// for (const d of nodes) {
// context.beginPath();
// context.moveTo(d.x + d.count, d.y);
// // context.arc(d.x, d.y, d.count * 2, 0, 2 * Math.PI);
// context.font(`9px sans-serif`);
// context.fillText(d.ingredient, d.x, d.y);
// }
// context.fillStyle = "#fff";
// context.fill();
// context.strokeStyle = "#333";
// context.stroke();
context.restore();
}
return context.canvas;
}