Published
Edited
May 6, 2021
6 stars
Insert cell
Insert cell
drawCountries = {
const context = DOM.context2d(width, height),
path = d3.geoPath(projection, context);
yield context.canvas;

context.beginPath();
path({ type: "Sphere" });
context.stroke();
context.lineWidth = .5;

for (const circle of countries.features.map(encloseFeature)) {
context.beginPath();
path(
d3
.geoCircle()
.center(circle.c)
.radius(circle.r)()
);
context.fillStyle = color(circle.r);
context.globalAlpha = .2;
context.fill();
context.globalAlpha = 1;
context.stroke();
}

context.globalAlpha = .1;
context.fillStyle = "#000";
context.beginPath();
path(countries);
context.fill();
}
Insert cell
import { enclose } from "@fil/spherical-smallest-circle-problem"
Insert cell
function encloseFeature(f) {
const { type, coordinates } = f.geometry;
return enclose(
coordinates.flat(type == "Polygon" ? 1 : 2) /*.map(d => ((d[2] = 0.1), d))*/
);
}
Insert cell
Insert cell
d3 = require("d3@5", "d3-geo-projection@2")
Insert cell
countries = fetch(
"https://unpkg.com/visionscarto-world-atlas@0.0.6/world/110m_countries.geojson"
).then(d => d.json())
Insert cell
projection = d3
.geoLarrivee()
.rotate([-10, 0])
.fitExtent([[2, 2], [width - 2, height - 2]], { type: "Sphere" })
Insert cell
color = d3.scaleOrdinal(d3.schemeDark2)
Insert cell
import { select } from "@jashkenas/inputs"
Insert cell
height = 720
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