File size: 523 Bytes
f8df83d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { toPng } from 'html-to-image'

/**
 * Download a DOM node as a PNG file.
 * @param {HTMLElement} node - The DOM node to capture
 * @param {string} filename - Output filename (e.g. 'sentiment-arc.png')
 */
export async function downloadChartPng(node, filename) {
  try {
    const dataUrl = await toPng(node, { cacheBust: true })
    const link = document.createElement('a')
    link.download = filename
    link.href = dataUrl
    link.click()
  } catch (err) {
    console.error('Chart export failed:', err)
  }
}