Published
Edited
Jun 14, 2021
1 fork
Insert cell
Insert cell
maine = {
const width = 800, height = 800;
const svg = d3.select(DOM.svg(width, height))
const projection = d3.geoMercator()
.fitExtent([[0,0],[width, height]], geoME)
const extent = d3.extent(geoME.features, (d) => d.properties.vaxrate);
//const color = d3.scaleQuantize(extent, d3.schemeBlues[9]);
const color = d3.scaleSequential(extent, d3.interpolateBlues);
svg.append("g")
.attr("transform", "translate(610,20)")
.append(() => legend({color, width: 260, tickFormat: ".0%"}));
let path = d3.geoPath()
.projection(projection);
svg.append('g').selectAll('path')
.data(geoME.features)
.join('path')
.attr('d', path)
.attr("fill", d => color(d.properties.vaxrate))
.style('stroke', 'rgba(0,0,0,.3)')
.on('mouseover', function (e, d, i) {
tooltip
.html(
`<div>${d.properties.name}:
${d.properties.vaxrate ? format(d.properties.vaxrate*100)+"%" : "unknown"}</div>`)
.style('visibility', 'visible');
// TODO: highlight zip somehow
//d3.select(this).attr('fill', 'blue');
})
.on('mousemove', function (e) {
tooltip
.style('top', e.pageY + 10 + 'px')
.style('left', e.pageX + 10 + 'px');
})
.on('mouseout', function () {
tooltip.html(``).style('visibility', 'hidden');
//d3.select(this).transition().attr('fill', 'green');
});
return svg.node()
}
Insert cell
data = FileAttachment("maine_vax_06_01_2021_utf8.csv").tsv({typed: true})
Insert cell
geoME = await d3.json("https://raw.githubusercontent.com/OpenDataDE/State-zip-code-GeoJSON/master/me_maine_zip_codes_geo.min.json");

Insert cell
format = d3.format(".2f")
Insert cell
geoME.features.forEach(f => {
const d = data.filter(dd => dd['Zip Code'] == f.properties.ZCTA5CE10);
if (d.length > 0) {
f.properties.vaxrate = d[0]["Vaccination Rate 6-1"];
f.properties.name = `${f.properties.ZCTA5CE10} (${d[0].Town})`;
} else {
f.properties.name = f.properties.ZCTA5CE10;
f.properties.vaxrate = undefined;
}
})
Insert cell
geoME
Insert cell
geoME.features[0].properties
Insert cell
tooltip = d3
.select('body')
.append('div')
.style('position', 'absolute')
.style('z-index', '10')
.style('visibility', 'hidden')
.style('padding', '10px')
.style('background', 'rgba(0,0,0,0.6)')
.style('border-radius', '4px')
.style('color', '#fff');
Insert cell
extent = d3.extent(geoME.features, d => d.proprties.vaxrate);
Insert cell
Insert cell
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