cityRacers = {
const svg = d3.create("svg").attr("width", width).attr("height", height);
svg
.append("rect")
.attr("x", 0)
.attr("y", 0)
.attr("width", width)
.attr("height", height)
.attr("fill", bgColor);
svg
.append("rect")
.attr("x", width - xMargin)
.attr("y", yMargin)
.attr("width", 8)
.attr("height", height - yMargin * 2)
.attr("fill", "white");
svg
.append("g")
.attr("transform", "translate(" + xMargin + ",0)")
.call(yAxis);
svg
.selectAll(".tick text")
.attr("font-size", "11px")
.attr("fill", "white")
.attr("font-family", "menlo");
svg.selectAll("g line").attr("stroke", "white").attr("stroke-width", 2);
//axis line and outer tick styles
svg.select("g path").attr("stroke", "white").attr("stroke-width", 2);
//data binding to create each circle
svg
.selectAll(".csaDots")
.data(csaData)
.enter()
.append("circle")
.attr("cx", xMargin)
.attr("cy", (d) => yScale(d.shortName))
// .attr("cy", (d, i) => yScaleIndex(i))
.attr("r", 5)
.attr("fill", "white")
.attr("class", "csaDots");
//create svg button and attach event listener for moving dots
svg
.append("rect")
.attr("fill", "orange")
.attr("width", 50)
.attr("height", 20)
.attr("x", width - 60)
.attr("y", 10)
.on("click", () => {
d3.selectAll(".csaDots")
.transition()
.duration((d) => speedScale(d.population))
.ease(d3.easeBounce)
.attr("cx", width - xMargin)
.attr("fill", (d) => d3.interpolateMagma(colorScale(d.population)));
});
//label for the button
svg
.append("text")
.attr("fill", "white")
.attr("x", width - 58)
.attr("y", 22)
.text("Go!")
.style("font-family", "courier")
.style("font-size", 14)
//so the text doesn't get in the way of our button seeing the mouse click...
.attr("pointer-events", "none");
//create svg button and attach event listener for resetting dots
svg
.append("rect")
.attr("fill", "orange")
.attr("cursor", "crosshair")
.attr("width", 50)
.attr("height", 20)
.attr("x", width - 60)
.attr("y", 40)
.on("click", () => {
d3.selectAll(".csaDots")
.transition()
.duration((d) => speedScale(d.population))
.ease(d3.easeBounce)
.attr("cx", xMargin)
.attr("fill", "white");
});
//label for the button
svg
.append("text")
.attr("fill", "white")
.attr("x", width - 58)
.attr("y", 54)
.text("Reset")
.style("font-family", "courier")
.style("font-size", 14)
//so the text doesn't get in the way of our button seeing the mouse click...
.attr("pointer-events", "none");
return svg.node();
}