Published
Edited
Apr 4, 2021
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
{
const svg = d3
.create("svg")
.attr("viewBox", [0, 0, width, 700])
.style("width", "100%")
.style("height", "auto");

svg
.append("g")
.selectAll("path")
.data(
topojson.feature(topojson_data, topojson_data.objects.counties).features
)
.enter()
.append("path")
.attr("fill", function(d) {
if (!county_data[d.id]) {
return 'white';
}
let v = county_data[d.id].Series_Complete_65PlusPop_Pct;
return d3.interpolate("white", "green")(v / 100);
})
.attr("d", path)
.append("title") // Tooltip
.text(function(d) {
if (!county_data[d.id]) {
return '';
}
return `${
county_data[d.id].Series_Complete_65PlusPop_Pct
}% of the 65+ population in ${county_data[d.id].County}, ${county_data[d.id].StateAbbr.trim()} have had the complete vaccination`;
});
return svg.node();
}
Insert cell
Insert cell
county_dates = (await fetch(
"https://cdc-vaccination-history.datasette.io/cdc.json?sql=select%20distinct%20Date%20from%20daily_reports_counties%20order%20by%20Date&_shape=arrayfirst"
)).json()
Insert cell
topojson_url = 'https://d3js.org/us-10m.v1.json'
Insert cell
topojson_data = await (await fetch(topojson_url)).json()
Insert cell
async function cachedFetch(url) {
window._cache = window._cache || {};
if (!window._cache[url]) {
window._cache[url] = await d3.csv(url);
}
return window._cache[url];
}
Insert cell
path = d3.geoPath()
Insert cell
topojson = require('topojson')
Insert cell
county_data_url = `https://cdc-vaccination-history.datasette.io/cdc/daily_reports_counties.csv?_stream=on&Date=${county_date}&_size=max`
Insert cell
county_csv_data = await cachedFetch(county_data_url)
Insert cell
county_data = county_csv_data.reduce((acc, value) => {
acc[value.FIPS] = value;
return acc;
}, {})
Insert cell
import { Scrubber } from "@mbostock/scrubber"
Insert cell
d3 = require("d3@6", "d3-geo-projection@2")
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