From d00dc07613855fc103f4d4be8991408b6693fcc5 Mon Sep 17 00:00:00 2001 From: junlu592 Date: Fri, 12 Dec 2025 14:38:23 +0100 Subject: [PATCH] adjusted last bin labeling with xmin --- ts/routes/graphs/reviews.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ts/routes/graphs/reviews.ts b/ts/routes/graphs/reviews.ts index df1c03759..f23ad7fdc 100644 --- a/ts/routes/graphs/reviews.ts +++ b/ts/routes/graphs/reviews.ts @@ -109,6 +109,8 @@ export function renderReviews( } const desiredBars = Math.min(70, Math.abs(xMin!)); const shouldCapRange = range !== GraphRange.AllTime; + // Store original xMin before any adjustments (needed for periodDays calculation) + const originalXMinBeforeAdjustment = xMin!; const originalXMin = shouldCapRange ? xMin! : undefined; // Create initial scale to determine tick spacing @@ -230,7 +232,11 @@ export function renderReviews( function tooltipText(d: BinType, cumulative: number): string { // Convert bin boundaries [x0, x1) for dayLabel // If bin ends at 0, treat it as crossing zero so day 0 is included - const startDay = Math.floor(d.x0!); + // For the first (oldest) bin, use the original xMin to ensure labels match the intended range + const isFirstBin = bins.length > 0 && d.x0 === bins[0].x0; + const startDay = isFirstBin + ? originalXMinBeforeAdjustment + : Math.floor(d.x0!); const endDay = d.x1! === 0 ? 1 : d.x1!; const day = dayLabel(startDay, endDay); const totals = totalsForBin(d); @@ -347,7 +353,11 @@ export function renderReviews( }) .on("mouseout", hideTooltip); - const periodDays = -xMin + 1; + // Calculate periodDays from the actual data range, not the adjusted xMin + // For AllTime, xMin might be extended for bin alignment, so use the original xMin (actual oldest data) + // For fixed ranges, use the original xMin before adjustment (which matches the displayed range) + const actualXMin = originalXMinBeforeAdjustment; + const periodDays = -actualXMin + 1; const studiedDays = sum(bins, (bin) => bin.length); const studiedPercent = (studiedDays / periodDays) * 100; const total = yCumMax;