Published
Edited
May 12, 2020
Insert cell
Insert cell
chart_1 = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, 975, 610]);

svg.append("path")
.datum(topojson.feature(us, us.objects.nation))
.attr("fill", "#ccc")
.attr("d", path);

svg.append("path")
.datum(topojson.mesh(us, us.objects.states, (a, b) => a !== b))
.attr("fill", "none")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("d", path);

const legend = svg.append("g")
.attr("fill", "#777")
.attr("transform", "translate(925,608)")
.attr("text-anchor", "middle")
.style("font", "10px sans-serif")
.selectAll("g")
.data([1e6, 5e6, 1e7])
.join("g");

legend.append("circle")
.attr("fill", "none")
.attr("stroke", "#ccc")
.attr("cy", d => -radius(d))
.attr("r", radius);

legend.append("text")
.attr("y", d => -2 * radius(d))
.attr("dy", "1.3em")
.text(d3.format(".1s"));

svg.append("g")
.attr("fill", "brown")
.attr("fill-opacity", 0.5)
.attr("stroke", "#fff")
.attr("stroke-width", 0.5)
.selectAll("circle")
.data(topojson.feature(us, us.objects.states).features
.map(d => (d.value = covidData.get(d.id), d))
.sort((a, b) => b.value - a.value))
.join("circle")
.attr("transform", d => `translate(${path.centroid(d)})`)
.attr("r", d => radius(d.value))
.append("title")
.text(d => `${d.properties.name}
${format(d.value)}`);

return svg.node();
}
Insert cell
data = new Map((await FileAttachment("population.json").json()).slice(1).map(([population, state, county]) => [state, +population]))
Insert cell
radius = d3.scaleSqrt([0, d3.quantile([...data.values()].sort(d3.ascending), 0.1)], [0, 15])
Insert cell
path = d3.geoPath()
Insert cell
format = d3.format(",.0f")
Insert cell
us = FileAttachment("counties-albers-10m.json").json()
Insert cell
topojson = require("topojson-client@3")
Insert cell
d3 = require("d3@5")
Insert cell
data_1 = d3.csv(
"https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-states.csv"
)
Insert cell
covidData = new Map(data_1.map(d => [d.fips, +d.cases]))
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