"use client"; /** * 차트 서브타입 컴포넌트 * * Recharts 기반 막대/원형/라인 차트 * 컨테이너 크기가 너무 작으면 "차트 표시 불가" 메시지 */ import React from "react"; import { BarChart, Bar, PieChart, Pie, Cell, LineChart, Line, XAxis, YAxis, Tooltip, ResponsiveContainer, } from "recharts"; import type { DashboardItem } from "../../types"; // ===== Props ===== export interface ChartItemProps { item: DashboardItem; /** 차트에 표시할 데이터 행 */ rows: Record[]; /** 컨테이너 너비 (px) - 최소 크기 판단용 */ containerWidth: number; } // ===== 기본 색상 팔레트 ===== const DEFAULT_COLORS = [ "#6366f1", // indigo "#8b5cf6", // violet "#06b6d4", // cyan "#10b981", // emerald "#f59e0b", // amber "#ef4444", // rose "#ec4899", // pink "#14b8a6", // teal ]; // ===== 최소 표시 크기 ===== const MIN_CHART_WIDTH = 120; // ===== 메인 컴포넌트 ===== export function ChartItemComponent({ item, rows, containerWidth, }: ChartItemProps) { const { chartConfig, visibility } = item; const chartType = chartConfig?.chartType ?? "bar"; const colors = chartConfig?.colors?.length ? chartConfig.colors : DEFAULT_COLORS; const xKey = chartConfig?.xAxisColumn ?? "name"; const yKey = chartConfig?.yAxisColumn ?? "value"; // 컨테이너가 너무 작으면 메시지 표시 if (containerWidth < MIN_CHART_WIDTH) { return (
차트
); } // 데이터 없음 if (!rows.length) { return (
데이터 없음
); } return (
{/* 라벨 */} {visibility.showLabel && (

{item.label}

)} {/* 차트 영역 */}
{chartType === "bar" ? ( []}> ) : chartType === "line" ? ( []}> 250} /> ) : ( /* pie */ []} dataKey={yKey} nameKey={xKey} cx="50%" cy="50%" outerRadius="80%" label={containerWidth > 250} > {rows.map((_, index) => ( ))} )}
); }