{
let currMonth = 0;
d3.selectAll("rect").remove();
d3.selectAll("text").remove();
d3.select("#canvas")
.selectAll("rect")
.data(data)
.enter()
.append("rect")
.attr("y", (d) => yScale(d.week_start))
.attr("x", (d) => width / 2 - xScale(d.strength_before) / 2)
.attr("width", (d) => xScale(d.strength_before))
.attr("height", (d) => xScale(d.strength_before) / 1.8)
.attr("fill", "#A4B3A1")
.attr("fill-opacity", 0.8)
.attr("stroke", "#fff");
d3.select("#canvas")
.selectAll("text")
.data(data)
.enter()
.append("text")
.attr("y", (d) => yScale(d.week_start) + 15)
.attr("x", (d) => width / 2 - xScale(d.strength_before) / 2 + 5)
.attr("fill", (d) => {
if (currMonth != d.week_start.getMonth()) {
currMonth = d.week_start.getMonth();
return "#fff";
} else {
return "rgba(0, 0, 0, 0)";
currMonth = d.week_start.getMonth();
}
})
.attr("font-family", "GT America")
.attr("font-size", 14)
.text(
(d) =>
monthNames[d.week_start.getMonth()] +
" " +
(d.week_start.getYear() - 100)
);
}