Skip to content

Commit 77b69da

Browse files
committed
updated function nae
1 parent 4663ca6 commit 77b69da

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/components/TraversalVisualizer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { BFS } from "../services/graphAlgorithms/bfs";
99
import { DFS } from "../services/graphAlgorithms/dfs";
1010
import { ASTAR } from "../services/graphAlgorithms/astar";
1111
import { conflict } from "../services/graphAlgorithms/helper";
12-
import { colorNodes, clearPath } from "../services/utils";
12+
import { colorNodes, clearGrid } from "../services/utils";
1313

1414
import "../css/Graphs.css";
1515

@@ -78,7 +78,7 @@ const TraversalVisualizer: React.FC<GraphProps> = ({ graphsInfo }) => {
7878
const resetMatrix = () => {
7979
if (!isSorting) {
8080
setAlgorithm("");
81-
clearPath();
81+
clearGrid();
8282
setMatrix(generateMatrix());
8383
}
8484
};

src/services/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const colorNodes = (path: any[], expanded: any) => {
1111
`.matrix-row-${row} .col-index-${col}`
1212
) as HTMLElement | null;
1313

14-
// Color path nodes with delay
14+
// Color path nodes
1515
path.forEach((node: any) => {
1616
const el = getNodeElement(node);
1717
if (
@@ -77,11 +77,13 @@ export const startSorting = (animations: any[]) => {
7777
return animations.length * ANIMATION_SPEED_MS;
7878
};
7979

80-
export const clearPath = () => {
80+
export const clearGrid = () => {
81+
// Function to clear the grid of path and expanded nodes
8182
const pathNodes = document.querySelectorAll(".matrix-cell.path");
8283
pathNodes.forEach((node) => {
8384
node.classList.remove("path");
8485
});
86+
8587
const expandedNodes = document.querySelectorAll(".matrix-cell.expanded");
8688
expandedNodes.forEach((node) => {
8789
node.classList.remove("expanded");

0 commit comments

Comments
 (0)