From 6e341d5e0722e9da6c074d6a196e84c18f73a31c Mon Sep 17 00:00:00 2001 From: junlu592 Date: Tue, 9 Dec 2025 13:17:59 +0100 Subject: [PATCH] fixed labels for bins, and made sure year is 365 days --- ts/lib/tslib/time.ts | 11 ++--------- ts/routes/graphs/reviews.ts | 8 +++++++- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/ts/lib/tslib/time.ts b/ts/lib/tslib/time.ts index 05bc45563..25d70eef3 100644 --- a/ts/lib/tslib/time.ts +++ b/ts/lib/tslib/time.ts @@ -177,17 +177,10 @@ export function dayLabel(daysStart: number, daysEnd: number): string { daysStart, 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 { - // Crosses zero: [-5, 1) -> "0-4 days ago" return tr.statisticsDaysAgoRange({ - daysStart: 0, - daysEnd: Math.abs(daysStart) - 1, + daysStart: Math.abs(daysEnd - 1), + daysEnd: -daysStart, }); } } diff --git a/ts/routes/graphs/reviews.ts b/ts/routes/graphs/reviews.ts index a32089a3e..f8832525b 100644 --- a/ts/routes/graphs/reviews.ts +++ b/ts/routes/graphs/reviews.ts @@ -108,6 +108,8 @@ export function renderReviews( break; } 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 let x = scaleLinear().domain([xMin!, xMax]); @@ -117,7 +119,11 @@ export function renderReviews( const spacing = thresholds[1] - thresholds[0]; const partial = thresholds[0] - xMin!; 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]); thresholds = x.ticks(desiredBars); }