Public
Edited
Oct 5, 2022
1 fork
Also listed in…
Mapping
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

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more