canvas = {
const width = 800, height = 600;
const context = DOM.context2d(width, height);
context.clearRect(0, 0, width, height);
const voronoi = d3.Delaunay
.from(points, d => d.x * width, d => d.y * height)
.voronoi([0, 0, width, height]);
for (let i = 0; i < points.length; i++) {
context.beginPath();
voronoi.renderCell(i, context);
context.fillStyle = points[i].color;
context.fill();
const cell = voronoi.cellPolygon(i);
if (!cell) continue;
const cx = points[i].x * width;
const cy = points[i].y * height;
const dotCount = Math.floor(points[i].weight * 2000);
for (let j = 0; j < dotCount; j++) {
const angle = Math.random() * 2 * Math.PI;
const radius = Math.random() * 30;
const px = cx + Math.cos(angle) * radius;
const py = cy + Math.sin(angle) * radius;
if (d3.polygonContains(cell, [px, py])) {
context.fillStyle = "rgba(255,255,255,0.5)";
context.beginPath();
context.arc(px, py, 0.8, 0, 2 * Math.PI);
context.fill();
}
}
}
return context.canvas;
}