Skip to content

Commit 4663ca6

Browse files
committed
updating the traversal
1 parent 1e823f9 commit 4663ca6

File tree

2 files changed

+34
-41
lines changed

2 files changed

+34
-41
lines changed

src/css/Graphs.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@
2929

3030
.expanded {
3131
background-color: oklch(85.5% 0.138 181.071) !important;
32+
animation: changeColor 2s linear infinite;
3233
}

src/services/utils.ts

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,40 @@ const SECONDARY_COLOR: string = "red";
44

55
export const colorNodes = (path: any[], expanded: any) => {
66
// Function to color nodes
7-
// for each node in the path
8-
path.forEach((node) => {
9-
// select the node from the matrix
10-
const [row, col] = node;
11-
// select the node from html matching the row and col
12-
const nodeElement = document.querySelector(
7+
8+
// get node html element by row and col
9+
const getNodeElement = ([row, col]: any) =>
10+
document.querySelector(
1311
`.matrix-row-${row} .col-index-${col}`
14-
);
15-
// if the node exists
16-
if (nodeElement) {
17-
// if the node is not an objective or start
18-
if (
19-
!nodeElement.classList.contains("objective") &&
20-
!nodeElement.classList.contains("start")
21-
) {
22-
// add the path class
23-
nodeElement.classList.add("path");
24-
}
12+
) as HTMLElement | null;
13+
14+
// Color path nodes with delay
15+
path.forEach((node: any) => {
16+
const el = getNodeElement(node);
17+
if (
18+
el &&
19+
!el.classList.contains("objective") &&
20+
!el.classList.contains("start")
21+
) {
22+
el.classList.add("path");
23+
}
24+
});
25+
26+
// Color expanded nodes with delay
27+
expanded?.forEach((node: any, index: number) => {
28+
const el = getNodeElement(node);
29+
if (
30+
el &&
31+
!el.classList.contains("path") &&
32+
!el.classList.contains("objective") &&
33+
!el.classList.contains("start") &&
34+
!el.classList.contains("obstacle")
35+
) {
36+
setTimeout(() => {
37+
el.classList.add("expanded");
38+
}, index * 10);
2539
}
2640
});
27-
// if expanded node
28-
if (expanded) {
29-
// for each expanded node
30-
expanded.forEach((node: any) => {
31-
// select the node from the matrix
32-
const [row, col] = node;
33-
// select the node from html matching the row and col
34-
const nodeElement = document.querySelector(
35-
`.matrix-row-${row} .col-index-${col}`
36-
);
37-
// if the node exists
38-
if (nodeElement) {
39-
if (
40-
!nodeElement.classList.contains("path") &&
41-
!nodeElement.classList.contains("objective") &&
42-
!nodeElement.classList.contains("start")
43-
) {
44-
nodeElement.classList.add("expanded");
45-
}
46-
}
47-
});
48-
}
4941
};
5042

5143
export const startSorting = (animations: any[]) => {
@@ -86,11 +78,11 @@ export const startSorting = (animations: any[]) => {
8678
};
8779

8880
export const clearPath = () => {
89-
const pathNodes = document.querySelectorAll(".path");
81+
const pathNodes = document.querySelectorAll(".matrix-cell.path");
9082
pathNodes.forEach((node) => {
9183
node.classList.remove("path");
9284
});
93-
const expandedNodes = document.querySelectorAll(".expanded");
85+
const expandedNodes = document.querySelectorAll(".matrix-cell.expanded");
9486
expandedNodes.forEach((node) => {
9587
node.classList.remove("expanded");
9688
});

0 commit comments

Comments
 (0)