Skip to content

Commit f8bdf99

Browse files
authored
Merge branch 'module/analytics' into feature/ui-event-count
2 parents ff007ab + 6daf0d1 commit f8bdf99

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed

client/my-app/src/app/(with-layout)/analytics/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import AnalyticsView from "@/components/features/analytics/AnalyticsView";
22
import TimeBasedAlertDistribution from "@/components/features/analytics/chart/TimeBasedAlertDistribution";
33
import AiAccuracyChart from "@/components/features/analytics/chart/AiAccuracyChart";
44
import EventCount from "@/components/features/analytics/chart/EventCount";
5+
import AlertResolutionRate from "@/components/features/analytics/chart/AlertResolutionRate";
56

67
export default function Analytics() {
78
return (
@@ -31,6 +32,10 @@ export default function Analytics() {
3132
<EventCount />
3233
</div>
3334
</div>
35+
36+
<div className="rounded-lg bg-[var(--color-white)] shadow-md p-6">
37+
<AlertResolutionRate />
38+
</div>
3439
</div>
3540
);
3641
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
"use client";
2+
3+
import React from "react";
4+
import dynamic from "next/dynamic";
5+
import type { ApexOptions } from "apexcharts";
6+
7+
const ReactApexChart = dynamic(() => import("react-apexcharts"), {
8+
ssr: false,
9+
});
10+
11+
// props เผื่อรองรับ custom height
12+
type Props = {
13+
height?: number;
14+
};
15+
16+
const AXIS_LABEL_STYLE = {
17+
colors: "#6b7280",
18+
fontSize: "12px",
19+
};
20+
21+
22+
const data = [
23+
{ month: "January", total: 65, closed: 80 },
24+
{ month: "February", total: 90, closed: 60 },
25+
{ month: "March", total: 55, closed: 10 },
26+
{ month: "April", total: 78, closed: 50 },
27+
{ month: "May", total: 50, closed: 45 },
28+
{ month: "June", total: 42, closed: 40 },
29+
{ month: "July", total: 67, closed: 20 },
30+
{ month: "August", total: 40, closed: 55 },
31+
{ month: "September", total: 52, closed: 90 },
32+
{ month: "October", total: 64, closed: 78 },
33+
{ month: "November", total: 48, closed: 25 },
34+
{ month: "December", total: 88, closed: 15 },
35+
];
36+
37+
38+
const chartSeries = [
39+
{ name: "Total Alerts", data: data.map((d) => d.total) },
40+
{ name: "Closed Alerts", data: data.map((d) => d.closed) },
41+
];
42+
43+
44+
const chartOptions: ApexOptions = {
45+
chart: {
46+
type: "line",
47+
zoom: { enabled: false },
48+
toolbar: { show: false },
49+
background: "transparent",
50+
parentHeightOffset: 0,
51+
},
52+
53+
stroke: {
54+
curve: "straight",
55+
width: 3,
56+
},
57+
58+
markers: {
59+
size: 5,
60+
strokeWidth: 2,
61+
colors: ["#ffffff"],
62+
strokeColors: ["#3b82f6", "#ef4444"],
63+
hover: { size: 7 },
64+
},
65+
66+
colors: ["#3b82f6", "#ef4444"],
67+
68+
grid: {
69+
borderColor: "#e5e7eb",
70+
strokeDashArray: 4,
71+
xaxis: { lines: { show: true } },
72+
yaxis: { lines: { show: true } },
73+
},
74+
75+
xaxis: {
76+
categories: data.map((d) => d.month),
77+
labels: { style: AXIS_LABEL_STYLE },
78+
axisBorder: { show: false },
79+
axisTicks: { show: false },
80+
},
81+
82+
yaxis: {
83+
min: 0,
84+
max: 100,
85+
tickAmount: 5,
86+
labels: { style: AXIS_LABEL_STYLE },
87+
},
88+
89+
tooltip: {
90+
theme: "light",
91+
shared: true,
92+
intersect: false,
93+
},
94+
95+
legend: {
96+
show: false,
97+
},
98+
};
99+
100+
101+
export default function AlertResolutionRate({ height = 250 }: Props) {
102+
return (
103+
<div className="w-full rounded-3xl bg-white px-6 py-5 shadow-sm border border-[#e5e7f5]">
104+
<div className="mb-3 flex items-center justify-between">
105+
<h2 className="text-lg font-bold text-[var(--color-primary,#111827)]">
106+
Alert Resolution Rate
107+
</h2>
108+
</div>
109+
110+
{/* Chart */}
111+
<div className="w-full">
112+
<ReactApexChart
113+
options={chartOptions}
114+
series={chartSeries}
115+
type="line"
116+
height={height}
117+
/>
118+
</div>
119+
120+
{/* Legend */}
121+
<div className="mt-4 flex flex-wrap items-center justify-center gap-3 text-xs text-slate-600">
122+
<div className="flex items-center gap-2">
123+
<span className="h-2.5 w-2.5 rounded-full bg-[#3b82f6]" />
124+
<span className="whitespace-nowrap">Total Alerts</span>
125+
</div>
126+
<div className="flex items-center gap-2">
127+
<span className="h-2.5 w-2.5 rounded-full bg-[#ef4444]" />
128+
<span className="whitespace-nowrap">Closed Alerts</span>
129+
</div>
130+
</div>
131+
</div>
132+
);
133+
}

0 commit comments

Comments
 (0)