import { lazy, Suspense } from 'react'; import { Spin } from '@/shared/antd-imports'; // Lazy load Chart.js components const LazyBarChart = lazy(() => import('react-chartjs-2').then(module => ({ default: module.Bar })) ); const LazyLineChart = lazy(() => import('react-chartjs-2').then(module => ({ default: module.Line })) ); const LazyPieChart = lazy(() => import('react-chartjs-2').then(module => ({ default: module.Pie })) ); const LazyDoughnutChart = lazy(() => import('react-chartjs-2').then(module => ({ default: module.Doughnut })) ); // Lazy load Gantt components const LazyGanttChart = lazy(() => import('gantt-task-react').then(module => ({ default: module.Gantt })) ); // Chart loading fallback const ChartLoadingFallback = () => (
); // Wrapped components with Suspense export const BarChart = (props: any) => ( }> ); export const LineChart = (props: any) => ( }> ); export const PieChart = (props: any) => ( }> ); export const DoughnutChart = (props: any) => ( }> ); export const GanttChart = (props: any) => ( }> ); // Hook to preload chart libraries when needed export const usePreloadCharts = () => { const preloadCharts = () => { // Preload Chart.js import('react-chartjs-2'); import('chart.js'); // Preload Gantt import('gantt-task-react'); }; return { preloadCharts }; };