ERP-node/frontend/components/admin/dashboard/charts/Chart.tsx

83 lines
2.8 KiB
TypeScript
Raw Normal View History

"use client";
import React from "react";
import { BarChart } from "./BarChart";
2025-10-14 16:49:57 +09:00
import { HorizontalBarChart } from "./HorizontalBarChart";
import { LineChart } from "./LineChart";
import { AreaChart } from "./AreaChart";
import { PieChart } from "./PieChart";
import { StackedBarChart } from "./StackedBarChart";
2025-10-14 15:50:15 +09:00
import { ComboChart } from "./ComboChart";
import { ChartConfig, ChartData, ElementSubtype } from "../types";
interface ChartProps {
chartType: ElementSubtype;
data: ChartData;
config: ChartConfig;
width?: number;
height?: number;
}
/**
*
* - D3
*/
export function Chart({ chartType, data, config, width, height }: ChartProps) {
// 데이터가 없으면 placeholder 표시
if (!data || !data.labels.length || !data.datasets.length) {
return (
<div
className="flex items-center justify-center rounded-lg border-2 border-dashed border-gray-300 bg-gray-50"
style={{ width, height }}
>
<div className="text-center">
<div className="mb-2 text-4xl">📊</div>
<div className="text-sm font-medium text-gray-600"> </div>
<div className="mt-1 text-xs text-gray-500"> </div>
</div>
</div>
);
}
// 차트 타입에 따라 렌더링
switch (chartType) {
case "bar":
return <BarChart data={data} config={config} width={width} height={height} />;
2025-10-14 16:49:57 +09:00
case "horizontal-bar":
return <HorizontalBarChart data={data} config={config} width={width} height={height} />;
case "line":
return <LineChart data={data} config={config} width={width} height={height} />;
case "area":
return <AreaChart data={data} config={config} width={width} height={height} />;
case "pie":
return <PieChart data={data} config={config} width={width} height={height} isDonut={false} />;
case "donut":
return <PieChart data={data} config={config} width={width} height={height} isDonut={true} />;
case "stacked-bar":
return <StackedBarChart data={data} config={config} width={width} height={height} />;
case "combo":
2025-10-14 15:50:15 +09:00
return <ComboChart data={data} config={config} width={width} height={height} />;
default:
return (
<div
className="flex items-center justify-center rounded-lg border-2 border-dashed border-gray-300 bg-gray-50"
style={{ width, height }}
>
<div className="text-center">
<div className="mb-2 text-4xl"></div>
<div className="text-sm font-medium text-gray-600"> </div>
<div className="mt-1 text-xs text-gray-500">{chartType}</div>
</div>
</div>
);
}
}