chart_1 = {
const margin = { top: 30, right: 10, bottom: 120, left: 115};
const cellHeight = 20;
const cellWidth = 2.7;
const paddingY = 5;
const countries = Array.from(new Set(data.map(d => d.country)));
const months = Array.from(new Set(data.map(d => +d.Month))).sort(d3.ascending);
const everySeventhMonth= months.filter((_, index) => index % 7 === 0);
const chartWidth = months.length * cellWidth + margin.left + margin.right;
const chartHeight = countries.length * (cellHeight + paddingY) + margin.top + margin.bottom;
const color = d3.scaleSequential()
.domain(d3.extent(data, d => d.mean_SD))
.interpolator(d3.interpolateBlues);
const xScale = d3.scaleTime()
.domain(d3.extent(data, d => d.Month))
.range([margin.left, chartWidth - margin.right]);
const svg = d3.create("svg")
.attr("width", chartWidth)
.attr("height", chartHeight);
const yScale = d3.scaleBand()
.domain(countries)
.range([margin.top, chartHeight - margin.bottom])
.padding(0.1);
svg.append("text")
.attr("x", chartWidth / 2)
.attr("y", margin.top / 2)
.attr("text-anchor", "middle")
.attr("font-size", 16)
.attr("font-weight", "bold")
.text("Average Snow Levels by Country (2000–2025)");
svg.append("g")
.selectAll("g")
.data(countries)
.join("g")
.attr("transform", d => `translate(0, ${yScale(d)})`)
.each(function (country) {
const countryData = data.filter(d => d.country === country);
d3.select(this)
.selectAll("rect")
.data(countryData)
.join("rect")
.attr("x", d => xScale(d.Month))
.attr("y", 0)
.attr("width", cellWidth)
.attr("height", yScale.bandwidth())
.attr("fill", d => color(d.mean_SD))
d3.select(this)
.append("text")
.attr("x", margin.left - 10)
.attr("y", yScale.bandwidth() / 2)
.attr("text-anchor", "end")
.attr("font-size", 12)
.text(country);
});
const xAxis = d3.axisBottom(xScale)
.tickValues(everySeventhMonth)
.tickFormat(d3.timeFormat("%b %Y"));
svg.append("g")
.attr("class", "x-axis")
.attr("transform", `translate(0,${chartHeight - margin.bottom})`)
.call(xAxis)
.selectAll("text")
.style("font-weight", "normal !important")
.attr("transform", "rotate(-60)")
.style("text-anchor", "end")
.attr("dx", "-0.5em")
.attr("dy", "0.1em");
svg.append("text")
.attr("x", chartWidth / 2)
.attr("y", chartHeight - margin.bottom + 90)
.attr("text-anchor", "middle")
.attr("font-size", 12)
.attr("fill", "black")
.text("Link to the data source: https://www.ecmwf.int/");
return svg.node();
}