Public
Edited
Aug 1, 2023
60 forks
Importers
77 stars
Also listed in…
Gallery
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

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