Skip to content

Commit d8589b5

Browse files
committed
feat: add ChartFallback component for handling insufficient chart data
1 parent 81531db commit d8589b5

File tree

2 files changed

+68
-40
lines changed

2 files changed

+68
-40
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use client';
2+
3+
import { motion } from 'framer-motion';
4+
import { AlertTriangle } from 'lucide-react';
5+
import React from 'react';
6+
7+
const ChartFallback = () => {
8+
return (
9+
<motion.div
10+
initial={{ opacity: 0, y: 10 }}
11+
animate={{ opacity: 1, y: 0 }}
12+
transition={{ duration: 0.5, ease: 'easeOut' }}
13+
className="flex flex-col items-center justify-center h-[300px] border border-dashed border-gray-300 rounded-lg text-gray-500 px-4 text-center"
14+
>
15+
<AlertTriangle className="w-6 h-6 mb-2 text-yellow-500 animate-pulse" />
16+
<p className="text-sm font-medium">
17+
3일 이상의 통계가 쌓여야 차트를 확인할 수 있어요.
18+
</p>
19+
</motion.div>
20+
);
21+
};
22+
23+
export default ChartFallback;

src/views/(developer)/wepp-dashboard/sections/wepp-dashboard-chart/index.tsx

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
SUB_FILTERS,
2323
} from './utils';
2424
import { FilterType, SubFilterType } from './types';
25+
import ChartFallback from './chart-fallback';
2526

2627
// ----------------------------------------------------------------------
2728

@@ -110,49 +111,53 @@ const WeppDashboardChart = () => {
110111
)}
111112
</div>
112113

113-
<ResponsiveContainer width="100%" height={300}>
114-
<AreaChart data={chartData}>
115-
<defs>
114+
{chartData.length <= 3 ? (
115+
<ChartFallback />
116+
) : (
117+
<ResponsiveContainer width="100%" height={300}>
118+
<AreaChart data={chartData}>
119+
<defs>
120+
{keysByFilter.map((key) => (
121+
<linearGradient
122+
id={`fill_${key}`}
123+
key={key}
124+
x1="0"
125+
y1="0"
126+
x2="0"
127+
y2="1"
128+
>
129+
<stop
130+
offset="5%"
131+
stopColor={LINE_COLORS[key]}
132+
stopOpacity={0.7}
133+
/>
134+
<stop
135+
offset="95%"
136+
stopColor={LINE_COLORS[key]}
137+
stopOpacity={0.1}
138+
/>
139+
</linearGradient>
140+
))}
141+
</defs>
142+
143+
<XAxis dataKey="date" />
144+
<YAxis allowDecimals={false} />
145+
<Tooltip content={<CustomTooltip />} />
146+
<Legend content={<CustomLegend />} />
147+
116148
{keysByFilter.map((key) => (
117-
<linearGradient
118-
id={`fill_${key}`}
149+
<Area
119150
key={key}
120-
x1="0"
121-
y1="0"
122-
x2="0"
123-
y2="1"
124-
>
125-
<stop
126-
offset="5%"
127-
stopColor={LINE_COLORS[key]}
128-
stopOpacity={0.7}
129-
/>
130-
<stop
131-
offset="95%"
132-
stopColor={LINE_COLORS[key]}
133-
stopOpacity={0.1}
134-
/>
135-
</linearGradient>
151+
type="monotone"
152+
dataKey={key}
153+
stroke={LINE_COLORS[key]}
154+
fill={`url(#fill_${key})`}
155+
strokeWidth={2}
156+
/>
136157
))}
137-
</defs>
138-
139-
<XAxis dataKey="date" />
140-
<YAxis allowDecimals={false} />
141-
<Tooltip content={<CustomTooltip />} />
142-
<Legend content={<CustomLegend />} />
143-
144-
{keysByFilter.map((key) => (
145-
<Area
146-
key={key}
147-
type="monotone"
148-
dataKey={key}
149-
stroke={LINE_COLORS[key]}
150-
fill={`url(#fill_${key})`}
151-
strokeWidth={2}
152-
/>
153-
))}
154-
</AreaChart>
155-
</ResponsiveContainer>
158+
</AreaChart>
159+
</ResponsiveContainer>
160+
)}
156161
</Section>
157162
);
158163
};

0 commit comments

Comments
 (0)