Published
Edited
May 14, 2020
1 fork
21 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
draw = (context, points, t) => {
mutable nbtotal = points.length;

if (points.length > nbCities) {
points = points.slice();
d3.quickselect( // very nice suggestion from https://observablehq.com/@fil Thanks!!
points,
nbCities,
0,
points.length - 1,
(a, b) => b.size - a.size
);
points.splice(nbCities, points.length - 1)
}
if (background){
context.globalAlpha = 1
context.drawImage(image, 0, 0, width, height)
context.fill()
}
mutable nbrendered = points.length;
context.globalAlpha = 0.5
context.fillStyle = background ? 'yellow' : 'black'
const k = 1 / 500 / t.k;
for (let i = 0; i < points.length; i++) {
const d = points[i],
v = d.size * k;
context.beginPath();
context.arc(
d[0],
d[1],
Math.sqrt(v),
0,
tau
) // Color, size, anything can be changed.
context.fill()
}

}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
image = zoomable('https://raw.githubusercontent.com/toulousedataviz/toulousedataviz.github.io/master/CanvasElectionsx8.png')
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more