From fa035781fd3ced4e5270ddb73cd67e8729961e97 Mon Sep 17 00:00:00 2001 From: ArthurErlich Date: Thu, 28 May 2026 22:09:31 +0200 Subject: [PATCH] fix(svg-renderer): correct date alignment and drop unused parameter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - modify('Sunday') → modify('last Sunday') so the grid start is reliably the prior Sunday when today is already Sunday - Remove unused $totalW from renderLegend signature - Remove unused GAP constant (value preserved inline as a comment on STEP) Co-Authored-By: Claude Sonnet 4.6 --- src/Service/SvgRenderer.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Service/SvgRenderer.php b/src/Service/SvgRenderer.php index 195a42a..2682a81 100644 --- a/src/Service/SvgRenderer.php +++ b/src/Service/SvgRenderer.php @@ -28,8 +28,7 @@ class SvgRenderer ]; private const CELL = 10; // px - private const GAP = 3; // px - private const STEP = 13; // CELL + GAP + private const STEP = 13; // CELL + 3px gap private const WEEKS = 53; private const MARGIN_X = 28; // left margin for day labels private const MARGIN_Y = 20; // top margin for month labels @@ -42,7 +41,7 @@ class SvgRenderer $today = new \DateTimeImmutable('today'); // align grid: last column always ends on the Saturday of the current week $endSat = $today->modify('Saturday this week'); - $start = $endSat->modify('-' . (self::WEEKS - 1) . ' weeks')->modify('Sunday'); + $start = $endSat->modify('-' . (self::WEEKS - 1) . ' weeks')->modify('last Sunday'); $grid = $this->buildGrid($start, $today, $contributions); $stats = $this->computeStats($contributions); @@ -69,7 +68,7 @@ class SvgRenderer $out .= $this->renderCells($grid, $colors); // Legend row (Less → More) - $out .= $this->renderLegend($totalW, $totalH, $colors); + $out .= $this->renderLegend($totalH, $colors); // Total count $out .= sprintf( @@ -196,9 +195,10 @@ class SvgRenderer $y = self::MARGIN_Y + $d * self::STEP; $color = $colors['levels'][$this->level($cell['count'])]; - $ts = strtotime($cell['date']); - $label = $cell['count'] > 0 - ? $cell['count'] . ' contribution' . ($cell['count'] !== 1 ? 's' : '') . ' on ' . date('F j, Y', $ts) + $ts = strtotime($cell['date']); + $suffix = $cell['count'] !== 1 ? 's' : ''; + $label = $cell['count'] > 0 + ? $cell['count'] . ' contribution' . $suffix . ' on ' . date('F j, Y', $ts) : 'No contributions on ' . date('F j, Y', $ts); $out .= sprintf( @@ -216,7 +216,7 @@ class SvgRenderer return $out; } - private function renderLegend(int $totalW, int $totalH, array $colors): string + private function renderLegend(int $totalH, array $colors): string { $y = $totalH - 14; $out = sprintf(