/** * Shared utilities for chart watermarks and legends in SVG/PNG exports */ interface WatermarkColors { fg: string bg: string fgSubtle: string } /** * Build and return legend as SVG for export * Legend items are displayed in a column, on the top left of the chart. */ export function drawSvgPrintLegend(svg: Record, colors: WatermarkColors) { const data = Array.isArray(svg?.data) ? svg.data : [] if (!data.length) return '' const seriesNames: string[] = [] data.forEach((serie, index) => { seriesNames.push(` ${serie.name} `) }) return seriesNames.join('') } /** * Build and return npmx svg logo and tagline, to be injected during PNG & SVG exports */ export function drawNpmxLogoAndTaglineWatermark( svg: Record, colors: WatermarkColors, translateFn: (key: string) => string, positioning: 'bottom' | 'belowDrawingArea' = 'bottom', ) { if (!svg?.drawingArea) return '' const npmxLogoWidthToHeight = 2.64 const npmxLogoWidth = 100 const npmxLogoHeight = npmxLogoWidth / npmxLogoWidthToHeight // Position watermark based on the positioning strategy const watermarkY = positioning === 'belowDrawingArea' ? svg.drawingArea.top + svg.drawingArea.height + 58 : svg.height - npmxLogoHeight const taglineY = positioning === 'belowDrawingArea' ? watermarkY - 6 : svg.height - npmxLogoHeight - 6 // Center the watermark horizontally relative to the full SVG width const watermarkX = svg.width / 2 - npmxLogoWidth / 2 return ` ${translateFn('tagline')} ` }