hospitalDots = {
let canvas = d3
.create("canvas")
.attr("width", width)
.attr("height", height)
.node();
let ctx = canvas.getContext("2d");
ctx.globalCompositeOperation = "lighter";
scaleCanvas(canvas, ctx);
let projection = d3
.geoAlbersUsa()
.fitSize([width - 10, height], countyShapes);
let path = d3
.geoPath()
.projection(projection)
.context(ctx);
ctx.fillStyle = "#111";
ctx.fillRect(0, 0, width, width);
ctx.fillStyle = "#555";
let r = 1;
hospitals
.filter(d => {
let events = eventsByHospital.get(d.hospital_pk);
if (events) return value(events[week]) > 75;
})
.sort(function(a, b) {
let eventsA = eventsByHospital.get(a.hospital_pk);
let eventsB = eventsByHospital.get(b.hospital_pk);
if (!eventsA || !eventsB) return -1;
return value(eventsA[week]) - value(eventsB[week]);
})
.forEach(d => {
let p = projection([d.LONGITUDE, d.LATITUDE]);
let events = eventsByHospital.get(d.hospital_pk);
if (events) {
let alpha = metricNormalize(value(events[week]));
r = metricRadius(value(events[week]));
let c = d3.rgb(colorScale(alpha));
ctx.fillStyle = `rgba(${[c.r, c.g, c.b]}, ${alpha}`;
}
if (p) ctx.fillRect(p[0], p[1], r, r);
});
return canvas;
}