From 6ebe80775ea376cea238704a9f170a89019fcedf Mon Sep 17 00:00:00 2001 From: junlu592 Date: Tue, 2 Dec 2025 11:29:32 +0100 Subject: [PATCH] reviewed code and simplified functions in review.ts --- ts/routes/graphs/reviews.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ts/routes/graphs/reviews.ts b/ts/routes/graphs/reviews.ts index f26a9b157..4651cd29f 100644 --- a/ts/routes/graphs/reviews.ts +++ b/ts/routes/graphs/reviews.ts @@ -90,37 +90,37 @@ export function renderReviews( ): TableDatum[] { const svg = select(svgElem); const trans = svg.transition().duration(600) as any; - - let xMax = 1; + + let xMax = 0; let xMin = 0; // cap max to selected range switch (range) { case GraphRange.Month: xMin = -30; - xMax = 0; break; case GraphRange.ThreeMonths: xMin = -89; - xMax = 0; break; case GraphRange.Year: xMin = -364; - xMax = 0; break; case GraphRange.AllTime: xMin = min(sourceData.reviewCount.keys())!; + xMax = 1; break; } const desiredBars = Math.min(70, Math.abs(xMin!)); + // Create initial scale to determine tick spacing let x = scaleLinear().domain([xMin!, xMax]); let thresholds = x.ticks(desiredBars); + // Adjust xMin to align with tick spacing so the oldest bin has the same width as others if (thresholds.length >= 2) { const spacing = thresholds[1] - thresholds[0]; - const partial = thresholds[0] - x.domain()[0]; + const partial = thresholds[0] - xMin!; if (spacing > 0 && partial > 0 && partial < spacing) { - const adjustedMin = thresholds[0] - spacing; - x = scaleLinear().domain([adjustedMin, xMax]); + xMin = thresholds[0] - spacing; + x = scaleLinear().domain([xMin, xMax]); thresholds = x.ticks(desiredBars); } }