import React, { useRef } from 'react'; // Wrapper component that adds PNG export to any chart export function ExportableChart({ children, filename = 'chart', className = '' }) { const chartRef = useRef(null); const exportAsPNG = () => { const chartContainer = chartRef.current; if (!chartContainer) return; const canvas = chartContainer.querySelector('canvas'); if (!canvas) return; // Create a new canvas with white background const exportCanvas = document.createElement('canvas'); const ctx = exportCanvas.getContext('2d'); // Set dimensions with padding const padding = 20; exportCanvas.width = canvas.width + (padding * 2); exportCanvas.height = canvas.height + (padding * 2); // Fill white background ctx.fillStyle = '#ffffff'; ctx.fillRect(0, 0, exportCanvas.width, exportCanvas.height); // Draw the chart ctx.drawImage(canvas, padding, padding); // Export const link = document.createElement('a'); link.download = `${filename}-${new Date().toISOString().split('T')[0]}.png`; link.href = exportCanvas.toDataURL('image/png', 1.0); link.click(); }; return (