Public
Edited
Dec 20, 2022
1 fork
5 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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more