@@ -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