Published
Edited
Sep 22, 2020
Importers
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
metrics = Object.keys(eavsby.counties[0])
Insert cell
Insert cell
eavsby.counties
Insert cell
eavsbyfips = d3.group(eavsby.counties, d => d.FIPSCode.slice(0, 5))
Insert cell
Insert cell
// We use a log color scale
pollperregisteredColor = d3.scaleSequential(
pollperregisteredExtent,
d3.interpolateReds
)
Insert cell
pollperregisteredExtent = [0.01, 0] //d3.extent(eavsby.counties, getValue).reverse()
Insert cell
getValue = function(d) {
// active metric per county
// +d[activeMetric] / pop
// poll places per registered voter
return +d["D4a"] / +d["A1a"];
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
po
Insert cell
Insert cell
// activePostOffices = d3
// .csvParse(await FileAttachment("Post Offices@1.csv").text())
// .filter(po => {
// let nameWords = po.name.split(' ');
// return !nameWords.includes('(historical)');
// })
Insert cell
activePostOffices = d3
.csvParse(await FileAttachment("postoffices.csv").text())
.filter(d => d.status == "Open")
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function colorCountyByElectionData(fips, metric = "diff") {
let d = countyElectionResults.filter(d => +d.combined_fips == +fips)[0];
if (!d) return false;
return voteDiffColorScale(+d.diff);
// if (!d) return '#999';
// if (+d.votes_dem > +d.votes_gop) return 'blue';
// else return 'red';
}
Insert cell
Insert cell
Insert cell
{
let d = countyElectionResults.filter(
d => +d.combined_fips == +electionResults.id
)[0];
if (!d) return "";
return md`
${getPoId(electionResults)}
difference: ${numformat(d.diff)}
population: ${numformat(pop.get(electionResults.id))}
`;
}
Insert cell
electionResults
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
activeMetricExtent = d3.extent(eavsby.counties, d => +d[activeMetric])
Insert cell
Insert cell
numformat = d3.format(",d")
Insert cell
statesByFips
Insert cell
import {
us,
countyShapes,
populationData,
populationByCounty,
populationColor,
statesMesh,
statesByFips,
height,
projection,
populationFormat,
legend,
path
} from "@enjalot/making-a-county-map"
Insert cell
topojson = require("topojson-client@3")
Insert cell
Insert cell
usc = require('https://bundle.run/us-state-codes@1.1.2')
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