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 CELL = 10; // px
|
||||||
private const GAP = 3; // px
|
private const STEP = 13; // CELL + 3px gap
|
||||||
private const STEP = 13; // CELL + GAP
|
|
||||||
private const WEEKS = 53;
|
private const WEEKS = 53;
|
||||||
private const MARGIN_X = 28; // left margin for day labels
|
private const MARGIN_X = 28; // left margin for day labels
|
||||||
private const MARGIN_Y = 20; // top margin for month labels
|
private const MARGIN_Y = 20; // top margin for month labels
|
||||||
@@ -42,7 +41,7 @@ class SvgRenderer
|
|||||||
$today = new \DateTimeImmutable('today');
|
$today = new \DateTimeImmutable('today');
|
||||||
// align grid: last column always ends on the Saturday of the current week
|
// align grid: last column always ends on the Saturday of the current week
|
||||||
$endSat = $today->modify('Saturday this 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);
|
$grid = $this->buildGrid($start, $today, $contributions);
|
||||||
$stats = $this->computeStats($contributions);
|
$stats = $this->computeStats($contributions);
|
||||||
@@ -69,7 +68,7 @@ class SvgRenderer
|
|||||||
$out .= $this->renderCells($grid, $colors);
|
$out .= $this->renderCells($grid, $colors);
|
||||||
|
|
||||||
// Legend row (Less → More)
|
// Legend row (Less → More)
|
||||||
$out .= $this->renderLegend($totalW, $totalH, $colors);
|
$out .= $this->renderLegend($totalH, $colors);
|
||||||
|
|
||||||
// Total count
|
// Total count
|
||||||
$out .= sprintf(
|
$out .= sprintf(
|
||||||
@@ -197,8 +196,9 @@ class SvgRenderer
|
|||||||
$color = $colors['levels'][$this->level($cell['count'])];
|
$color = $colors['levels'][$this->level($cell['count'])];
|
||||||
|
|
||||||
$ts = strtotime($cell['date']);
|
$ts = strtotime($cell['date']);
|
||||||
|
$suffix = $cell['count'] !== 1 ? 's' : '';
|
||||||
$label = $cell['count'] > 0
|
$label = $cell['count'] > 0
|
||||||
? $cell['count'] . ' contribution' . ($cell['count'] !== 1 ? 's' : '') . ' on ' . date('F j, Y', $ts)
|
? $cell['count'] . ' contribution' . $suffix . ' on ' . date('F j, Y', $ts)
|
||||||
: 'No contributions on ' . date('F j, Y', $ts);
|
: 'No contributions on ' . date('F j, Y', $ts);
|
||||||
|
|
||||||
$out .= sprintf(
|
$out .= sprintf(
|
||||||
@@ -216,7 +216,7 @@ class SvgRenderer
|
|||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function renderLegend(int $totalW, int $totalH, array $colors): string
|
private function renderLegend(int $totalH, array $colors): string
|
||||||
{
|
{
|
||||||
$y = $totalH - 14;
|
$y = $totalH - 14;
|
||||||
$out = sprintf(
|
$out = sprintf(
|
||||||
|
|||||||
Reference in New Issue
Block a user