diff --git a/dev-info/index.html b/dev-info/index.html index c844c37..1848a67 100644 --- a/dev-info/index.html +++ b/dev-info/index.html @@ -142,6 +142,6 @@ - + \ No newline at end of file diff --git a/hardware-info/index.html b/hardware-info/index.html index 6984f03..b57eddb 100644 --- a/hardware-info/index.html +++ b/hardware-info/index.html @@ -238,6 +238,5 @@ - \ No newline at end of file diff --git a/index.html b/index.html index 0e5b340..0697480 100644 --- a/index.html +++ b/index.html @@ -123,6 +123,4 @@ - - \ No newline at end of file diff --git a/js/heatmap.js b/js/heatmap.js index b09569b..414075e 100644 --- a/js/heatmap.js +++ b/js/heatmap.js @@ -1,7 +1,7 @@ (function (global) { "use strict"; - /* ---- core logic (unchanged from the working version) ---- */ + /* ---- core logic ---- */ function sundayOf(date) { const sunday = new Date(date); sunday.setUTCDate(sunday.getUTCDate() - sunday.getUTCDay()); @@ -28,6 +28,19 @@ } return week; } + // The current week is truncated to "today" (per the viewer's clock) so future + // cells don't render. But the data source has its own clock; if it reports a + // contribution dated later in the current week than the viewer's clock thinks + // "now" is, that day's index lands past the truncated array. Grow the week to + // fit any real data point instead of writing off the end (week[idx] undefined). + function ensureDay(week, idx) { + while (week.length <= idx) { + const date = new Date(week[0].date + "T00:00:00Z"); + date.setUTCDate(date.getUTCDate() + week.length); + week.push({ sources: {}, contributions: 0, date: date.toISOString().slice(0, 10) }); + } + return week[idx]; + } function buildHeatmapData(sources) { const weeks = new Map(); for (const sourceName of Object.keys(sources)) { @@ -39,9 +52,10 @@ if (day.contributions > 0) { const week = weeks.get(key); const idx = new Date(day.timestamp * 1000).getUTCDay(); - week[idx].contributions += day.contributions; - if (!week[idx].sources[sourceName]) week[idx].sources[sourceName] = 0; - week[idx].sources[sourceName] += day.contributions; + const cell = ensureDay(week, idx); + cell.contributions += day.contributions; + if (!cell.sources[sourceName]) cell.sources[sourceName] = 0; + cell.sources[sourceName] += day.contributions; } } } @@ -259,4 +273,4 @@ function textSpan(t) { const s = document.createElement("span"); s.textContent = t; return s; } global.ContribHeatmap = { render }; -})(typeof window !== "undefined" ? window : this); \ No newline at end of file +})(typeof window !== "undefined" ? window : this);