temp_chart = {
var content = html`
<div id="chart_temp_container">
</div>`;
yield content;
var margin = { top: 60, right: 30, bottom: 120, left: 40 };
var gridSizeDay = Math.floor(width / days.length) * 1.2;
var gridSizeYear = Math.floor(width / days.length) * 4;
var height = gridSizeYear * years.length;
var maingroup = d3
.select('#chart_temp_container')
.append("svg")
.attr("class", "svg")
.attr("width", 1600 + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var yearsLabels = maingroup
.selectAll(".yearsLabel")
.data(years)
.enter()
.append("text")
.attr("font-size", 12)
.text(function(d) {
return d % 5 == 0 ? d : "";
})
.attr("x", 0)
.attr("y", function(d, i) {
return i * gridSizeYear;
})
.attr("transform", "translate(-4," + gridSizeYear / 2 + ")")
.style("text-anchor", "end");
// ====================================== LABEL MONTH ================================
var monthsLabels = maingroup
.selectAll(".monthLabel")
.data(days)
.enter()
.append("text")
.attr("class", "textmonthLabel")
.text(function(d) {
return +d % 30 == 0 ? monthName(d) : "";
})
.attr("x", function(d, i) {
return (i - 5) * gridSizeDay;
})
.attr("font-size", 10)
.attr("y", 0)
.attr("transform", "translate(" + gridSizeDay / 2 + ", -6)")
.style("text-anchor", "end");
var monthBar = maingroup
.selectAll(".monthBar")
.data([31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365])
.enter()
.append("line")
.attr("x1", function(d) {
return d * gridSizeDay;
})
.attr("y1", 0)
.attr("x2", function(d) {
return d * gridSizeDay;
})
.attr("y1", -10)
.style("stroke", "blue")
.style("stroke-opacity", 1)
.style("fill", "blue");
//================================ TEXTE===========================================
maingroup
.append("text")
.attr("class", "credit")
.attr("x", 0)
.attr("y", gridSizeYear * (years.length + 1) + 15)
.style("text-anchor", "start")
.attr("font-size", 10)
.text(
"Basé sur les données de la NOAA (National Oceanic and Atmosphéric Administration - USA)"
);
maingroup
.append("text")
.attr("class", "title")
.attr("x", width / 2)
.attr("y", -45)
.style("text-anchor", "middle")
.text(
name +
" - Températures journalières minimales de " +
minDate +
" à " +
maxDate
);
maingroup
.append("text")
.attr("class", "subtitle")
.attr("x", width / 2)
.attr("y", -25)
.attr("font-size", 12)
.style("text-anchor", "middle")
.text("(" + data_temp_filter.length + " mesures)");
//================================ HEATMAP ========================================
var heatMap = maingroup
.selectAll(".hour")
.data(data_temp_filter)
.enter()
.append("rect")
.attr("x", function(d) {
return d.dayYear * gridSizeDay;
})
.attr("y", function(d) {
return (d.year - 1958) * gridSizeYear;
})
.attr("width", gridSizeDay)
.attr("height", gridSizeYear)
.style("stroke", "none")
.style("stroke-opacity", 0)
.style("fill", function(d) {
return colorScale(d.TMIN);
})
.append("title")
.text(function(d) {
return "date : " + d.date + "\nTempérature : " + d.TMIN + " °C";
});
//==================================== LEGEND ===========================================
var legendSize = 5;
var legendMap = maingroup
.selectAll(".legend")
.data(d3.range(minScale, maxScale + 1, 1))
.enter()
.append("rect")
.attr("x", function(d) {
return width / 2.5 + d * legendSize * gridSizeDay;
})
.attr("y", gridSizeYear * (years.length + 1) + 50)
.attr("width", gridSizeDay * legendSize)
.attr("height", gridSizeYear * 2)
.style("stroke", "none")
.style("stroke-opacity", 0)
.style("fill", function(d) {
return colorScale(d);
});
maingroup
.append("text")
.attr("class", "legendTitle")
.attr("x", width / 2)
.attr("y", gridSizeYear * years.length + 50)
.attr("font-size", 14)
.style("text-anchor", "middle")
.text("Echelle des températures");
var legenLabels = maingroup
.selectAll(".legendLabel")
.data(d3.range(minScale, maxScale + 1, 1))
.enter()
.append("text")
.attr("font-size", 10)
.text(function(d) {
return d % 5 == 0 ? d : "";
})
.attr("x", function(d) {
return (
width / 2.5 + legendSize * gridSizeDay + d * legendSize * gridSizeDay
);
})
.attr("y", gridSizeYear * (years.length + 1) + 80)
.attr("transform", "translate(-4," + gridSizeYear / 2 + ")")
.attr("font-size", 10)
.style("text-anchor", "middle");
return svg;
}