{
let w = d3.min([1100, width]);
let h = 0.625 * w;
let projection = d3
.geoConicEqualArea()
.parallels([34.333, 36.1666])
.rotate([79, 0])
.fitSize([w - 10, h], geo_data.boundary);
let path = d3.geoPath().projection(projection);
let div = d3.create("div").style("width", `${w}px`).style("height", `${h}px`);
let svg = div.append("svg").attr("width", w).attr("height", h);
let map = svg.append("g").attr("id", "map");
let base_layer = map.append("g").attr("id", "base_layer");
let color_scale;
if (group == "African American" || group == "White" || group == "Hispanic") {
color_scale = d3
.scaleLinear()
.interpolate(() => d3.interpolateBlues)
.domain([0, 1]);
} else if (group == "Asian") {
color_scale = d3
.scaleThreshold()
.domain([0.0000001, 0.05, 0.1])
.range(d3.schemeBlues[6].slice(0, 4));
} else if (group == "Indigenous American") {
color_scale = d3
.scaleThreshold()
.domain([0.0000001, 0.02])
.range(d3.schemeBlues[6].slice(0, 3));
}
base_layer
.selectAll("path")
.data(geo_data.blockgroups.features)
.join("path")
.attr("d", path)
.attr("fill", (d) =>
color_scale(
grouped_racial_data.get(d.properties.GEOID)["B02001_001E"] / 6200
)
)
.attr("data-geoid", (d) => d.properties.GEOID)
.attr("stroke", "black")
.attr("stroke-width", 0.3)
.append("title")
.text((d) =>
d3.format("D")(grouped_racial_data.get(d.properties.GEOID)["B02001_001E"])
);
let road_group = map.append("g").attr("class", "roads").attr("opacity", 1);
road_group
.append("g")
.selectAll("path.road")
.data(geo_data.roads.features)
.join("path")
.attr("class", "road context")
.attr("fill", "none")
.attr("stroke", "#000")
.attr("stroke-width", 2.5)
.attr("stroke-linejoin", "round")
.attr("d", path)
.style("pointer-events", "none");
road_group
.append("g")
.selectAll("path.road")
.data(geo_data.roads.features)
.join("path")
.attr("class", "road context")
.attr("fill", "none")
.attr("stroke", "#ddd")
.attr("stroke-width", 1.5)
.attr("stroke-linejoin", "round")
.attr("d", path)
.style("pointer-events", "none");
svg
.append("path")
.attr("d", path(geo_data.boundary.features[0]))
.attr("stroke", "black")
.attr("stroke-width", 3)
.attr("fill", "none");
let city_name_display = map
.append("g")
.attr("class", "towns")
.attr("opacity", 1);
city_name_display
.selectAll("text.city")
.data(towns)
.join("text")
.attr("class", "city context")
.attr("x", (d) => projection([d.lon, d.lat])[0])
.attr("y", (d) => projection([d.lon, d.lat])[1])
.attr("dx", (o) => (o.name == "Sandy Mush" ? 60 : 0))
.attr("opacity", 1)
.text((o) => o.name)
.style("font-family", "sans-serif")
.attr("font-size", 14)
.attr("pointer-events", "none")
.attr("text-anchor", "middle")
.attr("fill", group == "White" ? "white" : "black");
div.node().color_scale = color_scale;
return div.node();
}