65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
'use client'
|
|
|
|
// apps/admin/src/components/charts/top-users-chart.tsx
|
|
// 유저별 사용량 Top 20 — Horizontal bar
|
|
|
|
import {
|
|
ResponsiveContainer,
|
|
BarChart,
|
|
Bar,
|
|
XAxis,
|
|
YAxis,
|
|
CartesianGrid,
|
|
Tooltip,
|
|
} from 'recharts'
|
|
import { Box } from '@mui/material'
|
|
import { d3roPalette, d3roFontMono } from '@d3ro/ui/theme'
|
|
|
|
interface TopUserRow {
|
|
user_id: string
|
|
name: string | null
|
|
total_count: number
|
|
feature_count: number
|
|
}
|
|
|
|
interface TopUsersChartProps {
|
|
data: TopUserRow[]
|
|
}
|
|
|
|
export function TopUsersChart({ data }: TopUsersChartProps): React.ReactElement {
|
|
const chartData = data.map(row => ({
|
|
name: row.name ?? row.user_id.substring(0, 8),
|
|
total: row.total_count,
|
|
features: row.feature_count,
|
|
}))
|
|
|
|
return (
|
|
<Box sx={{ width: '100%', height: Math.max(250, data.length * 28) }}>
|
|
<ResponsiveContainer>
|
|
<BarChart data={chartData} layout="vertical">
|
|
<CartesianGrid strokeDasharray="3 3" stroke={d3roPalette.border.subtle} />
|
|
<XAxis
|
|
type="number"
|
|
tick={{ fill: d3roPalette.text.muted, fontFamily: d3roFontMono, fontSize: 11 }}
|
|
/>
|
|
<YAxis
|
|
type="category"
|
|
dataKey="name"
|
|
width={100}
|
|
tick={{ fill: d3roPalette.text.muted, fontFamily: d3roFontMono, fontSize: 11 }}
|
|
/>
|
|
<Tooltip
|
|
contentStyle={{
|
|
background: d3roPalette.bg.card,
|
|
border: `1px solid ${d3roPalette.border.default}`,
|
|
fontFamily: d3roFontMono,
|
|
fontSize: 11,
|
|
color: d3roPalette.text.primary,
|
|
}}
|
|
/>
|
|
<Bar dataKey="total" fill={d3roPalette.accent.main} name="Total Calls" />
|
|
</BarChart>
|
|
</ResponsiveContainer>
|
|
</Box>
|
|
)
|
|
}
|