{
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height)
.attr("viewBox", [0, 0, width, height]);
const counties = svg
.selectAll(".county")
.data(countiesData)
.join("path")
.attr("class", "county")
.attr("d", path)
.style("fill", d => {
const scale = colorScales[selection];
return scale ? scale(wildfireMap.get(d.id) || 0) : "#ccc";
})
.style("stroke", "#000")
.style("cursor", "pointer")
.on("mouseover", function () {
d3.select(this).style("stroke", "#fff").style("stroke-width", 2);
})
.on("mouseout", function () {
d3.select(this).style("stroke", "#000").style("stroke-width", 1);
})
.on("click", function (event, d) {
const wildfireMap = updateWildfireMap(yearFilter, selection);
const countyData = california_county_fips_geoid.find(c => c.GEOID_TIGER == d.id);
const countyName = countyData ? countyData["County Name"] : "Unknown";
const metricValue = wildfireMap.get(d.id) || 0;
console.log(`Clicked on: ${countyName}, ${selection}: ${metricValue}`);
d3.select("#tooltip")
.style("visibility", "visible")
.style("left", event.pageX + "px")
.style("top", event.pageY - 40 + "px")
.html(`<strong>${countyName}</strong><br>${selection}: ${metricValue}`);
});
function updateMap(year, metric) {
const wildfireMap = updateWildfireMap(year, metric);
const scale = colorScales[metric];
if (!scale) {
console.error(`No color scale found for metric: ${metric}`);
return;
}
scale.domain([0, d3.max(californiaWildfireDamage, d => +d[metric] || 0)]);
counties.style("fill", d => scale(wildfireMap.get(d.id) || 0));
}
updateMap(yearFilter, selection);
viewof metricSelection.oninput = () => updateMap(yearFilter, selection);
viewof yearFilter.oninput = () => updateMap(yearFilter, selection);
return svg.node();
}