chart = {
const years = d3.nest()
.key(d => d.date.getUTCFullYear())
.entries(data)
.reverse();
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height * years.length])
.attr("font-family", "sans-serif")
.attr("font-size", 10);
const year = svg.selectAll("g")
.data(years)
.join("g")
.attr("transform", (d, i) => `translate(0,${height * i + cellSize * 1.5})`);
const day = year.append("g")
.selectAll("rect")
.data(d => d3.utcDays(d3.utcMonth(d.values[0].date), d3.utcMonth.ceil(d.values[d.values.length - 1].date)))
.join("rect")
.attr("width", cellSize - 1)
.attr("height", cellSize - 1)
.attr("x", d => dayPositionX(d))
.attr("y", d => d3.utcMonday.count(d3.utcMonth(d), d) * cellSize + 0.5)
.attr("fill", d => color2(d));
const dayNumber = year.append("g")
.selectAll("g")
.data(d => d3.utcDays(d3.utcMonth(d.values[0].date), d3.utcMonth.ceil(d.values[d.values.length - 1].date)))
.join("g");
dayNumber.append('text')
.attr("class", "subdomain-text")
.attr("x", d => dayPositionX(d) + cellSize / 2)
.attr("y", d => d3.utcMonday.count(d3.utcMonth(d), d) * cellSize + 0.5 + cellSize / 2)
.attr("text-anchor", "middle")
.attr("dominant-baseline", "central")
.text(d => formatDay(d));
const month = year.append("g")
.selectAll("g")
.data(d => d3.utcMonths(d3.utcMonth(d.values[0].date), d.values[d.values.length - 1].date))
.join("g");
month.append("text")
.attr("x", d => countMonth(d) * cellSize * 7 + countMonth(d) * monthPadding)
.attr("y", -5)
.text(formatMonth);
return svg.node();
}