Skip to content

Commit 71205db

Browse files
committed
added some front end features
1 parent 040de56 commit 71205db

File tree

3 files changed

+41
-64
lines changed

3 files changed

+41
-64
lines changed

src/components/GraphTraversalVisualiser/GraphTraversalVisualiser.css

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.matrix-container {
22
align-content: center;
3-
min-height: 100vh;
3+
/* min-height: 100vh; */
44
display: flex;
55
flex-direction: column;
66
align-items: center;
@@ -44,6 +44,28 @@
4444
background-color: aquamarine;
4545
}
4646

47+
.legend {
48+
align-content: center;
49+
display: flex;
50+
justify-content: center;
51+
}
52+
53+
.legend ul {
54+
list-style: none;
55+
}
56+
57+
.legend li {
58+
display: inline;
59+
/* color: black; */
60+
margin: 10px;
61+
padding: 10px;
62+
}
63+
64+
65+
.white-text {
66+
color:white;
67+
}
68+
4769
/* button start */
4870
.btn {
4971
background-color: white;

src/components/GraphTraversalVisualiser/GraphTraversalVisualiser.jsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const MatrixVisualization = () => {
5656
};
5757

5858
const generateMatrix = () => {
59-
const n = 40
59+
const n = 30
6060
const newMatrix = Array.from({ length: n }, () => Array(n).fill(" ")); // generate array
6161
const objectivesArray = []; // array to hold bojectives
6262
const obstaclesArray = []; // array to hold obstacles
@@ -106,15 +106,17 @@ const MatrixVisualization = () => {
106106
const [row, col] = node;
107107
const nodeElement = document.querySelector(`.matrix-row-${row} .col-index-${col}`);
108108
if (nodeElement) {
109-
nodeElement.classList.add('path');
109+
if (!(nodeElement.classList.contains('objective')) && !(nodeElement.classList.contains('start'))){
110+
nodeElement.classList.add('path');
111+
}
110112
}});
111113

112114
if (expanded){
113115
expanded.forEach(node => {
114116
const [row, col] = node;
115117
const nodeElement = document.querySelector(`.matrix-row-${row} .col-index-${col}`);
116118
if (nodeElement) {
117-
if (!(nodeElement.classList.contains('path'))){
119+
if (!(nodeElement.classList.contains('path')) && !(nodeElement.classList.contains('objective')) && !(nodeElement.classList.contains('start'))){
118120
nodeElement.classList.add('expanded');
119121
}
120122
}});
@@ -171,14 +173,23 @@ const MatrixVisualization = () => {
171173
key={colIndex}
172174
className={`matrix-cell ${start.row === rowIndex && start.col === colIndex ? 'start' : ''}
173175
${objectives.some(obj => obj.row === rowIndex && obj.col === colIndex) ? 'objective' : ''}
174-
${obstacles.some(obs => obs.row === rowIndex && obs.col === colIndex) ? 'obstacle' : ''} col-index-${colIndex}`}
175-
>
176+
${obstacles.some(obs => obs.row === rowIndex && obs.col === colIndex) ? 'obstacle' : ''} col-index-${colIndex}`}>
176177
{cell}
177178
</div>
178179
))}
179180
</div>
180181
))}
181182
</div>
183+
<div className='legend'>
184+
<ul>
185+
<li className='start'>Start</li>
186+
<li className='objective'>Objective</li>
187+
<li className='path'>Path</li>
188+
<li className='obstacle white-text'>Obstacle</li>
189+
<li className='expanded'>Expanded Nodes</li>
190+
<li className='weight'>Weighted (ignored for bfs and dfs)</li>
191+
</ul>
192+
</div>
182193
<form onSubmit={handleSubmit}>
183194
<label htmlFor='algorithm' className='label'>
184195
Algorithms:
@@ -192,7 +203,7 @@ const MatrixVisualization = () => {
192203
<option value='DFS'>DFS</option>
193204
<option value='UCS'>UCS</option>
194205
<option value='Astar'>Astar</option>
195-
<option value='IDS'>IDS</option>
206+
{/* <option value='IDS'>IDS</option> */}
196207
</select>
197208
</label>
198209
<input
@@ -203,6 +214,7 @@ const MatrixVisualization = () => {
203214
disabled={button}
204215
/>
205216
</form>
217+
206218
</div>
207219
);
208220
};

src/components/GraphTraversalVisualiser/createMap.js

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)