Published
Edited
Oct 5, 2020
2 forks
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
projection = d3.geoAlbersUsa().fitSize([width - 10, height - 20], countyShapes)
Insert cell
diffScale = d3
.scaleLinear()
// .domain(diffExtent)
.domain([-10000, 10000])
.range([-10, 10])
Insert cell
turf.centroid(countyShapes.features[0])
Insert cell
center = d => {
return projection(turf.centroid(d).geometry.coordinates) || [0, 0];
}
Insert cell
allYearsFlat = FileAttachment("allYearsFlat@1.csv").csv({ typed: false })
Insert cell
allYearsFlat.filter(d => d.State_Full == "WISCONSIN")
Insert cell
allYearsFlat.filter(d => diff(d) < -1000000)
Insert cell
eavsByCounty = new Map(
allYearsFlat.map(d => {
let s = String(d.FIPSCode);
return [s.slice(0, s.length - 5).padStart(5, "0"), d];
})
)
Insert cell
diff = d => {
return +d["A1a|2018"] - +d["A1a|2016"];
}
Insert cell
diffExtent = d3.extent(allYearsFlat, diff)
Insert cell
d3.min(allYearsFlat, diff)
Insert cell
// https://observablehq.com/@mbostock/mortality-due-to-alcohol-use-disorder
color2 = {
const values = allYearsFlat.map(diff);
const max = Math.max(d3.min(values), d3.max(values));

return d3
.scaleSqrt()
.domain([-max, 0, max])
.range([-1, 0, 1])
.interpolate((a, b) =>
a < 0 ? t => d3.interpolatePurples(1 - t) : t => d3.interpolateGreens(t)
);
}
Insert cell
import { legend } from "@d3/color-legend"
Insert cell
countySVG
Insert cell
fips = countySVG ? countySVG.id : ""
Insert cell
eav = eavsByCounty.get(fips)
Insert cell
eav ? diff(eav) : ""
Insert cell
height = 500
Insert cell
pop2016 = demographicsData[2016].get(fips)["B01003_001E"]
Insert cell
pop2018 = demographicsData[2018].get(fips)["B01003_001E"]
Insert cell
format = d3.format(",d")
Insert cell
import {
demographicsData,
selectedFields,
niceLabel,
countyShapes
} from "@enjalot/us-county-datasets"
Insert cell
d3 = require("d3@6")
Insert cell
FileAttachment("keyLables.json").json()
Insert cell
turf = require('https://bundle.run/turf@3.0.14')
Insert cell
import { twitch } from "@codingwithfire/twitch"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more