Published
Edited
Feb 21, 2020
3 forks
Importers
46 stars
Insert cell
Insert cell
Insert cell
Insert cell
projection = d3.geoNaturalEarth1()
.fitExtent([[0, 0], [width, height]], { type: "Sphere" })
.precision(0.1)
Insert cell
path = d3.geoPath()
.projection(projection)
Insert cell
Insert cell
Insert cell
land = topojson.merge(world, world.objects.countries.geometries.filter(d => d.id !== "010"))
Insert cell
Insert cell
Insert cell
Insert cell
land_simplified = {
//It's possible to first presimplify to get a sense of what min-value needs to be given to topojson.simplify
let world_simplified = topojson.presimplify(world)
let min_weight = topojson.quantile(world_simplified, quantile_value)
//Every arc coordinate whose z-value is lower than min_weight is removed
world_simplified = topojson.simplify(world_simplified, min_weight)
//Merge the simplified countries into a new land shape
let land = topojson.merge(world_simplified, world_simplified.objects.countries.geometries.filter(d => d.id !== "010")) //take out Antractica
return land
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
land_rounded = {
//Run the geo-path variable on the simplified land coordinates to get the SVG path coordinates back
//as a string, and next split these by each start of a new SVG path, the "M"
const svg_path = path(land_simplified).split("M")
//Remove the first empty result
svg_path.shift()
//Loop through each separate path, remove the closing letter of the path, "Z"
//Then split by each straight path section, given by "L"
//And finally, get the x and y coordinates by splitting the remaining string by its comma ","
let land_rounded = []
svg_path.forEach(d => { land_rounded.push(d.replace(/Z/,"").split("L").map(p => p.split(","))) })
return land_rounded
}
Insert cell
Insert cell
line = d3.line()
.x(d => d[0])
.y(d => d[1])
.curve(d3.curveBasisClosed)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
height = width / 2
Insert cell
Insert cell
Insert cell
Insert cell
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