Published
Edited
Apr 9, 2020
Fork of Assignment 3
1 fork
Insert cell
md`# Assignment 3`
Insert cell
d3 = require("d3@5")
Insert cell
topojson = require("topojson-client@3")
Insert cell
basepolygons = FileAttachment("iowa_counties_wgs84.json").json()
Insert cell
basefeatures = topojson.feature(basepolygons, basepolygons.objects.iowa_counties_wgs84)
Insert cell
points = FileAttachment("State_of_Iowa_Forfeiture_Cases-point.json").json()
Insert cell
csv_data = d3.csvParse(await FileAttachment("State_of_Iowa_Forfeiture_Cases.csv").text(),({FIPS, Total_Money}) => [FIPS,+Total_Money])
Insert cell
data = Object.assign(new Map(csv_data))
Insert cell
data.get("19043")
Insert cell
radius = d3.scaleSqrt([0, d3.max([...data.values()])], [0, 20])
Insert cell
radius(710)
Insert cell
d3.max([...data.values()])
Insert cell
format = d3.format(".2s")
Insert cell
projection = d3.geoTransverseMercator().rotate([94,0]).fitExtent([[80, 80], [width, height]], basefeatures);
Insert cell
path_basemap = d3.geoPath().projection(projection)
Insert cell
path_points = d3.geoPath().projection(projection)
Insert cell
width = 975
Insert cell
height = 610
Insert cell
title = "Total_Money_Forfeiture"
Insert cell
text = (d => "Total_Money" + data.get(+d.properties.FIPS)[1])
Insert cell
proportionalSymbols = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
svg.append("path")
.datum(topojson.feature(basepolygons, basepolygons.objects.iowa_counties_wgs84))
.attr("fill", "#a6cee3")
.attr("d", path_basemap);
svg.append("path")
.datum(topojson.mesh(basepolygons, basepolygons.objects.iowa_counties_wgs84, (a, b) => a !== b))
.attr("fill", "#a6cee3")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("d", path_basemap);
svg.append("text")
.text(title)
.attr("font", "serif")
.attr ("fill","#1f78b4")
.attr ("font-size", "55px")
.attr("transform", "translate( 105, 50 )")
;
const legend = svg.append("g")
.attr("fill", "#777")
.attr("transform", "translate(100,500)")
.attr("text-anchor", "middle")
.style("font", "10px sans-serif")
.selectAll("g")
.data([1.4e7, d3.max([...data.values()])])
.join("g");
legend.append("circle")
.attr("fill", "none")
.attr("fill-opacity", 0.5)
.sort((a, b) => b.value - a.value)
.attr("stroke", "#1f78b4")
.attr("cy", d => -radius(d))
.attr("r", radius);
legend.append("text")
.attr("y", d => (2 * -radius(d))-20)
.attr("dy", "1.3em")
.text(format)
.text(function(d) {return format(d) + " Dollars"})
;
legend.append("text")
.text("Dollars")
.attr ("font", "20px sans-serif")
.attr ("dy", "1.5em" )
;
svg.append("g")
.attr("fill", "#1f78b4")
.attr("fill-opacity", 0.5)
.attr("stroke", "#1f78b4")
.attr("stroke-width", .5)
.selectAll("circle")
.data(points.features
.map(d => (d.value = data.get(d.properties.FIPS), d))
.sort((a, b) => b.value - a.value))
.join("circle")
.attr("transform", d => `translate(${path_points.centroid(d)})`)
.attr("r", d => radius(data.get(d.properties.FIPS)))
.append("title")
.text(d => `${d.properties.FIPS} ƒ: ${format(d.value)}`);
return svg.node();
}
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