✨ 새로운 기능: - 드래그 앤 드롭 대시보드 설계 도구 - SQL 쿼리 에디터 및 실시간 실행 - Recharts 기반 차트 컴포넌트 (Bar, Pie, Line) - 차트 데이터 매핑 및 설정 UI - 요소 이동, 크기 조절, 삭제 기능 - 레이아웃 저장 기능 📦 추가된 컴포넌트: - DashboardDesigner: 메인 설계 도구 - QueryEditor: SQL 쿼리 작성 및 실행 - ChartConfigPanel: 차트 설정 패널 - ChartRenderer: 실제 차트 렌더링 - CanvasElement: 드래그 가능한 캔버스 요소 🔧 기술 스택: - Recharts 라이브러리 추가 - TypeScript 타입 정의 완비 - 독립적 컴포넌트 구조로 설계 🎯 접속 경로: /admin/dashboard
104 lines
2.5 KiB
TypeScript
104 lines
2.5 KiB
TypeScript
'use client';
|
|
|
|
import React from 'react';
|
|
import {
|
|
LineChart,
|
|
Line,
|
|
XAxis,
|
|
YAxis,
|
|
CartesianGrid,
|
|
Tooltip,
|
|
Legend,
|
|
ResponsiveContainer
|
|
} from 'recharts';
|
|
import { ChartConfig } from '../types';
|
|
|
|
interface LineChartComponentProps {
|
|
data: any[];
|
|
config: ChartConfig;
|
|
width?: number;
|
|
height?: number;
|
|
}
|
|
|
|
/**
|
|
* 꺾은선 차트 컴포넌트
|
|
* - Recharts LineChart 사용
|
|
* - 다중 라인 지원
|
|
*/
|
|
export function LineChartComponent({ data, config, width = 250, height = 200 }: LineChartComponentProps) {
|
|
const {
|
|
xAxis = 'x',
|
|
yAxis = 'y',
|
|
colors = ['#3B82F6', '#EF4444', '#10B981', '#F59E0B'],
|
|
title,
|
|
showLegend = true
|
|
} = config;
|
|
|
|
// Y축에 해당하는 모든 키 찾기 (그룹핑된 데이터의 경우)
|
|
const yKeys = data.length > 0
|
|
? Object.keys(data[0]).filter(key => key !== xAxis && typeof data[0][key] === 'number')
|
|
: [yAxis];
|
|
|
|
return (
|
|
<div className="w-full h-full p-2">
|
|
{title && (
|
|
<div className="text-center text-sm font-semibold text-gray-700 mb-2">
|
|
{title}
|
|
</div>
|
|
)}
|
|
|
|
<ResponsiveContainer width="100%" height="100%">
|
|
<LineChart
|
|
data={data}
|
|
margin={{
|
|
top: 5,
|
|
right: 30,
|
|
left: 20,
|
|
bottom: 5,
|
|
}}
|
|
>
|
|
<CartesianGrid strokeDasharray="3 3" stroke="#f0f0f0" />
|
|
<XAxis
|
|
dataKey={xAxis}
|
|
tick={{ fontSize: 12 }}
|
|
stroke="#666"
|
|
/>
|
|
<YAxis
|
|
tick={{ fontSize: 12 }}
|
|
stroke="#666"
|
|
/>
|
|
<Tooltip
|
|
contentStyle={{
|
|
backgroundColor: 'white',
|
|
border: '1px solid #ccc',
|
|
borderRadius: '4px',
|
|
fontSize: '12px'
|
|
}}
|
|
formatter={(value: any, name: string) => [
|
|
typeof value === 'number' ? value.toLocaleString() : value,
|
|
name
|
|
]}
|
|
/>
|
|
{showLegend && yKeys.length > 1 && (
|
|
<Legend
|
|
wrapperStyle={{ fontSize: '12px' }}
|
|
/>
|
|
)}
|
|
|
|
{yKeys.map((key, index) => (
|
|
<Line
|
|
key={key}
|
|
type="monotone"
|
|
dataKey={key}
|
|
stroke={colors[index % colors.length]}
|
|
strokeWidth={2}
|
|
dot={{ r: 3 }}
|
|
activeDot={{ r: 5 }}
|
|
/>
|
|
))}
|
|
</LineChart>
|
|
</ResponsiveContainer>
|
|
</div>
|
|
);
|
|
}
|