Skip to content

Commit 82c4ea4

Browse files
committed
refactor(svg): extract radar scan line into renderRadarScan() helper
1 parent 4fc855a commit 82c4ea4

1 file changed

Lines changed: 34 additions & 30 deletions

File tree

lib/svg/generator.ts

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,27 @@ function renderTowers(
357357
return towers;
358358
}
359359

360+
function renderRadarScan(
361+
speed: string,
362+
sf: number,
363+
accentColor: string,
364+
autoTheme: boolean
365+
): string {
366+
const s = createScaler(sf);
367+
const fillAttr = autoTheme
368+
? 'class="cp-accent-fill scan-line"'
369+
: `fill="${accentColor}" class="cp-accent-fill scan-line"`;
370+
return `<rect
371+
x="${s(100)}"
372+
y="${s(80)}"
373+
width="${s(400)}"
374+
height="${s(1)}"
375+
${fillAttr}
376+
fill-opacity="0.3"
377+
style="--scan-speed: ${speed}; --scan-start: ${s(0)}px; --scan-end: ${s(240)}px;"
378+
/>`;
379+
}
380+
360381
function renderFooter(
361382
stats: StreakStats,
362383
params: BadgeParams,
@@ -369,15 +390,7 @@ function renderFooter(
369390
return `
370391
${!params.hide_stats ? renderStatsSection(stats, labels, s, params) : ''}
371392
${!params.hide_title ? `<text x="${s(300)}" y="${s(50)}" text-anchor="middle" class="title">${truncateUsername(safeUser).toUpperCase()}</text>` : ''}
372-
<rect
373-
x="${s(100)}"
374-
y="${s(80)}"
375-
width="${s(400)}"
376-
height="${s(1)}"
377-
class="cp-accent-fill scan-line"
378-
fill-opacity="0.3"
379-
style="--scan-speed: ${params.speed || '8s'}; --scan-start: ${s(0)}px; --scan-end: ${s(240)}px;"
380-
/>`;
393+
${renderRadarScan(params.speed || '8s', sf, accent, false)}`;
381394
}
382395

383396
const MONTH_NAMES = [
@@ -623,16 +636,7 @@ ${
623636
? `<text x="${s(300)}" y="${s(50)}" text-anchor="middle" class="title">${truncateUsername(safeUser).toUpperCase()}</text>`
624637
: ''
625638
}
626-
627-
<rect
628-
x="${s(100)}"
629-
y="${s(80)}"
630-
width="${s(400)}"
631-
height="${s(1)}"
632-
class="cp-accent-fill scan-line"
633-
fill-opacity="0.3"
634-
style="--scan-speed: ${params.speed || '8s'}; --scan-start: ${s(0)}px; --scan-end: ${s(240)}px;"
635-
/>
639+
${renderRadarScan(params.speed || '8s', sf, '', true)}
636640
</svg>
637641
`;
638642
}
@@ -930,13 +934,13 @@ export function generateWrappedSVG(
930934
931935
.title-user { font-family: ${selectedFont || '"Syncopate", sans-serif'}; font-weight: 700; font-size: 13px; letter-spacing: 2.5px; opacity: 0.85; }
932936
.title-wrapped { font-family: ${selectedFont || '"Syncopate", sans-serif'}; font-weight: 700; font-size: 13px; letter-spacing: 2.5px; }
933-
937+
934938
.total-commits { font-family: ${statsFont}; font-size: 46px; font-weight: 700; }
935939
.total-label { font-family: "Roboto", sans-serif; font-size: 9.5px; font-weight: 700; letter-spacing: 1.5px; opacity: 0.5; }
936-
940+
937941
.grid-label { font-family: "Roboto", sans-serif; font-size: 9px; font-weight: 700; letter-spacing: 1.5px; opacity: 0.5; }
938942
.grid-val { font-family: ${statsFont}; font-size: 14.5px; font-weight: 600; }
939-
943+
940944
.scan-line {
941945
animation: scan-sweep var(--scan-speed, 8s) linear infinite;
942946
transform-box: fill-box;
@@ -1085,11 +1089,11 @@ function generateAutoThemeMonthlySVG(stats: MonthlyStats, params: BadgeParams):
10851089
${googleFontsImport}
10861090
:root { --cp-bg: #${light.bg}; --cp-text: #${light.text}; --cp-accent: #${light.accent}; --cp-negative: #${light.negative || 'cf222e'}; }
10871091
@media (prefers-color-scheme: dark) { :root { --cp-bg: #${dark.bg}; --cp-text: #${dark.text}; --cp-accent: #${dark.accent}; --cp-negative: #${dark.negative || 'f85149'}; } }
1088-
.cp-bg-fill { fill: var(--cp-bg); }
1089-
.cp-text-fill { fill: var(--cp-text); color: var(--cp-text); }
1092+
.cp-bg-fill { fill: var(--cp-bg); }
1093+
.cp-text-fill { fill: var(--cp-text); color: var(--cp-text); }
10901094
.cp-accent-fill { fill: var(--cp-accent); color: var(--cp-accent); }
10911095
.cp-delta-fill { fill: ${stats.deltaAbsolute >= 0 ? 'var(--cp-accent)' : 'var(--cp-negative)'}; }
1092-
1096+
10931097
.title { font-family: ${selectedFont || '"Syncopate", sans-serif'}; fill: var(--cp-text); font-size: 14px; letter-spacing: 2px; font-weight: 400; opacity: 0.8; }
10941098
.stats { font-family: ${statsFont}; fill: var(--cp-accent); font-size: 36px; font-weight: 600; letter-spacing: 0; }
10951099
.label { font-family: "Roboto", sans-serif; fill: var(--cp-text); font-size: 10px; font-weight: 400; letter-spacing: 1px; opacity: 0.7; }
@@ -1776,7 +1780,7 @@ export function generateVersusSVG(
17761780
${renderDefs(sf, params)}
17771781
${renderStyle(selectedFont, statsFont, googleFontsImport, text, accent, sf, bg)}
17781782
<rect width="${W}" height="${H}" rx="${radius}" fill="${params.hideBackground ? 'transparent' : bg}" />
1779-
1783+
17801784
<g transform="translate(0, 0)">
17811785
<g transform="translate(0, ${Math.round(20 * sf)})">${towers1}</g>
17821786
${renderIsometricLabels(calendar1, params, text, sf)}
@@ -1790,7 +1794,7 @@ export function generateVersusSVG(
17901794
</g>
17911795
17921796
<line x1="${singleW}" y1="${s(40)}" x2="${singleW}" y2="${H - s(40)}" stroke="${text}" stroke-opacity="0.2" stroke-width="2" stroke-dasharray="4 4" />
1793-
1797+
17941798
<g transform="translate(${singleW}, ${H / 2})">
17951799
<circle cx="0" cy="0" r="${s(24)}" fill="${bg}" stroke="${accent}" stroke-width="2" />
17961800
<text x="0" y="${s(6)}" text-anchor="middle" font-family="${statsFont}" fill="${accent}" font-size="${s(16)}" font-weight="bold">VS</text>
@@ -1911,7 +1915,7 @@ function generateAutoThemeVersusSVG(
19111915
<title>CommitPulse Versus Stats: ${safeUser1} vs ${safeUser2}</title>
19121916
<desc>${safeUser1} has ${stats1.totalContributions} ${unit}. ${safeUser2} has ${stats2.totalContributions} ${unit}.</desc>
19131917
${renderDefs(sf, params)}
1914-
1918+
19151919
<style>
19161920
@import url('https://fonts.googleapis.com/css2?family=Fira+Code&amp;family=JetBrains+Mono&amp;family=Roboto&amp;family=Syncopate:wght@400;700&amp;family=Space+Grotesk:wght@400;500;600;700&amp;display=swap');
19171921
:root { --cp-bg: #${light.bg}; --cp-text: #${light.text}; --cp-accent: #${light.accent}; --cp-label-fill: ${lightLabelFill}; --cp-label-opacity: ${lightLabelOpacity}; }
@@ -1944,7 +1948,7 @@ function generateAutoThemeVersusSVG(
19441948
</style>
19451949
19461950
<rect width="${W}" height="${H}" rx="${radius}" class="${params.hideBackground ? '' : 'cp-bg-fill'}" fill="${params.hideBackground ? 'transparent' : ''}" />
1947-
1951+
19481952
<g transform="translate(0, 0)">
19491953
<g transform="translate(0, ${Math.round(20 * sf)})">${towers1}</g>
19501954
${renderIsometricLabels(calendar1, params, '', sf)}
@@ -1958,7 +1962,7 @@ function generateAutoThemeVersusSVG(
19581962
</g>
19591963
19601964
<line x1="${singleW}" y1="${s(40)}" x2="${singleW}" y2="${H - s(40)}" stroke="var(--cp-text)" stroke-opacity="0.2" stroke-width="2" stroke-dasharray="4 4" />
1961-
1965+
19621966
<g transform="translate(${singleW}, ${H / 2})">
19631967
<circle cx="0" cy="0" r="${s(24)}" class="cp-bg-fill" stroke="var(--cp-accent)" stroke-width="2" />
19641968
<text x="0" y="${s(6)}" text-anchor="middle" font-family="${statsFont}" class="cp-accent-fill" font-size="${s(16)}" font-weight="bold">VS</text>

0 commit comments

Comments
 (0)