fix(svg-renderer): correct date alignment and drop unused parameter
- 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 <noreply@anthropic.com>
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user