Skip to content

Commit 19a1d31

Browse files
committed
updated the node coloring
1 parent ab0d267 commit 19a1d31

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

src/services/utils.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,17 @@
11
const ANIMATION_SPEED_MS: number = 5;
22
const PRIMARY_COLOR: string = "green";
33
const SECONDARY_COLOR: string = "red";
4+
const EXPAND_DELAY = 10;
5+
// Function to color nodes
46

57
export const colorNodes = (path: any[], expanded: any) => {
6-
// Function to color nodes
7-
8+
const timeToAnimateExpanded = (expanded?.length || 0) * EXPAND_DELAY;
89
// get node html element by row and col
910
const getNodeElement = ([row, col]: any) =>
1011
document.querySelector(
1112
`.matrix-row-${row} .col-index-${col}`
1213
) as HTMLElement | null;
1314

14-
// Color path nodes
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-
2615
// Color expanded nodes with delay
2716
expanded?.forEach((node: any, index: number) => {
2817
const el = getNodeElement(node);
@@ -35,9 +24,26 @@ export const colorNodes = (path: any[], expanded: any) => {
3524
) {
3625
setTimeout(() => {
3726
el.classList.add("expanded");
38-
}, index * 10);
27+
}, index * EXPAND_DELAY);
3928
}
4029
});
30+
31+
// Color path nodes
32+
setTimeout(() => {
33+
path.forEach((node: any) => {
34+
const el = getNodeElement(node);
35+
if (
36+
el &&
37+
!el.classList.contains("objective") &&
38+
!el.classList.contains("start")
39+
) {
40+
if (el.classList.contains("expanded")) {
41+
el.classList.remove("expanded");
42+
}
43+
el.classList.add("path");
44+
}
45+
});
46+
}, timeToAnimateExpanded * 2);
4147
};
4248

4349
export const startSorting = (animations: any[]) => {

0 commit comments

Comments
 (0)