260714_01_ENH: 테스트 서버에서 기동 후 중간 테스트를 위한 커밋
This commit is contained in:
50
src/components/chart/KriPieChart.tsx
Normal file
50
src/components/chart/KriPieChart.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
'use client'
|
||||
|
||||
import { useMemo } from 'react'
|
||||
import type { EChartsOption } from 'echarts'
|
||||
|
||||
import { BaseEChart } from './BaseEChart'
|
||||
import type { KriChartBaseProps, KriPieChartSeries } from './chart.types'
|
||||
import { defaultLegend, mergeChartOptions } from './chart.utils'
|
||||
|
||||
export type KriPieChartProps = KriChartBaseProps & {
|
||||
series: KriPieChartSeries[]
|
||||
}
|
||||
|
||||
const getPieCenter = (index: number, count: number) => {
|
||||
if (count === 1) return ['50%', '55%']
|
||||
|
||||
return [`${((index + 0.5) / count) * 100}%`, '55%']
|
||||
}
|
||||
|
||||
export function KriPieChart({
|
||||
series,
|
||||
title,
|
||||
legend,
|
||||
tooltip,
|
||||
option,
|
||||
...baseChartProps
|
||||
}: KriPieChartProps) {
|
||||
const chartOption = useMemo<EChartsOption>(() => {
|
||||
const generated: EChartsOption = {
|
||||
title,
|
||||
tooltip: tooltip ?? { trigger: 'item' },
|
||||
legend: legend ?? defaultLegend(series.length),
|
||||
series: series.map((item, index) => ({
|
||||
type: 'pie',
|
||||
name: item.name,
|
||||
data: item.data,
|
||||
radius: item.radius ?? (series.length > 1 ? ['32%', '52%'] : '65%'),
|
||||
center: item.center ?? getPieCenter(index, series.length),
|
||||
...item.option,
|
||||
})) as EChartsOption['series'],
|
||||
}
|
||||
|
||||
return mergeChartOptions(generated, option)
|
||||
}, [legend, option, series, title, tooltip])
|
||||
|
||||
return <BaseEChart option={chartOption} {...baseChartProps} />
|
||||
}
|
||||
|
||||
export default KriPieChart
|
||||
|
||||
Reference in New Issue
Block a user