Skip to content

Commit e6d29b7

Browse files
committed
Resize chart manually since responsive not working
1 parent 74eabcc commit e6d29b7

File tree

3 files changed

+60
-57
lines changed

3 files changed

+60
-57
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"@fontsource/roboto": "^5.1.0",
3535
"@mui/icons-material": "^6.4.8",
3636
"@mui/material": "^6.4.8",
37-
"@mui/x-charts": "^7.28.0",
37+
"@mui/x-charts": "^7.29.1",
3838
"@mui/x-date-pickers": "^7.28.0",
3939
"@tanstack/react-query": "^4.36.1",
4040
"@trpc/client": "^10.45.2",

src/pages/students/[student_id]/goals/[goal_id]/benchmarks/[benchmark_id]/view.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
TrialData,
2323
valueFormatter,
2424
} from "@/types/global";
25-
import { useEffect, useState } from "react";
25+
import { useEffect, useRef, useState } from "react";
2626
import { CustomItemTooltip } from "@/components/benchmarks/CustomItemTooltip";
2727
import type { NextPageWithBreadcrumbs } from "@/pages/_app";
2828
import { useBreadcrumbsContext } from "@/components/design_system/breadcrumbs/BreadcrumbsContext";
@@ -32,6 +32,22 @@ import { Typography, Card, CardContent, Stack } from "@mui/material";
3232
const ViewBenchmarkPage: NextPageWithBreadcrumbs = () => {
3333
const { setBreadcrumbs } = useBreadcrumbsContext();
3434
const router = useRouter();
35+
const ref = useRef<HTMLDivElement>(null);
36+
const [width, setWidth] = useState(0);
37+
38+
function handleResize() {
39+
if (ref.current) {
40+
setWidth(ref.current.offsetWidth);
41+
}
42+
}
43+
44+
useEffect(() => {
45+
handleResize();
46+
window.addEventListener("resize", handleResize);
47+
return () => {
48+
window.removeEventListener("resize", handleResize);
49+
};
50+
}, []);
3551

3652
const benchmark_id = router.query?.benchmark_id as string;
3753

@@ -163,7 +179,7 @@ const ViewBenchmarkPage: NextPageWithBreadcrumbs = () => {
163179
<Typography variant="h1">Viewing Data for [Student name]</Typography>
164180

165181
<Card>
166-
<CardContent>
182+
<CardContent ref={ref}>
167183
{benchmark?.trials.map((trial) => (
168184
<div key={trial.trial_data_id}>{trial.notes}</div>
169185
))}
@@ -214,7 +230,7 @@ const ViewBenchmarkPage: NextPageWithBreadcrumbs = () => {
214230
valueFormatter(v as BulkPoint | SoloPoint),
215231
},
216232
]}
217-
width={500}
233+
width={Math.min(720, width)}
218234
height={300}
219235
>
220236
<LinePlot />

0 commit comments

Comments
 (0)