Public
Edited
May 12, 2023
Insert cell
md`# Isarithmic Mapping: GEOG 3540
Isarithmic Mapping of Yearly Total Precipitation, Source: [The Iowa Environmental Mesonet (IEM)] https://mesonet.agron.iastate.edu/climodat`
Insert cell
{
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
yield svg.node();
svg.append("g").call(legend);
// svg.append("g")
// .attr("transform", "translate(360,20)")
// .append(() => legend({color, title: "Yearly Avg Precipitation in 2018", width: 260}));
svg.append("g")
.selectAll("path")
.data(isarithmicPolygons.features)
.join("path")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("fill", d => color(d.properties.range))
.attr("d", path)
.append("title")
.text(d => " Avg yearly precipitation: " + d.properties.range);
svg.append("g")
.selectAll("path")
.data(isarithmicPolygons.features)
.join("path")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("fill", d => color(d.properties.range))
.attr("d", path)
.append("title")
.text(d => " Avg yearly precipitation: " + d.properties.range);

svg.append("g")
.selectAll("path")
.data(counties.features)
.join("path")
.attr("stroke", "gray")
.attr("stroke-linejoin", "round")
.attr("fill", d => "none")
.attr("d", path);
return svg.node();
}
Insert cell
d3 = require("d3@5", "d3-svg-legend@2")
Insert cell
function unique(array) {
return array.filter((v, i) => array.indexOf(v) === i);
}
Insert cell
format = d => `${d}%`
Insert cell
topojson = require("topojson-client@3")
Insert cell
featureCollection = FileAttachment("prec2018_wgs84.json").json()
Insert cell
isarithmicPolygons = topojson.feature(featureCollection, featureCollection.objects.prec2018_wgs84)
Insert cell
polygonValues = {
const values = []
for (let i = 0; i < isarithmicPolygons.features.length; i++) {
let d = isarithmicPolygons.features[i];
values[i] = d.properties.range;
}
return values;
}
Insert cell
uniqueValues = unique(polygonValues.sort())
Insert cell
//load iowa counties reference dataset
iowa = FileAttachment("iowa_counties_topo@1.json").json()
Insert cell
counties = topojson.feature(iowa, iowa.objects.iowa_counties)
Insert cell
projection_counties = d3.geoTransverseMercator().rotate([94,0]).fitExtent([[80, 80], [width, height]], counties);
Insert cell
path = d3.geoPath().projection(projection_counties);
Insert cell
colors = d3.quantize(d3.interpolateHcl("#fafa6e", "#2A4858"), uniqueValues.length)
Insert cell
color = d3.scaleOrdinal(polygonValues.sort(), colors)
Insert cell
margin = 20
Insert cell
width = 975
Insert cell
height = 610
Insert cell
legend = d3.legendColor()
.shapeWidth(110)
.orient("horizontal")
.scale(x)
// .title("Avg yearly precipitation in 2018")
Insert cell
x = d3.scaleOrdinal(legendValues, colors)
Insert cell
legendValues = {
const values = []
for (let i = 0; i < uniqueValues.length; i++) {
let d = uniqueValues[i];
let d2 = d.split(" - ")
let startVal = Math.round(d2[0] * 100) / 100
let endVal = Math.round(d2[1] * 100) / 100
if(i > 0)
startVal += 0.01
startVal = Math.round(startVal * 100) / 100
values[i] = startVal + " - " + endVal
}
return values;
}
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