Skip to content

Commit 94af505

Browse files
committed
added comments to components
1 parent 24a9f8a commit 94af505

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/components/SortingVisualizer.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,26 @@ const SortingVisualizer: React.FC<ArrayProps> = ({ arraysInfo }) => {
2020
const [array, setArray] = useState<number[]>([]);
2121
const [algorithm, setAlgorithm] = useState<string>("");
2222
const [isSorting, setIsSorting] = useState(false);
23-
23+
// function load new array on component load
2424
useEffect(() => {
2525
setArray(generateRandomArray());
2626
}, []);
2727

28+
// function to set a new array
2829
const resetArray = () => {
2930
if (!isSorting) {
3031
setArray(generateRandomArray());
3132
}
3233
};
3334

35+
// function to handle if algorithm changes
3436
const handleChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
3537
setAlgorithm(e.target.value);
3638
};
3739

40+
// function to handle what happens on submit.
41+
// in our case we will get the sorting animations and then
42+
// color the nodes accordingly
3843
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
3944
e.preventDefault();
4045
if (!algorithm || isSorting) return;
@@ -67,6 +72,7 @@ const SortingVisualizer: React.FC<ArrayProps> = ({ arraysInfo }) => {
6772
</div>
6873

6974
<div style={{ maxWidth: "400px", width: "100%" }}>
75+
{/* importing algorithm form component with sorting specific values */}
7076
<AlgorithmForm
7177
value={algorithm}
7278
options={["Merge", "Bubble", "Selection", "Insertion"]}
@@ -79,6 +85,7 @@ const SortingVisualizer: React.FC<ArrayProps> = ({ arraysInfo }) => {
7985

8086
<Container className="mt-5">
8187
<h2 className="text-center mb-4">About Sorting Algorithms</h2>
88+
{/* importing algorithm form component with sorting specific values */}
8289
<AlgorithmInfo info={arraysInfo} />
8390
</Container>
8491
</Container>

src/components/TraversalVisualizer.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const TraversalVisualizer: React.FC<GraphProps> = ({ graphsInfo }) => {
2323
const [algorithm, setAlgorithm] = useState("");
2424
const [isSorting, setIsSorting] = useState(false);
2525

26+
// function to generate a new matrix/grid
2627
const generateMatrix = () => {
2728
const n = 30; // nxn array
2829
const newMatrix = Array.from({ length: n }, () => Array(50).fill(" ")); // generate array
@@ -69,10 +70,12 @@ const TraversalVisualizer: React.FC<GraphProps> = ({ graphsInfo }) => {
6970
return newMatrix;
7071
};
7172

73+
// function that gets called on component load
7274
useEffect(() => {
7375
setMatrix(generateMatrix());
7476
}, []);
7577

78+
// function to reset the matrix
7679
const resetMatrix = () => {
7780
if (!isSorting) {
7881
setAlgorithm("");
@@ -81,10 +84,13 @@ const TraversalVisualizer: React.FC<GraphProps> = ({ graphsInfo }) => {
8184
}
8285
};
8386

87+
// function to handle if algorithm changes
8488
const handleChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
8589
setAlgorithm(e.target.value);
8690
};
87-
91+
// function to handle what happens on submit.
92+
// in our case we will get the paths and expanded nodes and then
93+
// color the nodes accordingly
8894
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
8995
e.preventDefault();
9096
if (!algorithm || isSorting) return;
@@ -163,7 +169,9 @@ const TraversalVisualizer: React.FC<GraphProps> = ({ graphsInfo }) => {
163169
</div>
164170
))}
165171
</div>
172+
{/* importing legend for our graph/matrix/grid */}
166173
<GraphLengend />
174+
{/* importing algorithm form component with sorting specific values */}
167175
<AlgorithmForm
168176
value={algorithm}
169177
options={["Astar", "BFS", "DFS", "UCS"]}
@@ -174,6 +182,7 @@ const TraversalVisualizer: React.FC<GraphProps> = ({ graphsInfo }) => {
174182
/>
175183
<Container className="mt-5">
176184
<h2 className="text-center mb-4">About Traversal Algorithms</h2>
185+
{/* importing algorithm info component with traversal specific values */}
177186
<AlgorithmInfo info={graphsInfo} />
178187
</Container>
179188
</div>

0 commit comments

Comments
 (0)