Skip to content

Commit da4cc55

Browse files
committed
import linegraph in singlegradeinfo
please
1 parent 120a8e7 commit da4cc55

File tree

6 files changed

+76
-38
lines changed

6 files changed

+76
-38
lines changed

Diff for: package-lock.json

+10-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@mui/material": "^6.1.2",
2424
"@next/third-parties": "^14.2.15",
2525
"@vercel/speed-insights": "^1.0.12",
26-
"apexcharts": "^4.0.0",
26+
"apexcharts": "^4.4.0",
2727
"autoprefixer": "^10.4.2",
2828
"autosuggest-highlight": "^3.3.4",
2929
"css-loader": "^7.1.2",
@@ -38,7 +38,7 @@
3838
"postcss": "^8.4.6",
3939
"postcss-loader": "^8.1.1",
4040
"react": "^18.2.0",
41-
"react-apexcharts": "^1.6.0",
41+
"react-apexcharts": "^1.7.0",
4242
"react-docgen-typescript": "^2.2.2",
4343
"react-dom": "^18.2.0",
4444
"react-resizable-panels": "^2.1.4",

Diff for: src/components/common/SingleGradesInfo/singleGradesInfo.tsx

+27
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Skeleton } from '@mui/material';
22
import React from 'react';
33

44
import BarGraph from '@/components/graph/BarGraph/barGraph';
5+
import LineGraph from '@/components/graph/LineGraph/lineGraph';
56
import {
67
type SearchQuery,
78
searchQueryLabel,
@@ -14,6 +15,24 @@ function convertNumbersToPercents(distribution: GradesType): number[] {
1415
(frequencyOfLetterGrade) => (frequencyOfLetterGrade / total) * 100,
1516
);
1617
}
18+
function getRecentSemesters() {
19+
const recentSemesters: string[] = [];
20+
const today = new Date();
21+
const mm = today.getMonth() + 1;
22+
let yyyy = today.getFullYear();
23+
let season = mm <= 5 ? 'S' : 'F';
24+
25+
for (let i = 6; i >= 1; i--) {
26+
if (season === 'S') {
27+
yyyy -= 1;
28+
season = 'F';
29+
} else {
30+
season = 'S';
31+
}
32+
recentSemesters.push(yyyy.toString().substring(2) + season);
33+
}
34+
return recentSemesters;
35+
}
1736

1837
type Props = {
1938
title?: string;
@@ -42,6 +61,10 @@ function SingleGradesInfo({ title, course, grades }: Props) {
4261
}
4362

4463
const percents = convertNumbersToPercents(grades.data);
64+
const recentSemesters = getRecentSemesters();
65+
const gpaValues = [
66+
4, 4, 3.67, 3.33, 3, 2.67, 2.33, 2, 1.67, 1.33, 1, 0.67, 0,
67+
];
4568

4669
return (
4770
<div className="p-2">
@@ -88,6 +111,10 @@ function SingleGradesInfo({ title, course, grades }: Props) {
88111
<b>{grades.data.gpa === -1 ? 'None' : grades.data.gpa.toFixed(3)}</b>
89112
</p>
90113
</div>
114+
<div className="h-64">
115+
<LineGraph course ={recentSemesters}
116+
gpa={gpaValues} />
117+
</div>
91118
</div>
92119
);
93120
}

Diff for: src/components/graph/LineGraph/lineGraph.tsx

+36-25
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
import { Skeleton, ToggleButton, ToggleButtonGroup } from '@mui/material';
2-
import type { ApexOptions } from 'apexcharts';
3-
import React, { useState, useEffect } from 'react';
2+
import React, { useEffect, useState } from 'react';
43
import Chart from 'react-apexcharts';
54

6-
import { type SearchQuery, searchQueryLabel } from '@/modules/SearchQuery/SearchQuery';
5+
import {
6+
type SearchQuery,
7+
searchQueryLabel,
8+
} from '@/modules/SearchQuery/SearchQuery';
79
import type { GenericFetchedData } from '@/pages/dashboard/index';
10+
811
export type GPATrendType = {
9-
years: string[];
10-
gpa_values: number[];
11-
};
12+
season: string[];
13+
years: string[];
14+
gpa: number[];
15+
};
1216

1317
type Props = {
14-
course: SearchQuery;
18+
recentSemesters: SearchQuery;
1519
gpaTrend: GenericFetchedData<GPATrendType>;
1620
};
1721

18-
function GPATrendGraph({ course, gpaTrend }: Props) {
22+
function LineGraph({ recentSemesters, gpaTrend }: Props) {
1923
const [chartType, setChartType] = useState<'line' | 'bar'>('line');
2024
const [chartData, setChartData] = useState<{
2125
options: {
@@ -97,36 +101,43 @@ function GPATrendGraph({ course, gpaTrend }: Props) {
97101
},
98102
},
99103
},
100-
series: [{
101-
name: '',
102-
data: [],
103-
}],
104+
series: [
105+
{
106+
name: '',
107+
data: [],
108+
},
109+
],
104110
});
105111

106112
useEffect(() => {
107113
if (gpaTrend.state === 'done') {
108114
setChartData({
109115
options: {
110116
...chartData.options,
111-
xaxis: {
112-
categories: gpaTrend.data.years,
113-
labels: { rotate: -45 }
117+
xaxis: {
118+
categories: gpaTrend.data.season,
119+
labels: { rotate: -45 },
114120
},
115121
},
116-
series: [{
117-
name: searchQueryLabel(course),
118-
data: gpaTrend.data.gpa_values,
119-
}],
122+
series: [
123+
{
124+
name: searchQueryLabel(recentSemesters),
125+
data: gpaTrend.data.gpa,
126+
},
127+
],
120128
});
121129
}
122-
}, [gpaTrend, course]);
130+
}, [gpaTrend, recentSemesters]);
123131

124-
const handleChartToggle = (_event: React.MouseEvent<HTMLElement>, newChartType: 'line' | 'bar' | null) => {
132+
const handleChartToggle = (
133+
_event: React.MouseEvent<HTMLElement>,
134+
newChartType: 'line' | 'bar' | null,
135+
) => {
125136
if (newChartType) {
126137
setChartType(newChartType);
127138
}
128139
};
129-
140+
130141
if (typeof gpaTrend === 'undefined' || gpaTrend.state === 'error') {
131142
return null;
132143
}
@@ -146,8 +157,8 @@ function GPATrendGraph({ course, gpaTrend }: Props) {
146157
onChange={handleChartToggle}
147158
className="mb-2"
148159
>
149-
<ToggleButton value="bar">📊</ToggleButton>
150-
<ToggleButton value="line">📈</ToggleButton>
160+
<ToggleButton value="bar"></ToggleButton>
161+
<ToggleButton value="line"></ToggleButton>
151162
</ToggleButtonGroup>
152163
<div className="h-64">
153164
<Chart
@@ -161,4 +172,4 @@ function GPATrendGraph({ course, gpaTrend }: Props) {
161172
);
162173
}
163174

164-
export default GPATrendGraph;
175+
export default LineGraph;

Diff for: src/pages/dashboard/index.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,4 @@ export const Dashboard: NextPage<{ pageTitle: string }> = ({
943943
);
944944
};
945945

946-
947-
948946
export default Dashboard;

Diff for: tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"verbatimModuleSyntax": true
2626
},
2727
"include": ["src", "next-env.d.ts", "**/*.ts", "**/*.tsx", "/**/**/*/.tsx"],
28-
"exclude": ["node_modules", "**/tailwind.config.js"],
28+
"exclude": ["node_modules"],
2929
"ts-node": {
3030
"transpileOnly": true,
3131
"moduleTypes": {

0 commit comments

Comments
 (0)