Public
Edited
Dec 20, 2022
1 fork
6 stars
Insert cell
Insert cell
Insert cell
graticule = d3.geoGraticule10()
Insert cell
chart1 = Chart(d3.geoOrthographic().clipAngle(null), (context, path) => {
context.beginPath();
path(graticule);
context.strokeStyle = "#333";
context.stroke();
})
Insert cell
Insert cell
chart2 = Chart(d3.geoOrthographic().clipAngle(90), (context, path) => {
context.beginPath();
path(graticule);
context.strokeStyle = "#333";
context.stroke();
context.beginPath();
path(sphere);
context.strokeStyle = "#000";
context.lineWidth = 2;
context.stroke();
})
Insert cell
sphere = ({type: "Sphere"})
Insert cell
Insert cell
chart3 = Chart(d3.geoOrthographic().clipAngle(90), (context, path, gradient) => {
if (!gradient) {
const cx = width * 0.75;
const cy = height * 0.25;
const cr = Math.min(width, height) / 2;
gradient = context.createRadialGradient(cx, cy, 0, cx, cy, cr);
gradient.addColorStop(0.05, "#ffd");
gradient.addColorStop(1.00, "#ba9");
}
context.beginPath();
path(sphere);
context.fillStyle = gradient;
context.fill();
context.beginPath();
path(graticule);
context.strokeStyle = "#123";
context.globalAlpha = 0.5;
context.stroke();
context.beginPath();
path(sphere);
context.lineWidth = 2;
context.stroke();
return gradient;
})
Insert cell
Insert cell
function* Chart(projection, render) {
const context = DOM.context2d(width, height);
const path = d3.geoPath(projection.fitExtent([[1, 1], [width - 1, height - 1]], sphere).precision(0.2), context);
context.canvas.style.maxWidth = "100%";
let state;
while (true) {
const t = performance.now();
projection.rotate([vx * t, vy * t]);
context.clearRect(0, 0, width, height);
context.save();
state = render(context, path, state);
context.restore();
yield context.canvas;
}
}
Insert cell
vx = 0.018 // lambda degrees per millisecond
Insert cell
vy = 0.006 // theta degrees per millisecond
Insert cell
width = 960
Insert cell
height = 500
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