Public
Edited
Aug 21, 2023
4 forks
5 stars
Insert cell
Insert cell
{
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);

const g0 = svg.append("g").attr("id", "all");
const g1 = svg.append("g").attr("id", "africa");

g0.append("path")
.attr("id", "land")
.attr("fill", "#fcfcfc")
.attr("stroke", "none")
.datum(topojson.feature(world, world.objects.land));

g0.append("path")
.attr("id", "borders-all")
.attr("fill", "none")
.attr("stroke", "#eee")
.datum(topojson.mesh(world, world.objects.countries, (a, b) => a !== b));

g0.append("path")
.attr("id", "shore-all")
.attr("fill", "none")
.attr("stroke", "lightblue")
.datum(topojson.feature(world, world.objects.land));

g1.append("g")
.attr("id", "countries-africa")
.selectAll()
.data(AfricanCountries)
.join("path")
.attr("fill", "#fefefe")
.attr("stroke", "none");

g1.append("path")
.attr("id", "borders-africa")
.attr("fill", "none")
.attr("stroke", "#ddd")
.datum(
topojson.mesh(Africa0, Africa0.objects.countries, (a, b) => a !== b)
);

g1.append("path")
.attr("id", "shore-africa")
.attr("fill", "none")
.attr("stroke", "orange")
.datum(Africa);

const path = d3.geoPath(projection);
svg.selectAll("path").attr("d", path);

return svg.node();
}
Insert cell
import { world110m as world } from "@visionscarto/geo"
Insert cell
topojson.merge(world, world.objects.countries.geometries)
Insert cell
AfricanCountries = topojson
.feature(world, world.objects.countries)
.features.filter((d) => {
const c = d3.geoCentroid(d);
return c[0] > -20 && c[0] < 47 && c[1] < 34.5 && c[0] + c[1] < 60;
})
Insert cell
Africa0 = topojson.topology({
countries: { type: "FeatureCollection", features: AfricanCountries }
})
Insert cell
Africa = topojson.merge(Africa0, Africa0.objects.countries.geometries)
Insert cell
projection = d3
.geoChamberlinAfrica()
.fitExtent(
[
[50, 50],
[width - 50, height - 50]
],
Africa
)
.clipExtent([
[-2, -2],
[width + 2, height + 2]
])
Insert cell
topojson = require("topojson-client@3", "topojson-server@3")
Insert cell
d3 = require("d3@7", "d3-geo-projection@4")
Insert cell
height = 900
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