11const ANIMATION_SPEED_MS : number = 5 ;
22const PRIMARY_COLOR : string = "green" ;
33const SECONDARY_COLOR : string = "red" ;
4+ const EXPAND_DELAY = 10 ;
5+ // Function to color nodes
46
57export 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
4349export const startSorting = ( animations : any [ ] ) => {
0 commit comments