Public
Edited
Oct 5, 2022
1 fork
Also listed in…
Inputs
Insert cell
Insert cell
Insert cell
Insert cell
chart
Insert cell
countryNamesLookup.get(chart)
Insert cell
ids = {
let s = new Set(land50.features.map(d=>+d.id))
let a = Array.from(s);
return a}
Insert cell
numcolors = ids.length
Insert cell
colours = d3.range(numcolors).map(x => d3.interpolateSpectral(x / numcolors))
Insert cell
colourmap = {
let m = new Map()
ids.forEach((d,i) => m[d] = colours[i])
return m
}
Insert cell
reversecolourmap = {
let m = new Map()
ids.forEach((d,i) => m[colours[i]] = d)
return m
}
Insert cell
Insert cell
projection = d3[projectionName]().precision(0.1)
Insert cell
height = {
const [[x0, y0], [x1, y1]] = d3.geoPath(projection.fitWidth(width, sphere)).bounds(sphere);
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
sphere = ({type: "Sphere"})
Insert cell
land50 = FileAttachment("countries-50m.json").json().then(world => topojson.feature(world, world.objects.countries))
Insert cell
Insert cell
topojson = require("topojson-client@3")
Insert cell
d3 = require("d3@6")
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