import { ChartData } from '@/types/chat'; import { Card, CardContent, Typography } from '@mui/joy'; import { useMemo } from 'react'; import BarChart from './bar-chart'; import LineChart from './line-chart'; import TableChart from './table-chart'; type Props = { chartsData: Array; }; function Chart({ chartsData }: Props) { const chartRows = useMemo(() => { if (chartsData) { const res = []; // 若是有类型为 IndicatorValue 的,提出去,独占一行 const chartCalc = chartsData?.filter(item => item.chart_type === 'IndicatorValue'); if (chartCalc.length > 0) { res.push({ charts: chartCalc, type: 'IndicatorValue', }); } const otherCharts = chartsData?.filter(item => item.chart_type !== 'IndicatorValue'); const otherLength = otherCharts.length; let curIndex = 0; // charts 数量 3~8个,暂定每行排序 const chartLengthMap = [[0], [1], [2], [1, 2], [1, 3], [2, 1, 2], [2, 1, 3], [3, 1, 3], [3, 2, 3]]; chartLengthMap[otherLength].forEach(item => { if (item > 0) { const rowsItem = otherCharts.slice(curIndex, curIndex + item); curIndex = curIndex + item; res.push({ charts: rowsItem, }); } }); return res; } return undefined; }, [chartsData]); return (
{chartRows?.map((chartRow, index) => (
{chartRow.charts.map(chart => { if (chart.chart_type === 'IndicatorValue' || chart.type === 'IndicatorValue') { return (
{chart.values.map(item => (
{item.name} {item.value}
))}
); } else if (chart.chart_type === 'LineChart' || chart.type === 'LineChart') { return ; } else if (chart.chart_type === 'BarChart' || chart.type === 'BarChart') { return ; } else if (chart.chart_type === 'Table' || chart.type === 'TableChartData') { return ; } })}
))}
); } export * from './autoChart'; export default Chart;