|
143 | 143 | postsByDate.set(date, data);
|
144 | 144 | {{- end -}}
|
145 | 145 |
|
| 146 | + years = Array.from(years).sort().reverse(); |
146 | 147 | return [postsByDate, years];
|
147 | 148 | }
|
148 | 149 |
|
|
162 | 163 | myChart.setOption(option);
|
163 | 164 | }
|
164 | 165 |
|
| 166 | + function renderYearSelector(years){ |
| 167 | + // Populate year selector |
| 168 | + var yearSelector = document.getElementById('yearSelector'); |
| 169 | + years.forEach(year => { |
| 170 | + var option = document.createElement('option'); |
| 171 | + option.value = year; |
| 172 | + option.text = year; |
| 173 | + yearSelector.appendChild(option); |
| 174 | + }); |
| 175 | + |
| 176 | + yearSelector.addEventListener('change', function() { |
| 177 | + updateHeatmap(this.value); |
| 178 | + }); |
| 179 | + } |
| 180 | + |
165 | 181 |
|
166 | 182 | // Watch for theme changes
|
167 | 183 | const observer = new MutationObserver((mutations) => {
|
|
179 | 195 | });
|
180 | 196 |
|
181 | 197 | var option;
|
182 |
| - //var postsByDate = new Map(); |
183 |
| - //var years = new Set(); |
184 |
| - var [postsByDate, years] = populatePostData(); |
185 |
| - |
186 |
| - // Populate year selector |
187 |
| - years = Array.from(years).sort().reverse(); |
188 |
| - var yearSelector = document.getElementById('yearSelector'); |
189 |
| - years.forEach(year => { |
190 |
| - var option = document.createElement('option'); |
191 |
| - option.value = year; |
192 |
| - option.text = year; |
193 |
| - yearSelector.appendChild(option); |
194 |
| - }); |
195 |
| - |
196 |
| - yearSelector.addEventListener('change', function() { |
197 |
| - updateHeatmap(this.value); |
198 |
| - }); |
| 198 | + const [postsByDate, years] = populatePostData(); |
| 199 | + const latestYear = years && years.length > 0 ? years[0]: new Date().getFullYear(); |
199 | 200 |
|
200 | 201 | option = {
|
201 | 202 | title: { show: false },
|
|
259 | 260 | type: 'heatmap',
|
260 | 261 | coordinateSystem: 'calendar',
|
261 | 262 | calendarIndex: 0,
|
262 |
| - data: getHeatmapData(years[0]) |
| 263 | + data: getHeatmapData(latestYear) |
263 | 264 | }
|
264 | 265 | };
|
265 | 266 |
|
| 267 | + renderYearSelector(years); |
| 268 | + |
266 | 269 | // Initial chart initialization
|
267 | 270 | initOrUpdateChart();
|
268 | 271 | </script>
|
|
0 commit comments