fixed the heatmap cells being too sensitive compared to the original forgejo heatmap
This commit is contained in:
parent
bf03908323
commit
dd900af6aa
1 changed files with 10 additions and 5 deletions
|
|
@ -43,10 +43,13 @@ export default function ContributionHeatmap() {
|
||||||
const data: HeatmapData[] = await res.json();
|
const data: HeatmapData[] = await res.json();
|
||||||
const map = new Map<string, number>();
|
const map = new Map<string, number>();
|
||||||
let total = 0;
|
let total = 0;
|
||||||
|
let maxContribs = 0;
|
||||||
data.forEach((item) => {
|
data.forEach((item) => {
|
||||||
const d = new Date(item.timestamp * 1000);
|
const d = new Date(item.timestamp * 1000);
|
||||||
const dateStr = d.getFullYear() + "-" + String(d.getMonth() + 1).padStart(2, "0") + "-" + String(d.getDate()).padStart(2, "0");
|
const dateStr = d.getFullYear() + "-" + String(d.getMonth() + 1).padStart(2, "0") + "-" + String(d.getDate()).padStart(2, "0");
|
||||||
map.set(dateStr, (map.get(dateStr) || 0) + item.contributions);
|
const currentDayTotal = (map.get(dateStr) || 0) + item.contributions;
|
||||||
|
map.set(dateStr, currentDayTotal);
|
||||||
|
if (currentDayTotal > maxContribs) maxContribs = currentDayTotal;
|
||||||
total += item.contributions;
|
total += item.contributions;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -64,10 +67,12 @@ export default function ContributionHeatmap() {
|
||||||
const contribs = map.get(dateStr) || 0;
|
const contribs = map.get(dateStr) || 0;
|
||||||
|
|
||||||
let level = 0;
|
let level = 0;
|
||||||
if (contribs > 0) level = 1;
|
if (contribs > 0) {
|
||||||
if (contribs >= 3) level = 2;
|
level = 1;
|
||||||
if (contribs >= 6) level = 3;
|
if (contribs > maxContribs * 0.25) level = 2;
|
||||||
if (contribs >= 10) level = 4;
|
if (contribs > maxContribs * 0.5) level = 3;
|
||||||
|
if (contribs > maxContribs * 0.75) level = 4;
|
||||||
|
}
|
||||||
|
|
||||||
currentWeek.push({ date: dateStr, contribs, level });
|
currentWeek.push({ date: dateStr, contribs, level });
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue