-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathduration-chart.tsx
More file actions
79 lines (74 loc) · 2.71 KB
/
duration-chart.tsx
File metadata and controls
79 lines (74 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { format } from 'date-fns'
import { Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts'
import { Card } from '@/components/ui/card'
import { type TimeRange } from '@/components/time-range'
export interface DurationData {
period: string
avg_duration: number
p95_duration: number
}
interface DurationChartProps {
data: DurationData[]
timeRange: TimeRange
}
export function DurationChart({ data, timeRange }: DurationChartProps) {
let dateFormat = 'yyyy-MM-dd HH:mm'
if (timeRange === 'hourly') {
dateFormat = 'yyyy-MM-dd HH:mm'
} else if (timeRange === 'daily') {
dateFormat = 'd MMMM'
} else if (timeRange === 'weekly') {
dateFormat = 'd MMMM'
} else if (timeRange === 'monthly') {
dateFormat = 'MMMM'
}
return (
<ResponsiveContainer width="100%" height={350}>
<LineChart data={data}>
<XAxis
dataKey="period"
tickLine={false}
axisLine={false}
tickFormatter={(value) => format(new Date(value), dateFormat)}
/>
<YAxis
tickLine={false}
axisLine={false}
tickFormatter={(value) => `${value}s`}
/>
<Tooltip
content={({ active, payload }) => {
if (!active || !payload?.length) return null
return (
<Card className="p-2">
<div className="text-sm text-muted-foreground">
{format(new Date(payload[0].payload.period), dateFormat)}
</div>
<div className="font-bold">
Avg: {payload[0].payload.avg_duration}s
</div>
<div className="font-bold">
P95: {payload[0].payload.p95_duration}s
</div>
</Card>
)
}}
/>
<Line
type="monotone"
dataKey="avg_duration"
stroke="hsl(var(--chart-1))"
strokeWidth={2}
dot={false}
/>
<Line
type="monotone"
dataKey="p95_duration"
stroke="hsl(var(--chart-2))"
strokeWidth={2}
dot={false}
/>
</LineChart>
</ResponsiveContainer>
)
}