Published
Edited
Mar 1, 2022
4 stars
Insert cell
Insert cell
Insert cell
Insert cell
height = 600
Insert cell
reverseInterpolators = statePaths.map((d, i) => flubber.interpolate(voronoiPaths[i], d))
Insert cell
interpolators = statePaths.map((d, i) => flubber.interpolate(d, voronoiPaths[i]))
Insert cell
voronoiPaths = voronoiPolygons.map(d => project(d))
Insert cell
voronoiPolygons = d3.geoVoronoi(stateCentroids.map(d => projection.invert([d[0],d[1]]))).polygons().features
Insert cell
stateCentroids = stateFeatures.map(d => path.centroid(d))
Insert cell
statePaths = cleanedStateFeatures.map(d => path(d))
Insert cell
path = d3.geoPath();
Insert cell
project = d3.geoPath(projection);
Insert cell
cleanedStateFeatures = JSON.parse(JSON.stringify(stateFeatures)).map(feature => {
// Lower Peninsula Bias Inserted Here
if (feature.id == "26") {
feature.geometry.coordinates = [feature.geometry.coordinates[0]]
} else if (feature.geometry.coordinates.length > 1) {
const maxIndex = d3.maxIndex(feature.geometry.coordinates, d => d[0].length)
feature.geometry.coordinates = [feature.geometry.coordinates[maxIndex]]
}
return feature
})
Insert cell
stateFeatures = topojson.feature(us, us.objects.states).features.filter(d => d.id !== "02" && d.id !== "15")
Insert cell
projection = d3.geoAlbers().scale(1280).translate([480, 300]).clipExtent([[0, 0],[width, height]])
Insert cell
stateToFIPS = d3.csv('https://gist.githubusercontent.com/dantonnoriega/bf1acd2290e15b91e6710b6fd3be0a53/raw/11d15233327c8080c9646c7e1f23052659db251d/us-state-ansi-fips.csv', ({stname: state, " st": code, " stusps": abbrev}) => ({state, code: code.trim(), abbrev: abbrev.trim()}))
Insert cell
us = d3.json("https://cdn.jsdelivr.net/npm/us-atlas@1/us/10m.json")
Insert cell
topojson = require("topojson-client@3")
Insert cell
flubber = require("flubber")
Insert cell
d3 = require("d3-fetch@1", "d3-dsv@1", "d3-geo@1", "d3-geo-voronoi@1", "d3-geo-polygon", "d3-selection", "d3-transition", "d3-array", "d3-polygon")
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