chart = {
const svg = d3.create("svg")
.attr("viewBox", [-width / 2, -height / 2, width, height])
.style("padding-top", `${margin.top}px`);
svg.append("g")
.attr("class", "temp")
.selectAll("path")
.data(data)
.join("path")
.attr("opacity", 1)
.attr("data-state", d => `${d.state}`)
.attr("fill", (d,i) => "#7f8c8d")
.attr("stroke", "#fff")
.attr("stroke-width", 2)
.attr("d", (d,i) => arc(d,i,1,"sept2019"))
.on("mousemove", mousemove)
.on("mouseleave", mouseleave)
svg.append("g")
.selectAll("path")
.data(data)
.join("path")
.attr("opacity", 1)
.attr("data-state", d => `${d.state}`)
.attr("fill", "#d35400")
.attr("stroke", "#fff")
.attr("stroke-width", 2)
.attr("d", (d,i) => arc(d,i,-1,"sept2020"))
.on("mousemove", mousemove)
.on("mouseleave", mouseleave)
const states = svg.append("g")
.attr("transform", `translate(-${width/2 - margin.left} -${height/2})`)
.attr("font-size", 10)
.selectAll("text")
.data(data)
.join("text")
.attr("class", "state")
.attr("data-state", d => `${d.state}`)
.attr("opacity", 1)
.attr("y", (d,i) => legendScale(data.length - i))
.text(d => d.state + " +" + d.change + " pts")
.on("mousemove", mousemove)
.on("mouseleave", mouseleave)
const yearHeader = svg.append("g")
.attr("font-size", 25)
.attr("font-weight", "bold")
.attr("transform", `translate(-${width/2} -${height/2 - margin.top})`)
yearHeader
.append("text")
.attr("fill", "#7f8c8d")
.attr("x", width/2 - 60)
.text("2019")
yearHeader
.append("text")
.attr("fill", "#d35400")
.attr("x", width/2 + 5)
.text("2020")
svg.append("g")
.call(yAxis)
d3.selectAll("label").on("click", function() {
activateBtn(this)
});
if (window.innerWidth > 740) { return svg.node() }
else { return md`**Unfortunately, I couldn't make the viz responsive...**` }
}