Skip to content

Commit b3c7cbb

Browse files
authored
[25. 05. 26 / TASK-175] Feature - 전체 통계 그래프 퍼블리싱 (#38)
1 parent 16cdc3a commit b3c7cbb

File tree

7 files changed

+101
-32
lines changed

7 files changed

+101
-32
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@tailwindcss/typography": "^0.5.16",
2828
"@tanstack/react-query": "^5.69.0",
2929
"chart.js": "^4.4.7",
30+
"chartjs-plugin-datalabels": "^2.2.0",
3031
"holy-loader": "^2.3.13",
3132
"next": "14.2.18",
3233
"qrcode.react": "^4.2.0",

pnpm-lock.yaml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/(auth-required)/main/components/Section/Graph.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
Tooltip,
1212
Legend,
1313
} from 'chart.js';
14+
import ChartDataLabels from 'chartjs-plugin-datalabels';
1415
import { useQuery } from '@tanstack/react-query';
1516
import { useEffect, useState } from 'react';
1617
import { COLORS, PATHS, SCREENS } from '@/constants';
@@ -19,8 +20,18 @@ import { PostDetailValue } from '@/types';
1920
import { useResponsive } from '@/hooks';
2021
import { postDetail } from '@/apis';
2122
import { convertDateToKST } from '@/utils/dateUtil';
23+
import { graphOptions } from '@/constants/graph.constant';
2224

23-
ChartJS.register(CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Legend);
25+
ChartJS.register(
26+
CategoryScale,
27+
LinearScale,
28+
PointElement,
29+
LineElement,
30+
Title,
31+
Tooltip,
32+
Legend,
33+
ChartDataLabels,
34+
);
2435

2536
const datasets = {
2637
backgroundColor: COLORS.TEXT.MAIN,
@@ -132,17 +143,7 @@ export const Graph = ({ id, releasedAt }: IProp) => {
132143
)}
133144
<Line
134145
data={datas || defaultData}
135-
options={{
136-
responsive: true,
137-
maintainAspectRatio: false,
138-
animation: false,
139-
interaction: { mode: 'nearest', intersect: false },
140-
plugins: { legend: { display: false } },
141-
scales: {
142-
x: { axis: 'x', grid: { color: COLORS.BORDER.SUB }, ticks: { precision: 0 } },
143-
y: { axis: 'y', grid: { color: COLORS.BORDER.SUB }, ticks: { precision: 0 } },
144-
},
145-
}}
146+
options={graphOptions}
146147
className="w-[100%_!important] h-[auto_!important] max-h-[300px]"
147148
/>
148149
</div>

src/app/(auth-required)/main/components/Summary/Modal.tsx

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
import { Line } from 'react-chartjs-2';
2+
import {
3+
Chart as ChartJS,
4+
CategoryScale,
5+
LinearScale,
6+
PointElement,
7+
LineElement,
8+
Title,
9+
Tooltip,
10+
Legend,
11+
} from 'chart.js';
12+
import ChartDataLabels from 'chartjs-plugin-datalabels';
213
import { Modal as Layout } from '@/components';
314
import { COLORS } from '@/constants';
15+
import { graphOptions } from '@/constants/graph.constant';
16+
17+
ChartJS.register(
18+
CategoryScale,
19+
LinearScale,
20+
PointElement,
21+
LineElement,
22+
Title,
23+
Tooltip,
24+
Legend,
25+
ChartDataLabels,
26+
);
427

528
export const table = {
629
totalViews: '전체 조회수 통계',
@@ -34,20 +57,13 @@ const defaultData = {
3457

3558
export const Modal = ({ name }: { name: keyof typeof table }) => {
3659
return (
37-
<Layout title={table[name]} className="w-[1100px] h-fit max-TBL:w-[800px] transition-all">
60+
<Layout
61+
title={table[name]}
62+
className="w-[1000px] max-w-full max-TBL:w-[700px] max-MBI:w-full transition-all overflow-hidden"
63+
>
3864
<Line
3965
data={defaultData}
40-
options={{
41-
responsive: true,
42-
maintainAspectRatio: false,
43-
animation: false,
44-
interaction: { mode: 'nearest', intersect: false },
45-
plugins: { legend: { display: false } },
46-
scales: {
47-
x: { axis: 'x', grid: { color: COLORS.BORDER.SUB }, ticks: { precision: 0 } },
48-
y: { axis: 'y', grid: { color: COLORS.BORDER.SUB }, ticks: { precision: 0 } },
49-
},
50-
}}
66+
options={graphOptions}
5167
className="w-full h-[auto_!important] max-h-[300px]"
5268
/>
5369
</Layout>
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
// import { useModal } from '@/hooks';
1+
import { useModal } from '@/hooks';
22
import { parseNumber } from '@/utils/numberUtil';
3-
// import { Modal, table } from './Modal';
4-
import { table } from './Modal';
3+
import { Modal, table } from './Modal';
54

65
interface IProp {
76
title: string;
@@ -15,13 +14,12 @@ const afterContent =
1514
'after:text-PRIMARY-SUB after:content-[attr(data-increasement)_"↑"] after:ml-2 after:text-ST3 max-TBL:after:text-ST4 transition-all';
1615

1716
export const SidebarContent = ({ title, content, increasement, prefix = '개', id }: IProp) => {
18-
// const { open } = useModal();
17+
const { open } = useModal();
1918

2019
return (
2120
<div
22-
// onClick={() => open(<Modal name={id} />)}
23-
// className="flex flex-col items-center justify-center gap-[10px] bg-BG-SUB w-[375px] hover:bg-BG-ALT cursor-pointer transition-all duration-300 p-4 rounded-[4px] h-full max-TBL:w-[280px]"
24-
className="flex flex-col items-center justify-center gap-[10px] bg-BG-SUB w-[375px] duration-300 p-4 rounded-[4px] h-full max-TBL:w-[280px]"
21+
onClick={() => open(<Modal name={id} />)}
22+
className="flex flex-col items-center justify-center gap-[10px] bg-BG-SUB w-[375px] hover:bg-BG-ALT cursor-pointer transition-all duration-300 p-4 rounded-[4px] h-full max-TBL:w-[280px]"
2523
>
2624
<span className="text-TEXT-ALT text-T4 transition-all max-TBL:text-T5">{title}</span>
2725
<span
@@ -31,7 +29,7 @@ export const SidebarContent = ({ title, content, increasement, prefix = '개', i
3129
>
3230
{parseNumber(content) + prefix}
3331
</span>
34-
{/* <span className="text-TEXT-ALT text-ST5">클릭해서 통계 그래프 보기</span> */}
32+
<span className="text-TEXT-ALT text-ST5">클릭해서 통계 그래프 보기</span>
3533
</div>
3634
);
3735
};

src/constants/graph.constant.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { COLORS } from './colors.constant';
2+
3+
export const graphOptions = {
4+
responsive: true,
5+
maintainAspectRatio: false,
6+
animation: false,
7+
interaction: { mode: 'nearest', intersect: false },
8+
layout: {
9+
padding: {
10+
top: 30,
11+
bottom: 10,
12+
left: 10,
13+
right: 10,
14+
},
15+
},
16+
plugins: {
17+
legend: { display: false },
18+
tooltip: { enabled: false },
19+
datalabels: {
20+
display: true,
21+
color: COLORS.TEXT.MAIN,
22+
backgroundColor: COLORS.BG.MAIN,
23+
borderColor: COLORS.BORDER.SUB,
24+
borderWidth: 1,
25+
borderRadius: 4,
26+
padding: 4,
27+
font: {
28+
size: 12,
29+
weight: 'normal',
30+
},
31+
formatter: (value: number) => value.toString(),
32+
anchor: 'end',
33+
align: 'top',
34+
},
35+
},
36+
scales: {
37+
x: { axis: 'x', grid: { color: COLORS.BORDER.SUB }, ticks: { precision: 0 } },
38+
y: { axis: 'y', grid: { color: COLORS.BORDER.SUB }, ticks: { precision: 0 } },
39+
},
40+
} as const;

src/constants/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export * from './colors.constant';
44
export * from './sizes.constant';
55
export * from './paths.constant';
66
export * from './fonts.constant';
7+
export * from './graph.constant';
78
export * from './env.constant';

0 commit comments

Comments
 (0)