Public
Edited
Mar 28, 2024
Insert cell
Insert cell
population = FileAttachment("population.json").json()
.then((data) =>
data
.slice(1) // removes a header line
.map(([p, state, county]) => ({
state,
county,
population: +p
}))
)
Insert cell
Insert cell
us = FileAttachment("counties-albers-10m.json").json()
Insert cell
nation = topojson.feature(us, us.objects.nation)
Insert cell
statemap = new Map(topojson.feature(us, us.objects.states).features.map(d => [d.id, d]))
Insert cell
countymap = new Map(topojson.feature(us, us.objects.counties).features.map(d => [d.id, d]))
Insert cell
Insert cell
statemesh = topojson.mesh(us, us.objects.states, (a, b) => a !== b)
Insert cell
Insert cell
radiusLegend = (data, options) =>
Plot.dot(data, {
...options,
frameAnchor: "bottom-right",
strokeWidth: 0.8,
dx: -40,
dy: -3,
render: (i, s, v, d, c, next) => {
const g = next(i, s, v, d, c);
d3.select(g)
.selectAll("circle")
.each(function (i) {
const r = +this.getAttribute("r");
const x = +this.getAttribute("cx");
const y = +this.getAttribute("cy");
this.setAttribute("transform", `translate(0,${-r})`);
const title = d3.select(this).select("title");
d3.select(g)
.append("text")
.attr("x", x)
.attr("y", y - 2 * r - 4)
.attr("stroke", "none")
.attr("fill", "currentColor")
.text(title.text());
title.remove();
});
return g;
}
})
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