Skip to content

Commit 3174980

Browse files
committed
feat: make watermark generator more flexible
1 parent 88dce54 commit 3174980

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

app/composables/useChartWatermark.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,23 @@ export function drawNpmxLogoAndTaglineWatermark({
7676
colors,
7777
translateFn,
7878
positioning = 'bottom',
79+
sizeRatioLogo = 1,
80+
sizeRatioTagline = 1,
81+
offsetYTagline = -6,
82+
offsetYLogo = 0
7983
}: {
8084
svg: Record<string, any>
8185
colors: WatermarkColors
8286
translateFn: (key: string) => string
8387
positioning?: 'bottom' | 'belowDrawingArea'
88+
sizeRatioLogo?: number
89+
sizeRatioTagline?: number
90+
offsetYTagline?: number
91+
offsetYLogo?: number
8492
}) {
8593
if (!svg?.drawingArea) return ''
86-
const npmxLogoWidthToHeight = 2.64
87-
const npmxLogoWidth = 100
94+
const npmxLogoWidthToHeight = 2.64 * sizeRatioLogo
95+
const npmxLogoWidth = 100 * sizeRatioLogo
8896
const npmxLogoHeight = npmxLogoWidth / npmxLogoWidthToHeight
8997

9098
// Position watermark based on the positioning strategy
@@ -94,18 +102,18 @@ export function drawNpmxLogoAndTaglineWatermark({
94102
: svg.height - npmxLogoHeight
95103

96104
const taglineY =
97-
positioning === 'belowDrawingArea' ? watermarkY - 6 : svg.height - npmxLogoHeight - 6
105+
positioning === 'belowDrawingArea' ? watermarkY + offsetYTagline : svg.height - npmxLogoHeight + offsetYTagline
98106

99107
// Center the watermark horizontally relative to the full SVG width
100108
const watermarkX = svg.width / 2 - npmxLogoWidth / 2
101109

102110
return `
103-
${generateWatermarkLogo({ x: watermarkX, y: watermarkY, width: npmxLogoWidth, height: npmxLogoHeight, fill: colors.fg })}
111+
${generateWatermarkLogo({ x: watermarkX, y: watermarkY + offsetYLogo, width: npmxLogoWidth, height: npmxLogoHeight, fill: colors.fg })}
104112
<text
105113
fill="${colors.fgSubtle}"
106114
x="${svg.width / 2}"
107115
y="${taglineY}"
108-
font-size="12"
116+
font-size="${12 * sizeRatioTagline}"
109117
text-anchor="middle"
110118
>
111119
${translateFn('tagline')}

0 commit comments

Comments
 (0)