Skip to content

Commit 6467e72

Browse files
feature(ui) ทำ ui evevt count
1 parent c799ef7 commit 6467e72

File tree

2 files changed

+164
-8
lines changed

2 files changed

+164
-8
lines changed

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
11
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";
4+
import EventCount from "@/components/features/analytics/chart/EventCount";
45

56
export default function Analytics() {
67
return (
78
<div className="space-y-6">
9+
10+
{/* Top Section */}
811
<div className="grid grid-cols-[repeat(auto-fit,minmax(320px,1fr))] gap-6">
912
<AnalyticsView />
1013
</div>
1114

12-
13-
<div className="rounded-lg bg-[var(--color-white)] shadow-md p-6">
14-
<div className="rounded-lg bg-[var(--color-white)] shadow-md p-6 mt-6">
15-
<TimeBasedAlertDistribution />
15+
{/* Main 2 Columns Layout */}
16+
<div className="grid grid-cols-1 lg:grid-cols-[2fr,1fr] gap-6">
17+
18+
{/* LEFT SIDE */}
19+
<div className="space-y-6">
20+
<div className="rounded-lg bg-[var(--color-white)] shadow-md p-6">
21+
<TimeBasedAlertDistribution />
22+
</div>
23+
24+
<div className="rounded-lg bg-[var(--color-white)] shadow-md p-6">
25+
<AiAccuracyChart />
26+
</div>
1627
</div>
17-
</div>
1828

19-
20-
<div className="rounded-lg bg-[var(--color-white)] shadow-md p-6">
21-
<AiAccuracyChart />
29+
{/* RIGHT SIDE */}
30+
<div className="rounded-lg bg-[var(--color-white)] shadow-md p-6">
31+
<EventCount />
32+
</div>
2233
</div>
2334
</div>
2435
);
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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+
type EventCountChartProps = {
12+
height?: number;
13+
};
14+
15+
type ApexSeries = NonNullable<ApexOptions["series"]>;
16+
17+
const AXIS_LABEL_STYLE = {
18+
colors: "#6b7280",
19+
fontSize: "12px",
20+
};
21+
22+
// ===== CONFIG =====
23+
const MAX_VALUE = 300; // เปลี่ยน max แค่ตรงนี้ ที่เหลือจะตามให้เอง
24+
25+
// ===== DATA =====
26+
const EVENTS = [
27+
"Event 1",
28+
"Event 2",
29+
"Event 3",
30+
"Event 4",
31+
"Event 5",
32+
"Event 6",
33+
"Event 7",
34+
"Event 8",
35+
"Event 9",
36+
"Event 10",
37+
"Event 11",
38+
"Event 12",
39+
"Event 13",
40+
];
41+
42+
const EVENT_COUNTS = [80, 35, 70, 65, 20, 55, 75, 95, 60, 80, 30, 15, 267];
43+
44+
// ===== OPTIONS =====
45+
const chartOptions: ApexOptions = {
46+
chart: {
47+
type: "bar",
48+
stacked: true,
49+
toolbar: { show: false },
50+
background: "transparent",
51+
parentHeightOffset: 0,
52+
},
53+
54+
plotOptions: {
55+
bar: {
56+
horizontal: true,
57+
barHeight: "55%",
58+
borderRadius: 0,
59+
},
60+
},
61+
62+
dataLabels: {
63+
enabled: false,
64+
},
65+
66+
grid: {
67+
borderColor: "#e5e7eb",
68+
strokeDashArray: 4,
69+
xaxis: { lines: { show: true } },
70+
yaxis: { lines: { show: true } },
71+
},
72+
73+
xaxis: {
74+
position: "top",
75+
categories: EVENTS,
76+
min: 0,
77+
max: MAX_VALUE, // ใช้ MAX_VALUE ตรงนี้
78+
tickAmount: 10,
79+
labels: {
80+
style: AXIS_LABEL_STYLE,
81+
},
82+
axisBorder: { show: false },
83+
axisTicks: { show: false },
84+
},
85+
86+
yaxis: {
87+
labels: {
88+
style: AXIS_LABEL_STYLE,
89+
},
90+
},
91+
92+
tooltip: {
93+
theme: "light",
94+
y: {
95+
formatter: (val: number) => `${val}`,
96+
},
97+
},
98+
99+
legend: {
100+
show: false,
101+
},
102+
};
103+
104+
// series 1 = ม่วง (ค่าจริง) , series 2 = เทา (ส่วนที่เหลือถึง MAX_VALUE)
105+
const chartSeries: ApexSeries = [
106+
{
107+
name: "Event Count",
108+
data: EVENT_COUNTS,
109+
color: "#a0a1ff",
110+
},
111+
{
112+
name: "Remaining",
113+
data: EVENT_COUNTS.map((v) => MAX_VALUE - v), // เปลี่ยนจาก 100 → MAX_VALUE
114+
color: "#f3f4f6",
115+
},
116+
];
117+
118+
export default function EventCountChart({ height = 380 }: EventCountChartProps) {
119+
return (
120+
<div className="w-full rounded-3xl bg-white px-6 py-5 shadow-sm border border-[#e5e7f5]">
121+
<h2 className="text-lg font-bold text-[var(--color-primary,#111827)]">
122+
Event Count
123+
</h2>
124+
125+
<div className="w-full md:overflow-visible overflow-x-auto overflow-y-hidden">
126+
<div className="min-w-[700px] md:min-w-0">
127+
<ReactApexChart
128+
options={chartOptions}
129+
series={chartSeries}
130+
type="bar"
131+
height={height}
132+
/>
133+
</div>
134+
</div>
135+
136+
{/* Legend อธิบายความหมายสี — ล็อกกลางทุกหน้าจอ */}
137+
<div className="mt-4 flex flex-wrap items-center justify-center gap-3 text-xs text-slate-600">
138+
<div className="flex items-center gap-2">
139+
<span className="h-2.5 w-2.5 rounded-full bg-[#a0a1ff]" />
140+
<span className="whitespace-nowrap">Event Count</span>
141+
</div>
142+
</div>
143+
</div>
144+
);
145+
}

0 commit comments

Comments
 (0)