Public
Edited
Sep 8, 2022
2 forks
78 stars
Insert cell
Insert cell
Insert cell
chart = {
const context = DOM.context2d(width, height),
path = d3
.geoPath(projection)
.context(context);

yield context.canvas;

while (animate) {
const rotate = projection.rotate();
rotate[0] += 0.3;
projection.rotate(rotate);
render(context, path);
yield context.canvas;
}

const sel = d3.select(context.canvas).style("cursor", "grab");
d3.geoInertiaDrag(sel, () => render(context, path), projection);
invalidation.then(() => sel.on(".drag", null));

render(context, path);
}
Insert cell
function render(context, path) {
// dark blue sphere
context.fillStyle = "#000";
context.fillRect(0, 0, width, height);

context.beginPath();
path({ type: "Sphere" });
context.fillStyle = "#003";
context.fill();

const clipAngle = projection.clipAngle();
context.globalAlpha = 0.3;
projection.clipAngle(180);
draw(context, path.pointRadius(0.7));

// front globe
context.globalAlpha = 1;
projection.clipAngle(clipAngle);
draw(context, path.pointRadius(1.5));
}
Insert cell
function draw(context, path) {
for (const [value, points] of groups) {
context.beginPath();
path({
type: "MultiPoint",
coordinates: points.map(p => [p.lon, p.lat])
});
context.fillStyle = value === "NA" ? "#666" : color(value);
context.fill();
}
}
Insert cell
data = d3.csv(await FileAttachment("warmer.csv").url())
Insert cell
groups = d3.group(data, d => d.change)
Insert cell
color = d3.scaleSequential(d3.interpolateRdBu).domain([3, -3])
Insert cell
projection = d3.geoSatellite()
.rotate([360 * Math.random(), -45])
.translate([width / 2, height / 2])
Insert cell
Insert cell
height = Math.min(550, width)
Insert cell
d3 = require("d3@7", "d3-inertia@0.2", "d3-geo-projection@4")
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