chart = {
const mes = d3.select("#calendar").selectAll("svg")
.data(months)
.enter().append("svg")
.attr("class", "month")
.attr("width", (cellSize * 7) + (cellMargin * 8) )
.attr("height", 170)
.append("g")
mes.append("text")
.attr("class", "month-name")
.attr("x", ((cellSize * 7) + (cellMargin * 8)) / 2 )
.attr("y", 15)
.attr("text-anchor", "middle")
.text(function(d) { return monthName(d); })
mes.selectAll(".weekday-name").data(diaSemana)
.enter()
.append("text")
.attr("class", "weekday-name")
.attr("x", (d,i) => (i * cellSize) + (i * cellMargin) + cellMargin + (cellSize/2))
.attr("y", 30)
.attr("text-anchor", "middle")
.text(d => d)
const rect = mes.selectAll("rect.day")
.data(function(d, i) {
return d3.timeDays(d, new Date(d.getFullYear(), d.getMonth()+1, 1));
})
.enter().append("rect")
.attr("class", "day")
.attr("width", cellSize)
.attr("height", cellSize)
.attr("rx", 3).attr("ry", 3) // rounded corners
.attr("fill", '#e4e4e4') // default light grey fill
.attr("x", function(d) {
return (day(d) * cellSize) + (day(d) * cellMargin) + cellMargin;
})
.attr("y", function(d) {
return ((week(d) - week(new Date(d.getFullYear(),d.getMonth(),1))) * cellSize) +
((week(d) - week(new Date(d.getFullYear(),d.getMonth(),1))) * cellMargin) +
cellMargin + 30;
})
.on("mouseover", function(d) {
d3.select(this).classed('hover', true);
})
.on("mouseout", function(d) {
d3.select(this).classed('hover', false);
})
.datum(format);
// rect.append("title")
// .text(function(d) { return titleFormat(new Date(d)); });
mes.selectAll(".diaLabel")
.data(function(d, i) {
return d3.timeDays(d, new Date(d.getFullYear(), d.getMonth()+1, 1));
})
.enter().append("text")
.text(d => diaMes(new Date(d)))
.attr("class", "diaLabel")
.attr("x", function(d) {
return (day(d) * cellSize) + (day(d) * cellMargin + (cellSize / 1.8));
})
.attr("y", function(d) {
return ((week(d) - week(new Date(d.getFullYear(),d.getMonth(),1))) * cellSize) +
((week(d) - week(new Date(d.getFullYear(),d.getMonth(),1))) * cellMargin) +
cellMargin + 44;
})
rect.filter((d) => { return d in lookup; })
.style("fill", d => {
let i;
for (i = 0; i < data.length; i++) {
if (data[i].today == d){
return cor(data[i].categoria)}
}})
.classed("clickable", true)
.on("click", function(d){
if(d3.select(this).classed('focus')){
d3.select(this).classed('focus', false);
} else {
d3.select(this).classed('focus', true)
}
// funçãoAçãoEtc();
})
//return svg.node();
}