'use client' import { useMemo } from 'react' import type { EChartsOption } from 'echarts' import { BaseEChart } from './BaseEChart' import type { KriCartesianChartProps } from './chart.types' import { defaultGrid, defaultLegend, mergeChartOptions, mergeObjectOption } from './chart.utils' export type KriLineChartProps = KriCartesianChartProps & { smooth?: boolean area?: boolean showSymbol?: boolean } export function KriLineChart({ categories, series, smooth = false, area = false, showSymbol = true, title, legend, tooltip, grid, xAxis, yAxis, option, ...baseChartProps }: KriLineChartProps) { const chartOption = useMemo(() => { const generated: EChartsOption = { title, tooltip: tooltip ?? { trigger: 'axis' }, legend: legend ?? defaultLegend(series.length), grid: grid ?? defaultGrid(series.length), xAxis: mergeObjectOption({ type: 'category', data: categories, boundaryGap: false }, xAxis) as EChartsOption['xAxis'], yAxis: mergeObjectOption({ type: 'value' }, yAxis) as EChartsOption['yAxis'], series: series.map((item) => ({ type: 'line', name: item.name, data: item.data, smooth, showSymbol, ...(area ? { areaStyle: {} } : {}), ...(item.color ? { color: item.color } : {}), ...item.option, })) as EChartsOption['series'], } return mergeChartOptions(generated, option) }, [area, categories, grid, legend, option, series, showSymbol, smooth, title, tooltip, xAxis, yAxis]) return } export default KriLineChart