Published
Edited
Apr 1, 2020
1 fork
Insert cell
md`# Proportional Symbol Mapping Geoviz Assignment 3`
Insert cell
proportionalSymbols = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
svg.append("path")
.datum(topojson.feature(counties, counties.objects.county))
.attr("fill", "gray")
.attr("d", path_basemap);
svg.append("path")
.datum(topojson.mesh(counties, counties.objects.county, (a, b) => a !== b))
.attr("fill", "none")
.attr("stroke", "none")
.attr("stroke-linejoin", "round")
.attr("d", path_basemap);
const legend = svg.append("g")
.attr("fill", "#777")
.attr("transform", "translate(700,450)")
.attr("text-anchor", "middle")
.style("font", "10px sans-serif")
.selectAll("g")
.data([1e6, d3.max([...data.values()])])
.join("g");
legend.append("circle")
.attr("fill", "none")
.attr("stroke", "#ccc")
.attr("cy", d => -radius(d))
.attr("r", radius);
legend.append("text")
.attr("y", d => -2 * radius(d))
.attr("dy", "1.3em")
.text(format);
svg.append("g")
.attr("fill", "#7a0177")
.attr("fill-opacity", 0.5)
.attr("stroke", "#f768a1")
.attr("stroke-width", 0.5)
.selectAll("circle")
.data(LandfillPoints.features
.map(d => (d.value = data.get(d.properties.LFID), 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.LFID)))
.append("title")
.text(d => `${d.properties.LFID} : ${format(d.value)}`);
return svg.node();
}
Insert cell
height = 610
Insert cell
width = 975
Insert cell
path_points = d3.geoPath().projection(projection)
Insert cell
path_basemap = d3.geoPath().projection(projection)
Insert cell
projection = d3.geoAlbersUsa()

Insert cell
format = d3.format(".2s")
Insert cell
d3.max([...data.values()])
Insert cell
radius(1911803)
Insert cell
//proportional symbols
radius = d3.scaleSqrt([0, d3.max([...data.values()])], [0, 20])
Insert cell
data.get(614)
Insert cell
data = Object.assign(new Map(csv_data))
Insert cell
csv_data = d3.csvParse(await FileAttachment("IowaLandfills.csv").text(),({LFID, WasteInPlace}) => [+LFID, +WasteInPlace])
Insert cell
//import the point data (geojson)
LandfillPoints = FileAttachment("LandfillPoints2.json").json()
Insert cell
//import the polygon base map data
counties = FileAttachment("county.json").json()
Insert cell
simple = require("simple-statistics@7.0.7/dist/simple-statistics.min.js")
Insert cell
topojson = require("topojson-client@3")
Insert cell
d3 = require("d3@5")
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