diff --git a/ts/lib/tslib/time.ts b/ts/lib/tslib/time.ts index b560f1546..05bc45563 100644 --- a/ts/lib/tslib/time.ts +++ b/ts/lib/tslib/time.ts @@ -177,28 +177,18 @@ 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 { - // For bins that cross or end at day 0, we need special handling - if (daysEnd > 0) { - // Bin crosses day 0: show from 0 to the oldest day (exclusive of endDay) - // If bin is [-5, 1), we want "0-4 days ago" - return tr.statisticsDaysAgoRange({ - daysStart: 0, - daysEnd: -daysStart - 1, - }); - } else { - // Bin is entirely in the past: show from newest to oldest - // For a bin [startDay, endDay), to show consecutive ranges like "0-4", "5-9", "10-14", - // we use endDay as the start of the range - // The bin width is daysEnd - daysStart, so daysEnd = daysStart + (width - 1) - // Example: bin [-10, -5) has width 5, should show "5-9 days ago" - const binWidth = Math.abs(daysEnd - daysStart); - const daysStartAbs = Math.abs(daysEnd); - return tr.statisticsDaysAgoRange({ - daysStart: daysStartAbs, - daysEnd: daysStartAbs + binWidth - 1, - }); - } + // Crosses zero: [-5, 1) -> "0-4 days ago" + return tr.statisticsDaysAgoRange({ + daysStart: 0, + daysEnd: Math.abs(daysStart) - 1, + }); } } } diff --git a/ts/routes/graphs/reviews.ts b/ts/routes/graphs/reviews.ts index 8cb221886..a32089a3e 100644 --- a/ts/routes/graphs/reviews.ts +++ b/ts/routes/graphs/reviews.ts @@ -234,17 +234,10 @@ 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!); - // If bin ends at 0, treat it as including day 0 (so use 1 as endDay for dayLabel) - // For negative bins, use the bin end directly (dayLabel will handle the conversion) - let endDay: number; - if (d.x1! === 0) { - endDay = 1; - } else if (d.x1! < 0) { - endDay = d.x1!; - } else { - endDay = Math.ceil(d.x1!); - } + const endDay = d.x1! === 0 ? 1 : d.x1!; const day = dayLabel(startDay, endDay); const totals = totalsForBin(d); const dayTotal = valueLabel(sum(totals));