interactiveMap = {
const canvas = d3
.create("canvas")
.attr("width", width)
.attr("height", height)
.node();
canvas.width = width;
canvas.height = height;
let ctx = canvas.getContext("2d");
scaleCanvas(canvas, ctx);
function draw() {
ctx.fillStyle = "rgba(255,255,255,0.5)";
ctx.fillRect(0, 0, width, height);
simulation.nodes().forEach(d => {
let opacity = 0.2 + d.value;
let fill = "lightgray";
if (d.stateWinner) {
if (d.results.trumpd < d.results.bidenj) {
fill = blue;
} else if (d.results.trumpd > d.results.bidenj) {
fill = red;
}
}
let rgb = d3.rgb(fill);
ctx.strokeStyle = `rgba(${rgb.r},${rgb.g},${rgb.b},${0.1}`;
ctx.beginPath();
ctx.moveTo(d.cx, d.cy);
ctx.lineTo(d.x, d.y);
ctx.stroke();
});
simulation.nodes().forEach(d => {
let opacity = 0.2 + d.value;
let fill = "lightgray";
if (d.stateWinner) {
if (d.results.trumpd < d.results.bidenj) {
fill = blue;
} else if (d.results.trumpd > d.results.bidenj) {
fill = red;
}
}
let rgb = d3.rgb(fill);
ctx.fillStyle = `rgba(${rgb.r},${rgb.g},${rgb.b},${opacity}`;
ctx.beginPath();
ctx.arc(d.x, d.y, d.r * 0.9, 0, Math.PI * 2);
ctx.fill();
});
}
draw();
simulation.on("tick", draw);
invalidation.then(() => simulation.stop());
return canvas;
}