Skip to content

Commit 5e76adf

Browse files
authored
refactor(svg): extract radar scan line into renderRadarScan() helper (JhaSourav07#2242)
## Description Fixes JhaSourav07#290 Extracts the animated radar scan `<rect>` element into a `renderRadarScan(speed, sf, accentColor, autoTheme)` helper. - Both `renderFooter` (static theme) and `generateAutoThemeSVG` (auto theme) now call this single helper - Static theme passes `autoTheme: false` with the resolved accent hex - Auto theme passes `autoTheme: true` with empty string (uses CSS class) - Single source of truth for radar scan markup All 110 existing tests pass. ## Pillar - [x] 📐 Pillar 2 — Geometric SVG Improvement ## Visual Preview No visual change — pure refactor. SVG output is identical. ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [x] My commits follow the Conventional Commits format. - [ ] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have starred the repo. - [x] I have made sure that i have only one commit to merge in this PR. - [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard.
2 parents 1dae8bc + 69f3217 commit 5e76adf

1 file changed

Lines changed: 23 additions & 25 deletions

File tree

lib/svg/generator.ts

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,27 @@ function renderTowers(
488488
return towers;
489489
}
490490

491+
function renderRadarScan(
492+
speed: string,
493+
sf: number,
494+
accentColor: string,
495+
autoTheme: boolean
496+
): string {
497+
const s = createScaler(sf);
498+
const fillAttr = autoTheme
499+
? 'class="cp-accent-fill scan-line"'
500+
: `fill="${accentColor}" class="cp-accent-fill scan-line"`;
501+
return `<rect
502+
x="${s(100)}"
503+
y="${s(80)}"
504+
width="${s(400)}"
505+
height="${s(1)}"
506+
${fillAttr}
507+
fill-opacity="0.3"
508+
style="--scan-speed: ${speed}; --scan-start: ${s(0)}px; --scan-end: ${s(240)}px;"
509+
/>`;
510+
}
511+
491512
function renderFooter(
492513
stats: StreakStats,
493514
params: BadgeParams,
@@ -500,15 +521,7 @@ function renderFooter(
500521
return `
501522
${!params.hide_stats ? renderStatsSection(stats, labels, s, params) : ''}
502523
${!params.hide_title ? `<text x="${s(300)}" y="${s(50)}" text-anchor="middle" class="title">${truncateUsername(safeUser).toUpperCase()}</text>` : ''}
503-
<rect
504-
x="${s(100)}"
505-
y="${s(80)}"
506-
width="${s(400)}"
507-
height="${s(1)}"
508-
class="cp-accent-fill scan-line"
509-
fill-opacity="0.3"
510-
style="--scan-speed: ${params.speed || '8s'}; --scan-start: ${s(0)}px; --scan-end: ${s(240)}px;"
511-
/>`;
524+
${renderRadarScan(params.speed || '8s', sf, accent, false)}`;
512525
}
513526

514527
const MONTH_NAMES = [
@@ -773,22 +786,7 @@ ${
773786
? `<text x="${s(300)}" y="${s(50)}" text-anchor="middle" class="title">${truncateUsername(safeUser).toUpperCase()}</text>`
774787
: ''
775788
}
776-
777-
${
778-
animate
779-
? `
780-
<rect
781-
x="${s(100)}"
782-
y="${s(80)}"
783-
width="${s(400)}"
784-
height="${s(1)}"
785-
class="cp-accent-fill scan-line"
786-
fill-opacity="0.3"
787-
style="--scan-speed: ${params.speed || '8s'}; --scan-start: ${s(0)}px; --scan-end: ${s(240)}px;"
788-
/>
789-
`
790-
: ''
791-
}
789+
${renderRadarScan(params.speed || '8s', sf, '', true)}
792790
</svg>
793791
`;
794792
}

0 commit comments

Comments
 (0)