Published unlisted
Edited
Oct 7, 2019
Insert cell
Insert cell
Insert cell
Changed in fork
chart = { const svg = d3.create("svg").attr("viewBox", [0, 0, 900, 610]); svg .append("g") .attr("transform", "translate(610,20)") .append(() => legend({ color: prevScale, title: 'Prev. of Obesity (%)', width: 260 }) ); svg .append("g") .selectAll("path") .data(topojson.feature(TJHD_ZCTAs, TJHD_ZCTAs.objects.TJHD_ZCTAs).features) .join("path") .attr('stroke', '#404040')
+
.attr('fill', 'white')
.attr("d", path) .attr("class", "ZCTA")
-
.append("title") .text( d => `${d.properties.ZCTA5CE10}: ${prev_by_ZCTA.get( d.properties.ZCTA5CE10 ) || '-'}\%` );
+
.append("title");
return svg.node(); }
Insert cell
Changed in fork
d3
+
.select(chart)
.selectAll('.ZCTA') .transition() .attr( "fill", d => prevScale(prev_by_ZCTA.get(d.properties.ZCTA5CE10)) || "white" )
-
.duration(2000)
+
.select("title") .text( d => `${d.properties.ZCTA5CE10}: ${prev_by_ZCTA.get( d.properties.ZCTA5CE10 ) || '-'}\%` )
Insert cell
projection = d3
.geoMercator()
.center([1.6, 37.95])
.rotate([80, 0])
.scale(21000)
.translate([900 / 2, 610 / 2])
Insert cell
path = d3.geoPath().projection(projection)
Insert cell
TJHD_ZCTAs = d3.json("https://api.myjson.com/bins/jidjj")
Insert cell
data = d3.csv("https://gist.githubusercontent.com/bjl2n/fe28782b53917eb9aabe7f279d5e0eea/raw")
Insert cell
prev_by_ZCTA = new Map(data.map(d => [d.ZCTA, +d3.format(".1f")(d[classification] * 100)]))
Insert cell
prevScale = d3.scaleThreshold(
[15, 25, 35, 45],
['#fef0d9', '#fdcc8a', '#fc8d59', '#e34a33', '#b30000']
)
Insert cell
topojson = require("topojson-client@3")
Insert cell
d3 = require("d3@5")
Insert cell
import { legend } from "@d3/color-legend"
Insert cell
import { select } from "@jashkenas/inputs"
Insert cell