MCPcopy
hub / github.com/zxlie/FeHelper / exportChart

Function exportChart

apps/chart-maker/main.js:550–632  ·  view source on GitHub ↗
(format)

Source from the content-addressed store, hash-verified

548
549 // 导出图表为图像
550 function exportChart(format) {
551 const chartWrapper = document.getElementById('chart-wrapper');
552
553 // 创建加载指示器
554 const loadingOverlay = document.createElement('div');
555 loadingOverlay.className = 'loading-overlay';
556 loadingOverlay.innerHTML = '<div class="loading-spinner"></div>';
557 chartWrapper.appendChild(loadingOverlay);
558
559 setTimeout(() => {
560 // 获取原始canvas的尺寸
561 const originalCanvas = document.getElementById('chart-canvas');
562 const width = originalCanvas.width;
563 const height = originalCanvas.height;
564
565 // 创建一个临时的高分辨率canvas
566 const tempCanvas = document.createElement('canvas');
567 const tempCtx = tempCanvas.getContext('2d');
568
569 // 设置更高的分辨率
570 const scale = 8; // 提升到8倍分辨率
571 tempCanvas.width = width * scale;
572 tempCanvas.height = height * scale;
573
574 // 优化渲染质量
575 tempCtx.imageSmoothingEnabled = true;
576 tempCtx.imageSmoothingQuality = 'high';
577
578 html2canvas(originalCanvas, {
579 backgroundColor: '#ffffff',
580 scale: scale, // 使用8倍缩放
581 width: width,
582 height: height,
583 useCORS: true,
584 allowTaint: true,
585 logging: false,
586 imageTimeout: 0,
587 onclone: (document) => {
588 const clonedCanvas = document.getElementById('chart-canvas');
589 if(clonedCanvas) {
590 clonedCanvas.style.width = width + 'px';
591 clonedCanvas.style.height = height + 'px';
592 }
593 },
594 // 添加高级渲染选项
595 canvas: tempCanvas,
596 renderCallback: (canvas) => {
597 // 应用锐化效果
598 const ctx = canvas.getContext('2d');
599 ctx.filter = 'contrast(1.1) saturate(1.2)';
600 }
601 }).then(canvas => {
602 // 移除加载指示器
603 loadingOverlay.remove();
604
605 // 导出图像时使用更高的质量设置
606 let imgUrl;
607 if (format === 'jpg') {

Callers 1

main.jsFile · 0.85

Calls 4

setTimeoutFunction · 0.85
removeMethod · 0.80
showNotificationFunction · 0.70
getContextMethod · 0.45

Tested by

no test coverage detected