fixed labels for bins, and made sure year is 365 days

This commit is contained in:
junlu592 2025-12-09 13:17:59 +01:00
parent 0c2c5c6a1c
commit 6e341d5e07
2 changed files with 9 additions and 10 deletions

View file

@ -177,17 +177,10 @@ export function dayLabel(daysStart: number, daysEnd: number): string {
daysStart, daysStart,
daysEnd: daysEnd - 1, daysEnd: daysEnd - 1,
}); });
} else if (daysEnd <= 0) {
// Past: [-10, -5) -> "5-9 days ago"
return tr.statisticsDaysAgoRange({
daysStart: Math.abs(daysEnd),
daysEnd: Math.abs(daysStart) - 1,
});
} else { } else {
// Crosses zero: [-5, 1) -> "0-4 days ago"
return tr.statisticsDaysAgoRange({ return tr.statisticsDaysAgoRange({
daysStart: 0, daysStart: Math.abs(daysEnd - 1),
daysEnd: Math.abs(daysStart) - 1, daysEnd: -daysStart,
}); });
} }
} }

View file

@ -108,6 +108,8 @@ export function renderReviews(
break; break;
} }
const desiredBars = Math.min(70, Math.abs(xMin!)); const desiredBars = Math.min(70, Math.abs(xMin!));
const shouldCapRange = range !== GraphRange.AllTime;
const originalXMin = shouldCapRange ? xMin! : undefined;
// Create initial scale to determine tick spacing // Create initial scale to determine tick spacing
let x = scaleLinear().domain([xMin!, xMax]); let x = scaleLinear().domain([xMin!, xMax]);
@ -117,7 +119,11 @@ export function renderReviews(
const spacing = thresholds[1] - thresholds[0]; const spacing = thresholds[1] - thresholds[0];
const partial = thresholds[0] - xMin!; const partial = thresholds[0] - xMin!;
if (spacing > 0 && partial > 0 && partial < spacing) { if (spacing > 0 && partial > 0 && partial < spacing) {
xMin = thresholds[0] - spacing; const adjustedMin = thresholds[0] - spacing;
// Don't extend beyond the original range limit for fixed ranges
xMin = shouldCapRange
? Math.max(adjustedMin, originalXMin!)
: adjustedMin;
x = scaleLinear().domain([xMin, xMax]); x = scaleLinear().domain([xMin, xMax]);
thresholds = x.ticks(desiredBars); thresholds = x.ticks(desiredBars);
} }