Public
Edited
Feb 24, 2023
1 fork
Also listed in…
reusable
Insert cell
Insert cell
map = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);

const defs = svg.append("defs");

defs.append("path")
.attr("id", "outline")
.attr("d", path(outline));

defs.append("clipPath")
.attr("id", "clip")
.append("use")
.attr("xlink:href", new URL("#outline", location));

const g = svg.append("g")
.attr("clip-path", `url(${new URL("#clip", location)})`);

g.append("use")
.attr("xlink:href", new URL("#outline", location))
.attr("fill", "#fff");

g.append("path")
.attr("d", path(graticule))
.attr("stroke", "#ddd")
.attr("fill", "none");

g.append("path")
.attr("d", path(land))
.attr("fill", "#ddd");

svg.append("use")
.attr("xlink:href", new URL("#outline", location))
.attr("stroke", "#000")
.attr("fill", "none");

svg.append("g")
.selectAll("circle")
.data(data)
.join("circle")
.attr("transform", d => `translate(${projection([d.longitude, d.latitude])})`)
.attr("r", 1.5)
.append("title")
.text(d => d.name);

return svg.node();
}
Insert cell
data = {
const url = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_month.geojson";
const response = await d3.json(url);
return response.features.map(d => ({
name: d.properties.title,
longitude: d.geometry.coordinates[0],
latitude: d.geometry.coordinates[1]
}));
}
Insert cell
path = d3.geoPath(projection)
Insert cell
projection = d3.geoNaturalEarth1()
Insert cell
height = {
const [[x0, y0], [x1, y1]] = d3.geoPath(projection.fitWidth(width, outline)).bounds(outline);
const dy = Math.ceil(y1 - y0), l = Math.min(Math.ceil(x1 - x0), dy);
projection.scale(projection.scale() * (l - 1) / l).precision(0.2);
return dy;
}
Insert cell
outline = ({type: "Sphere"})
Insert cell
graticule = d3.geoGraticule10()
Insert cell
land = topojson.feature(world, world.objects.land)
Insert cell
world = FileAttachment("land-50m.json").json()
Insert cell
topojson = require("topojson-client@3")
Insert cell
d3 = require("d3@6")
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