commit
a78dac9830
|
|
@ -142,6 +142,6 @@
|
||||||
<script src="/js/flavors.js"></script>
|
<script src="/js/flavors.js"></script>
|
||||||
<script src="/js/cat.js"></script>
|
<script src="/js/cat.js"></script>
|
||||||
<script src="/js/heatmap.js"></script>
|
<script src="/js/heatmap.js"></script>
|
||||||
<script>ContribHeatmap.render("#contrib", { theme: "trans" });</script>
|
<script>ContribHeatmap.render("#contrib", { theme: "forest" });</script>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
@ -238,6 +238,5 @@
|
||||||
<script src="/js/flavors.js"></script>
|
<script src="/js/flavors.js"></script>
|
||||||
<script src="/js/cat.js"></script>
|
<script src="/js/cat.js"></script>
|
||||||
<script src="/js/heatmap.js"></script>
|
<script src="/js/heatmap.js"></script>
|
||||||
<script>ContribHeatmap.render("#contrib", { theme: "trans" });</script>
|
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
@ -123,6 +123,4 @@
|
||||||
<script src="/js/flavors.js"></script>
|
<script src="/js/flavors.js"></script>
|
||||||
<script src="/js/cat.js"></script>
|
<script src="/js/cat.js"></script>
|
||||||
<script src="/js/heatmap.js"></script>
|
<script src="/js/heatmap.js"></script>
|
||||||
<script>ContribHeatmap.render("#contrib", { theme: "trans" });</script>
|
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
(function (global) {
|
(function (global) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
/* ---- core logic (unchanged from the working version) ---- */
|
/* ---- core logic ---- */
|
||||||
function sundayOf(date) {
|
function sundayOf(date) {
|
||||||
const sunday = new Date(date);
|
const sunday = new Date(date);
|
||||||
sunday.setUTCDate(sunday.getUTCDate() - sunday.getUTCDay());
|
sunday.setUTCDate(sunday.getUTCDate() - sunday.getUTCDay());
|
||||||
|
|
@ -28,6 +28,19 @@
|
||||||
}
|
}
|
||||||
return week;
|
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) {
|
function buildHeatmapData(sources) {
|
||||||
const weeks = new Map();
|
const weeks = new Map();
|
||||||
for (const sourceName of Object.keys(sources)) {
|
for (const sourceName of Object.keys(sources)) {
|
||||||
|
|
@ -39,9 +52,10 @@
|
||||||
if (day.contributions > 0) {
|
if (day.contributions > 0) {
|
||||||
const week = weeks.get(key);
|
const week = weeks.get(key);
|
||||||
const idx = new Date(day.timestamp * 1000).getUTCDay();
|
const idx = new Date(day.timestamp * 1000).getUTCDay();
|
||||||
week[idx].contributions += day.contributions;
|
const cell = ensureDay(week, idx);
|
||||||
if (!week[idx].sources[sourceName]) week[idx].sources[sourceName] = 0;
|
cell.contributions += day.contributions;
|
||||||
week[idx].sources[sourceName] += 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; }
|
function textSpan(t) { const s = document.createElement("span"); s.textContent = t; return s; }
|
||||||
|
|
||||||
global.ContribHeatmap = { render };
|
global.ContribHeatmap = { render };
|
||||||
})(typeof window !== "undefined" ? window : this);
|
})(typeof window !== "undefined" ? window : this);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue