// SVG Bar Chart import { escapeHtml } from "../../core/helpers"; import type { DailyCount } from "../../types/api"; export function renderSVGBarChart(dailyCounts: DailyCount[]): string { if (!dailyCounts || dailyCounts.length === 0) return ""; const chartW = 700; const chartH = 100; const barGap = 4; const barW = Math.max( 8, (chartW - (dailyCounts.length - 1) * barGap) / dailyCounts.length, ); let maxCount = 0; for (const day of dailyCounts) { const total = (day.completed || 0) + (day.failed || 0); if (total > maxCount) maxCount = total; } if (maxCount === 0) maxCount = 1; let svg = ``; for (let i = 0; i < dailyCounts.length; i++) { const day = dailyCounts[i]; const completed = day.completed || 0; const failed = day.failed || 0; const x = i * (barW + barGap); const cH = (completed / maxCount) * chartH; const fH = (failed / maxCount) * chartH; if (cH > 0) { svg += ``; } if (fH > 0) { svg += ``; } if (cH === 0 && fH === 0) { svg += ``; } const dateStr = day.date || ""; const parts = dateStr.split("-"); const label = parts.length >= 3 ? parts[1] + "/" + parts[2] : dateStr; svg += `${escapeHtml(label)}`; } svg += ""; return svg; }