Skip to content

Commit 3aae660

Browse files
committed
line graph shows up in blue, toggle button ok, needs to parse correct data.
1 parent 887987a commit 3aae660

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

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

+34-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Skeleton } from '@mui/material';
2-
import React from 'react';
1+
import { Skeleton, ToggleButton, ToggleButtonGroup } from '@mui/material';
2+
import React, { useState } from 'react';
33

44
import BarGraph from '@/components/graph/BarGraph/barGraph';
55
import LineGraph from '@/components/graph/LineGraph/lineGraph';
@@ -42,6 +42,16 @@ type Props = {
4242
};
4343

4444
function SingleGradesInfo({ title, course, grades }: Props) {
45+
const [chartType, setChartType] = useState<'line' | 'bar'>('line');
46+
47+
const handleChartToggle = (
48+
event: React.MouseEvent<HTMLElement>,
49+
newChartType: 'line' | 'bar'
50+
) => {
51+
if (newChartType !== null) {
52+
setChartType(newChartType);
53+
}
54+
};
4555
if (typeof grades === 'undefined' || grades.state === 'error') return null;
4656
if (grades.state === 'loading') {
4757
return (
@@ -59,6 +69,26 @@ function SingleGradesInfo({ title, course, grades }: Props) {
5969
const gpaValues = [4,4,3.67,3.33,3,2.67,2.33,2,1.67,1.33,1,0.67,0];
6070

6171
return (
72+
73+
<div>
74+
{/* Toggle Button to switch chart type */}
75+
<div className="flex justify-end mb-4 pr-2">
76+
<ToggleButtonGroup
77+
value={chartType}
78+
exclusive
79+
onChange={handleChartToggle}
80+
size = "small"
81+
orientation= "vertical"
82+
aria-label="chart type">
83+
84+
<ToggleButton value="line" aria-label="line chart">
85+
Line
86+
</ToggleButton>
87+
<ToggleButton value="bar" aria-label="bar chart">
88+
Bar
89+
</ToggleButton>
90+
</ToggleButtonGroup>
91+
</div>
6292
<div className="p-2">
6393
<div className="h-64">
6494
<BarGraph
@@ -83,7 +113,9 @@ function SingleGradesInfo({ title, course, grades }: Props) {
83113
/>
84114
</div>
85115
</div>
116+
</div>
86117
);
87118
}
88119

120+
89121
export default SingleGradesInfo;

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

+4-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Skeleton, ToggleButton, ToggleButtonGroup } from '@mui/material';
1+
import { Skeleton } from '@mui/material';
22
import dynamic from 'next/dynamic';
33
import React, { useEffect, useState } from 'react';
44

@@ -26,7 +26,6 @@ type Props = {
2626
};
2727

2828
function LineGraph({ gpaTrend, chartTitle, xAxisLabels, yAxisFormatter, tooltipFormatter, series }: Props): React.ReactNode {
29-
const [chartType, setChartType] = useState<'line' | 'bar'>('line');
3029
const [chartData, setChartData] = useState<{
3130
options: {
3231
chart: {
@@ -178,20 +177,11 @@ function LineGraph({ gpaTrend, chartTitle, xAxisLabels, yAxisFormatter, tooltipF
178177
);
179178
}
180179
}
181-
182-
const handleChartToggle = (_event: React.MouseEvent<HTMLElement>, newChartType: 'line' | 'bar' | null) => {
183-
if (newChartType) setChartType(newChartType);
184-
};
180+
const chartType = 'line'; // Define the chart type
185181

186182
return (
187-
<div className="p-2">
188-
<ToggleButtonGroup value={chartType} exclusive onChange={handleChartToggle} className="mb-2">
189-
<ToggleButton value="bar" />
190-
<ToggleButton value="line" />
191-
</ToggleButtonGroup>
192-
<div className="h-64">
193-
<Chart options={chartData.options} series={chartData.series} type={chartType} height={250} />
194-
</div>
183+
<div className="h-64">
184+
<Chart options={chartData.options} series={chartData.series} type={chartType} height={250} />
195185
</div>
196186
);
197187
}

0 commit comments

Comments
 (0)