p5(sketch => {
let system;
const radius = width/175;
const slider = sketch.createSlider(extent[0], extent[1], 1975);
let extraCanvas;
sketch.setup = function() {
sketch.createCanvas(width, width);
extraCanvas = sketch.createGraphics(width, width);
sketch.strokeWeight(2);
sketch.textSize(32);
sketch.textFont('Georgia');
slider.position(10, 10);
anomalies.forEach((d, i) => {
extraCanvas.noFill();
extraCanvas.strokeWeight(2);
extraCanvas.stroke(colorScale(d.value));
extraCanvas.circle(extraCanvas.width / 2, extraCanvas.height / 2, i * radius);
});
sketch.image(extraCanvas, 0, 0);
};
sketch.draw = function() {
sketch.clear();
sketch.image(extraCanvas, 0, 0);
const data = anomalies.find(({ year }) => year === slider.value());
const yearIndex = years.indexOf(data.year);
sketch.strokeWeight(1.5);
sketch.drawingContext.setLineDash([10, 10]);
sketch.fill("rgba(0,0,0,0)");
sketch.stroke("black");
sketch.circle(sketch.width / 2, sketch.height / 2, yearIndex * radius);
sketch.textAlign(sketch.CENTER);
sketch.fill("rgba(0,0,0,1)");
sketch.strokeWeight(0);
sketch.textStyle(sketch.NORMAL);
sketch.text(data.year, sketch.width / 2, sketch.height / 2 - 15);
sketch.textStyle(sketch.BOLD);
sketch.text(`${data.value} °C`, sketch.width / 2, sketch.height / 2 + 15);
}
})