hemisphere = ({ year, month }, config = {}) => {
const { width = 600, height = Math.min(width, 600) } = config;
const context = DOM.context2d(width, height);
const projection = d3.geoOrthographic().fitExtent(
[
[10, 10],
[width - 10, height * 2 - 20]
],
sphere
);
const path = d3.geoPath(projection, context);
function render(country, arc) {
context.clearRect(0, 0, width, height);
context.beginPath(),
context.rect(0, 0, width, height),
(context.fillStyle = "hsl(200, 50%, 44%)"),
context.fill();
context.beginPath(),
path(sphere),
(context.fillStyle = "hsl(200, 6%, 96%)"),
context.fill();
context.beginPath(),
path(land),
(context.fillStyle = "#ccc"),
context.fill();
context.beginPath(),
path(getTyphoonsPath(typhoonsOfDate({ year, month }))),
(context.strokeStyle = "hsla(0, 100%, 80%, 0.5)"),
(context.lineWidth = 0.75),
context.stroke();
context.beginPath(),
path(sphere),
(context.strokeStyle = "#002"),
(context.lineWidth = 1),
context.stroke();
context.beginPath(), path(arc), context.stroke();
if (year) {
(context.font = `bold ${height * 0.25}px Arial`),
(context.fillStyle = "hsla(200, 50%, 0%, 0.5)"),
(context.textAlign = "left"),
context.fillText(year, 30, height * 0.28);
}
if (month) {
(context.font = `bold ${height * 0.25}px Arial`),
(context.fillStyle = "hsla(200, 50%, 0%, 0.5)"),
(context.textAlign = "right"),
context.fillText(monthLabels.at(month - 1), width - 30, height * 0.28);
}
return context.canvas;
}
projection.rotate([230, 0, 0]);
return render(japan);
}