@@ -31,26 +31,10 @@ class PathVisualizer extends Component {
3131
3232 // creates the grid when the component is mounted
3333 componentDidMount ( ) {
34- // this.setState({
35- // startNode: [START_NODE_ROW, START_NODE_COL],
36- // finishNode: [FINISH_NODE_ROW, FINISH_NODE_COL]
37- // });
3834 let grid = getInitialGrid ( ) ;
39- this . setState ( { grid } ) ;
40- //window.addEventListener("resize", this.updateDimesions);
35+ this . setState ( { grid } ) ;
4136 }
4237
43- // updateDimesions = () => {
44- // console.log("update dimesions:- " + "width: " + window.screen.width + " height: " + window.screen.height);
45- // console.log("updated width: " + (28 / 1280) * window.screen.width);
46- // console.log("updated height: " + (28 / 720) * window.screen.height);
47- // const updatedWidth = (28 / 1280) * window.screen.width;
48- // const updatedHeight = (28 / 720) * window.screen.height;
49- // //footer.style.setProperty('--footer-color', input.value)
50- // document.querySelector('node').style.setProperty('--width', updatedWidth);
51- // document.querySelector('node').style.setProperty('--height', updatedHeight)
52- // }
53-
5438 toggle = ( ) => {
5539 this . setState ( { tooltipOpen : ! this . state . tooltipOpen } ) ;
5640 }
@@ -115,11 +99,11 @@ class PathVisualizer extends Component {
11599 visualizeDijkstra = ( ) => {
116100 if ( this . state . isVisualizing )
117101 return ;
118- const { grid, startNode_Pos, finishNode_Pos } = this . state ;
119- // const startNode = grid[START_NODE_ROW][START_NODE_COL ];
120- const startNode = grid [ startNode_Pos [ 0 ] ] [ startNode_Pos [ 1 ] ] ;
121- // const finishNode = grid[FINISH_NODE_ROW][FINISH_NODE_COL ];
122- const finishNode = grid [ finishNode_Pos [ 0 ] ] [ finishNode_Pos [ 1 ] ] ;
102+ const { grid, startNode_Pos, finishNode_Pos } = this . state ;
103+ const start_X = startNode_Pos [ 0 ] , start_Y = startNode_Pos [ 1 ] ;
104+ const startNode = grid [ start_X ] [ start_Y ] ;
105+ const finish_X = finishNode_Pos [ 0 ] , finish_Y = finishNode_Pos [ 1 ] ;
106+ const finishNode = grid [ finish_X ] [ finish_Y ] ;
123107 try {
124108 const visitedNodesInOrder = dijkstra ( grid , startNode , finishNode ) ;
125109 const nodesInShortestPathOrder = getNodesInShortestPathOrder ( finishNode ) ;
@@ -143,12 +127,11 @@ class PathVisualizer extends Component {
143127 visualizeDFS = ( ) => {
144128 if ( this . state . isVisualizing )
145129 return ;
146- const { grid, startNode_Pos, finishNode_Pos } = this . state ;
147- //const startNode = grid[START_NODE_ROW][START_NODE_COL];
148- //console.log(StartNode);
149- const startNode = grid [ startNode_Pos [ 0 ] ] [ startNode_Pos [ 1 ] ] ;
150- //const finishNode = grid[FINISH_NODE_ROW][FINISH_NODE_COL];
151- const finishNode = grid [ finishNode_Pos [ 0 ] ] [ finishNode_Pos [ 1 ] ] ;
130+ const { grid, startNode_Pos, finishNode_Pos } = this . state ;
131+ const start_X = startNode_Pos [ 0 ] , start_Y = startNode_Pos [ 1 ] ;
132+ const startNode = grid [ start_X ] [ start_Y ] ;
133+ const finish_X = finishNode_Pos [ 0 ] , finish_Y = finishNode_Pos [ 1 ] ;
134+ const finishNode = grid [ finish_X ] [ finish_Y ] ;
152135 try {
153136 const visitedNodesInOrder = dfs ( grid , startNode , finishNode ) ;
154137 const nodesInShortestPathOrder = getNodesInShortestPathOrder ( finishNode ) ;
@@ -171,11 +154,11 @@ class PathVisualizer extends Component {
171154 visualizeBFS = async ( ) => {
172155 if ( this . state . isVisualizing )
173156 return ;
174- const { grid, startNode_Pos, finishNode_Pos } = this . state ;
175- // const startNode = grid[START_NODE_ROW][START_NODE_COL ];
176- const startNode = grid [ startNode_Pos [ 0 ] ] [ startNode_Pos [ 1 ] ] ;
177- // const finishNode = grid[FINISH_NODE_ROW][FINISH_NODE_COL ];
178- const finishNode = grid [ finishNode_Pos [ 0 ] ] [ finishNode_Pos [ 1 ] ] ;
157+ const { grid, startNode_Pos, finishNode_Pos } = this . state ;
158+ const start_X = startNode_Pos [ 0 ] , start_Y = startNode_Pos [ 1 ] ;
159+ const startNode = grid [ start_X ] [ start_Y ] ;
160+ const finish_X = finishNode_Pos [ 0 ] , finish_Y = finishNode_Pos [ 1 ] ;
161+ const finishNode = grid [ finish_X ] [ finish_Y ] ;
179162 try {
180163 const visitedNodesInOrder = bfs ( grid , startNode , finishNode ) ;
181164 const nodesInShortestPathOrder = getNodesInShortestPathOrder ( finishNode ) ;
@@ -197,12 +180,11 @@ class PathVisualizer extends Component {
197180 visualizeAstar = ( ) => {
198181 if ( this . state . isVisualizing )
199182 return ;
200- console . log ( "a star" ) ;
201183 const { grid, startNode_Pos, finishNode_Pos } = this . state ;
202- // const startNode = grid[START_NODE_ROW][START_NODE_COL ];
203- const startNode = grid [ startNode_Pos [ 0 ] ] [ startNode_Pos [ 1 ] ] ;
204- // const finishNode = grid[FINISH_NODE_ROW][FINISH_NODE_COL ];
205- const finishNode = grid [ finishNode_Pos [ 0 ] ] [ finishNode_Pos [ 1 ] ] ;
184+ const start_X = startNode_Pos [ 0 ] , start_Y = startNode_Pos [ 1 ] ;
185+ const startNode = grid [ start_X ] [ start_Y ] ;
186+ const finish_X = finishNode_Pos [ 0 ] , finish_Y = finishNode_Pos [ 1 ] ;
187+ const finishNode = grid [ finish_X ] [ finish_Y ] ;
206188 try {
207189 const visitedNodesInOrder = astar ( grid , startNode , finishNode ) ;
208190 const nodesInShortestPathOrder = getNodesInShortestPathOrder ( finishNode ) ;
@@ -369,25 +351,22 @@ export default PathVisualizer;
369351
370352/*------------------------------------------------------------helper functions----------------------------------------------------------------*/
371353
372- // prev getInitialGrid func was here
373- // creating the initial grid, calls the createNode() function
374- // to initialise the node with initial properties
375- //const
376- const getInitialGrid = ( ) => {
377- let grid = [ ] ;
378- //const { startNode, finishNode } = this.state;
379- const startNode_Pos = [ 10 , 15 ] ;
380- const finishNode_Pos = [ 10 , 35 ] ;
381- for ( let row = 0 ; row < 20 ; row ++ ) {
382- const currRow = [ ] ;
383- for ( let col = 0 ; col < 40 ; col ++ ) { // previously I had it as 20*50
384- //currRow.push(createNode(row, col));
385- currRow . push ( createNode ( row , col , startNode_Pos , finishNode_Pos ) ) ;
386- }
387- grid . push ( currRow ) ;
354+ // creating the initial grid, calls the createNode() function
355+ // to initialise the node with initial properties
356+ const getInitialGrid = ( ) => {
357+ let grid = [ ] ;
358+ //const { startNode, finishNode } = this.state;
359+ const startNode_Pos = [ 10 , 15 ] ;
360+ const finishNode_Pos = [ 10 , 35 ] ;
361+ for ( let row = 0 ; row < 20 ; row ++ ) {
362+ const currRow = [ ] ;
363+ for ( let col = 0 ; col < 40 ; col ++ ) { // previously I had it as 20*50
364+ currRow . push ( createNode ( row , col , startNode_Pos , finishNode_Pos ) ) ;
388365 }
389- return grid ;
366+ grid . push ( currRow ) ;
390367 }
368+ return grid ;
369+ }
391370
392371// initialising the node with its initial properties
393372const createNode = ( row , col , startNode , finishNode ) => {
0 commit comments