Skip to content

Commit c1db0bf

Browse files
committed
implement light switch for the graph
1 parent 4394e71 commit c1db0bf

3 files changed

Lines changed: 31 additions & 9 deletions

File tree

src/components/Graph.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { getGroupColor } from "../utils";
77
import FullScreenButton from "./FullScreenButton.tsx";
88
import { useCallback, useEffect, useRef, useState } from "react";
99
import ResetViewButton from "./ResetViewButton.tsx";
10-
10+
import ThemeSwitch from "./ThemeSwitch.tsx";
1111
interface GraphProps {
1212
graphData: GraphData;
1313
width: number;
@@ -18,6 +18,7 @@ const Graph: React.FC<GraphProps> = ({ graphData, width, height }) => {
1818
const [isFullScreen, setIsFullScreen] = useState(false);
1919
const [graphWidth, setGraphWidth] = useState(width);
2020
const [graphHeight, setGraphHeight] = useState(height);
21+
const [switchOn, setSwitchOn] = useState<boolean>(false);
2122

2223
const fgRef = useRef<any>(null);
2324

@@ -102,6 +103,7 @@ const Graph: React.FC<GraphProps> = ({ graphData, width, height }) => {
102103
linkCurvature={0.3}
103104
linkOpacity={0.5}
104105
linkWidth={5}
106+
backgroundColor={switchOn ? "#ffffff" : "#000000"}
105107
nodeThreeObject={({ group }) => {
106108
const geometry =
107109
group === "" ? new THREE.BoxGeometry(8, 8, 8) : new THREE.SphereGeometry(5);
@@ -117,6 +119,7 @@ const Graph: React.FC<GraphProps> = ({ graphData, width, height }) => {
117119
/>
118120
<FullScreenButton isFullScreen={isFullScreen} setIsFullScreen={setIsFullScreen} />
119121
<ResetViewButton resetView={handleResetView} />
122+
<ThemeSwitch switchOn={switchOn} setSwitchOn={setSwitchOn} />
120123
<Legend />
121124
</Box>
122125
);

src/components/Layout.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,15 @@ export default function Layout({ children }: LayoutProps) {
1515
});
1616

1717
return (
18-
<Flex
19-
minHeight="100vh"
20-
display="flex"
21-
flexDirection="column"
22-
width="100%"
23-
overflowX="hidden" // Prevents horizontal overflow
24-
>
18+
<Flex minHeight="100vh" flexDirection="column" width="100%" overflowX="hidden">
2519
<Navbar />
2620
<Box
21+
as="main"
2722
flex="1"
2823
width={contentWidth}
2924
mx="auto"
3025
justifyContent="center"
31-
overflowX="hidden" // Prevents content overflow
26+
overflowX="hidden"
3227
>
3328
{children}
3429
</Box>

src/components/ThemeSwitch.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {Switch, Flex } from '@chakra-ui/react';
2+
import * as React from 'react';
3+
4+
type ThemeSwitchProps = {
5+
switchOn: boolean;
6+
setSwitchOn: (isSwitchOn: boolean) => void;
7+
}
8+
9+
const ThemeSwitch = ({ switchOn, setSwitchOn }: ThemeSwitchProps) => {
10+
const handleSwitchChange = (event: React. ChangeEvent<HTMLInputElement>) => {
11+
if (event.target.checked) {
12+
setSwitchOn(true);
13+
} else {
14+
setSwitchOn(false);
15+
}
16+
}
17+
return (
18+
<Flex position="absolute" left="10px" top="110px" padding="10px" flexDirection="column">
19+
<Switch isChecked={switchOn} onChange={handleSwitchChange} size='lg' />
20+
</Flex>
21+
);
22+
};
23+
24+
export default ThemeSwitch;

0 commit comments

Comments
 (0)