chartSelect = () => {
const marginTop = 13;
const svg = d3.create("svg")
.attr("width", chartwidth + margin.left + margin.right)
.attr("height", bandheight + marginTop + margin.bottom);
svg.append("style").html(css);
const g = svg.append("g")
.attr("transform", `translate(${[margin.left, marginTop]})`);
g.append("g")
.attr("opacity", selected.sf_1964_1993 ? 1 : 0)
.call(g => xaxisGenerator(g, bandheight));
const yaxis = g.append("g").attr("class", "axis y-axis");
const yaxisTick = yaxis.append("g").attr("class", "tick")
.attr("transform", `translate(0, ${y.bandwidth() / 2})`);
yaxisTick.append("line")
.attr("opacity", selected.sf_1964_1993 ? 1 : 0)
.attr("x2", chartwidth);
yaxisTick.append("text")
.attr("dy", "0.32em")
.attr("x", -margin.left)
.html(`<tspan style="font-weight: bold">${selected.label}</tspan>${selected.sf_1964_1993 ? "" : " has insufficient snowfall data to calculate a trend."}`);
const city = g.selectAll(".city")
.data([selected])
.join("g")
.attr("class", "city")
.attr("opacity", selected.sf_1964_1993 ? 1 : 0)
.attr("transform", d => `translate(0, ${y.bandwidth() / 2})`);
const cityLine = city.append("line")
.attr("x1", d => x(d.sf_1964_1993))
.attr("x2", d => x(d.sf_1994_2023))
.attr("stroke", d => colorScale(d.sf_change))
.attr("stroke-width", 6);
const cityCircleStart = city.append("circle")
.attr("cx", d => x(d.sf_1964_1993))
.attr("fill", "#fff")
.attr("stroke", "#888")
.attr("r", r);
const cityCircleEnd = city.append("circle")
.attr("cx", d => x(d.sf_1994_2023))
.attr("fill", d => colorScale(d.sf_change))
.attr("stroke", d => d3.color(colorScale(d.sf_change)).darker(1))
.attr("r", r);
const cityLabelStart = city.append("text")
.attr("class", "city-label")
.attr("dx", d => (r + 4) * (d.sf_change < 0 ? 1 : -1))
.attr("dy", "0.32em")
.attr("text-anchor", d => d.sf_change < 0 ? "start" : "end")
.attr("x", d => x(d.sf_1964_1993))
.attr("y", -18)
.text("1964-1993");
const cityLabelEnd = city.append("text")
.attr("class", "city-label")
.attr("dx", d => (r + 4) * (d.sf_change < 0 ? -1 : 1))
.attr("dy", "0.32em")
.attr("text-anchor", d => d.sf_change < 0 ? "end" : "start")
.attr("x", d => x(d.sf_1994_2023))
.attr("y", -18)
.text("1994-2023");
const cityInchesStart = city.append("text")
.attr("class", "county-inches county-inches-start")
.attr("dx", d => (r + 4) * (d.sf_change < 0 ? 1 : -1))
.attr("dy", "0.32em")
.attr("text-anchor", d => d.sf_change < 0 ? "start" : "end")
.attr("x", d => x(d.sf_1964_1993))
.text(d => `${Math.round(d.sf_1964_1993)} inches`);
const cityInchesEnd = city.append("text")
.attr("class", "county-inches county-inches-end")
.attr("dx", d => (r + 4) * (d.sf_change < 0 ? -1 : 1))
.attr("dy", "0.32em")
.attr("text-anchor", d => d.sf_change < 0 ? "end" : "start")
.attr("x", d => x(d.sf_1994_2023))
.text(d => `${Math.round(d.sf_1994_2023)} inches`);
return svg.node()
}