Public
Edited
Aug 1, 2023
57 forks
Importers
75 stars
Insert cell
Insert cell
canvas = {
const context = DOM.context2d(width, height);
const path = d3.geoPath(projection, context);
while (true) {
for (let i = 0, n = 480; i < n; ++i) {
const t = d3.easeCubic(2 * i > n ? 2 - 2 * i / n : 2 * i / n);
projection.alpha(t).rotate(rotate(t)).scale(scale(t));
context.clearRect(0, 0, width, height);
context.beginPath();
path(graticule);
context.lineWidth = 1;
context.strokeStyle = "#aaa";
context.stroke();
context.beginPath();
path(sphere);
context.lineWidth = 1.5;
context.strokeStyle = "#000";
context.stroke();
context.beginPath();
path(equator);
context.lineWidth = 1.5;
context.strokeStyle = "#f00";
context.stroke();
yield context.canvas;
}
}
}
Insert cell
function interpolateProjection(raw0, raw1) {
const mutate = d3.geoProjectionMutator(t => (x, y) => {
const [x0, y0] = raw0(x, y), [x1, y1] = raw1(x, y);
return [x0 + t * (x1 - x0), y0 + t * (y1 - y0)];
});
let t = 0;
return Object.assign(mutate(t), {
alpha(_) {
return arguments.length ? mutate(t = +_) : t;
}
});
}
Insert cell
projection = interpolateProjection(d3.geoOrthographicRaw, d3.geoEquirectangularRaw)
.scale(scale(0))
.translate([width / 2, height / 2])
.rotate(rotate(0))
.precision(0.1)
Insert cell
rotate = d3.interpolate([10, -20], [0, 0])
Insert cell
scale = d3.interpolate(width / 4, (width - 2) / (2 * Math.PI))
Insert cell
height = width / 1.8
Insert cell
equator = ({type: "LineString", coordinates: [[-180, 0], [-90, 0], [0, 0], [90, 0], [180, 0]]})
Insert cell
sphere = ({type: "Sphere"})
Insert cell
graticule = d3.geoGraticule10()
Insert cell
d3 = require("d3-geo@2", "d3-interpolate@2", "d3-ease@2")
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