Published
Edited
Nov 6, 2020
8 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = FileAttachment("gwinnett_county_wait_times.csv").csv({typed: true})
Insert cell
medianWaitTimes = d3.rollup(data, v => d3.median(v, d => d.waitTime), d => d.name)
Insert cell
json = FileAttachment("GA_precincts16_Gwinnett.json").json()
Insert cell
projection = d3
.geoAlbers()
.rotate([0, 64, 0])
.fitSize([mapWidth, mapHeight], json)
Insert cell
path = d3.geoPath(projection)
Insert cell
mapWidth = Math.min(width, 640)
Insert cell
mapHeight = Math.max(250, width / 2)
Insert cell
partyLabel = "% of 2016 votes for Clinton vs Trump"
Insert cell
raceLabel = "% of 2016 voting-age population who were Black"
Insert cell
mapTitle = mapColor === "party" ? partyLabel : raceLabel
Insert cell
precinctValue = d => {
const denominator = mapColor === "party"
? Number(d.properties.PRES16D) + Number(d.properties.PRES16R)
: Number(d.properties.VAP);
const numerator = mapColor === "party"
? Number(d.properties.PRES16D)
: Number(d.properties.BVAP);
return denominator ? numerator / denominator : 0;
}
Insert cell
partyColor = d3.scaleDiverging([0, 0.5, 1.0], d3.interpolateRdBu)
Insert cell
raceColor = d3.scaleSequential(d3.interpolatePurples)
Insert cell
color = mapColor === "party" ? partyColor : raceColor
Insert cell
locations = (await FileAttachment("gwinnett_county_early_voting_locations.csv").csv({typed: true}))
.map(({address, name, latitude, longitude}) => ({
address, name, coordinates: projection([longitude, latitude])
}))
Insert cell
d3 = require("d3@6")
Insert cell
import { vl } from "@vega/vega-lite-api"
Insert cell
import {legend} from "@d3/color-legend"
Insert cell
import {radio} from "@jashkenas/inputs"
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