@@ -166,8 +166,6 @@ export default class Sigma extends TypedEventEmitter<SigmaEvents> {
166
166
private edgeDataCache : Record < string , EdgeDisplayData > = { } ;
167
167
private nodesWithForcedLabels : string [ ] = [ ] ;
168
168
private edgesWithForcedLabels : string [ ] = [ ] ;
169
- private nodeKeyToIndex : Record < string , number > = { } ;
170
- private edgeKeyToIndex : Record < string , number > = { } ;
171
169
private nodeExtent : { x : Extent ; y : Extent } = { x : [ 0 , 1 ] , y : [ 0 , 1 ] } ;
172
170
173
171
private matrix : Float32Array = identity ( ) ;
@@ -218,8 +216,6 @@ export default class Sigma extends TypedEventEmitter<SigmaEvents> {
218
216
this . graph = graph ;
219
217
this . container = container ;
220
218
221
- this . initializeCache ( ) ;
222
-
223
219
// Initializing contexts
224
220
this . createWebGLContext ( "edges" , { preserveDrawingBuffer : true } ) ;
225
221
this . createCanvasContext ( "edgeLabels" ) ;
@@ -355,31 +351,6 @@ export default class Sigma extends TypedEventEmitter<SigmaEvents> {
355
351
return this ;
356
352
}
357
353
358
- /**
359
- * Method used to initialize display data cache.
360
- *
361
- * @return {Sigma }
362
- */
363
- private initializeCache ( ) : void {
364
- const graph = this . graph ;
365
-
366
- // NOTE: the data caches are never reset to avoid paying a GC cost
367
- // But this could prove to be a bad decision. In which case just "reset"
368
- // them here.
369
-
370
- let i = 0 ;
371
-
372
- graph . forEachNode ( ( key ) => {
373
- this . nodeKeyToIndex [ key ] = i ++ ;
374
- } ) ;
375
-
376
- i = 0 ;
377
-
378
- graph . forEachEdge ( ( key ) => {
379
- this . edgeKeyToIndex [ key ] = i ++ ;
380
- } ) ;
381
- }
382
-
383
354
/**
384
355
* Method binding camera handlers.
385
356
*
@@ -566,33 +537,46 @@ export default class Sigma extends TypedEventEmitter<SigmaEvents> {
566
537
this . _scheduleRefresh ( ) ;
567
538
} ;
568
539
569
- this . activeListeners . addNodeGraphUpdate = ( e : { key : string } ) : void => {
570
- // Adding entry to cache
571
- this . nodeKeyToIndex [ e . key ] = graph . order - 1 ;
540
+ this . activeListeners . dropNodeGraphUpdate = ( e : { key : string } ) : void => {
541
+ delete this . nodeDataCache [ e . key ] ;
542
+
543
+ if ( this . hoveredNode === e . key ) this . hoveredNode = null ;
544
+
572
545
this . activeListeners . graphUpdate ( ) ;
573
546
} ;
574
547
575
- this . activeListeners . addEdgeGraphUpdate = ( e : { key : string } ) : void => {
576
- // Adding entry to cache
577
- this . nodeKeyToIndex [ e . key ] = graph . order - 1 ;
548
+ this . activeListeners . dropEdgeGraphUpdate = ( e : { key : string } ) : void => {
549
+ delete this . edgeDataCache [ e . key ] ;
550
+
551
+ if ( this . hoveredEdge === e . key ) this . hoveredEdge = null ;
552
+
578
553
this . activeListeners . graphUpdate ( ) ;
579
554
} ;
580
555
581
- // TODO: clean cache on drop!
556
+ this . activeListeners . clearEdgesGraphUpdate = ( ) : void => {
557
+ this . edgeDataCache = { } ;
558
+ this . hoveredEdge = null ;
582
559
583
- // TODO: bind this on composed state events
584
- // TODO: it could be possible to update only specific node etc. by holding
585
- // a fixed-size pool of updated items
586
- graph . on ( "nodeAdded" , this . activeListeners . addNodeGraphUpdate ) ;
587
- graph . on ( "nodeDropped" , this . activeListeners . graphUpdate ) ;
560
+ this . activeListeners . graphUpdate ( ) ;
561
+ } ;
562
+
563
+ this . activeListeners . clearGraphUpdate = ( ) : void => {
564
+ this . nodeDataCache = { } ;
565
+ this . hoveredNode = null ;
566
+
567
+ this . activeListeners . clearEdgesGraphUpdate ( ) ;
568
+ } ;
569
+
570
+ graph . on ( "nodeAdded" , this . activeListeners . graphUpdate ) ;
571
+ graph . on ( "nodeDropped" , this . activeListeners . dropNodeGraphUpdate ) ;
588
572
graph . on ( "nodeAttributesUpdated" , this . activeListeners . softGraphUpdate ) ;
589
573
graph . on ( "eachNodeAttributesUpdated" , this . activeListeners . graphUpdate ) ;
590
- graph . on ( "edgeAdded" , this . activeListeners . addEdgeGraphUpdate ) ;
591
- graph . on ( "edgeDropped" , this . activeListeners . graphUpdate ) ;
574
+ graph . on ( "edgeAdded" , this . activeListeners . graphUpdate ) ;
575
+ graph . on ( "edgeDropped" , this . activeListeners . dropEdgeGraphUpdate ) ;
592
576
graph . on ( "edgeAttributesUpdated" , this . activeListeners . softGraphUpdate ) ;
593
577
graph . on ( "eachEdgeAttributesUpdated" , this . activeListeners . graphUpdate ) ;
594
- graph . on ( "edgesCleared" , this . activeListeners . graphUpdate ) ;
595
- graph . on ( "cleared" , this . activeListeners . graphUpdate ) ;
578
+ graph . on ( "edgesCleared" , this . activeListeners . clearEdgesGraphUpdate ) ;
579
+ graph . on ( "cleared" , this . activeListeners . clearGraphUpdate ) ;
596
580
597
581
return this ;
598
582
}
@@ -792,8 +776,6 @@ export default class Sigma extends TypedEventEmitter<SigmaEvents> {
792
776
793
777
// Save the node in the highlighted set if needed
794
778
if ( data . highlighted && ! data . hidden ) this . highlightedNodes . add ( node ) ;
795
-
796
- this . nodeKeyToIndex [ node ] = i ;
797
779
}
798
780
799
781
this . labelGrid . organize ( ) ;
@@ -853,8 +835,6 @@ export default class Sigma extends TypedEventEmitter<SigmaEvents> {
853
835
854
836
const hidden = data . hidden || sourceData . hidden || targetData . hidden ;
855
837
this . edgePrograms [ data . type ] . process ( sourceData , targetData , data , hidden , edgesPerPrograms [ data . type ] ++ ) ;
856
-
857
- this . nodeKeyToIndex [ edge ] = i ;
858
838
}
859
839
860
840
for ( const type in this . edgePrograms ) {
@@ -1706,16 +1686,16 @@ export default class Sigma extends TypedEventEmitter<SigmaEvents> {
1706
1686
this . touchCaptor . kill ( ) ;
1707
1687
1708
1688
// Releasing graph handlers
1709
- graph . removeListener ( "nodeAdded" , this . activeListeners . addNodeGraphUpdate ) ;
1689
+ graph . removeListener ( "nodeAdded" , this . activeListeners . dropNodeGraphUpdate ) ;
1710
1690
graph . removeListener ( "nodeDropped" , this . activeListeners . graphUpdate ) ;
1711
1691
graph . removeListener ( "nodeAttributesUpdated" , this . activeListeners . softGraphUpdate ) ;
1712
1692
graph . removeListener ( "eachNodeAttributesUpdated" , this . activeListeners . graphUpdate ) ;
1713
- graph . removeListener ( "edgeAdded" , this . activeListeners . addEdgeGraphUpdate ) ;
1714
- graph . removeListener ( "edgeDropped" , this . activeListeners . graphUpdate ) ;
1693
+ graph . removeListener ( "edgeAdded" , this . activeListeners . graphUpdate ) ;
1694
+ graph . removeListener ( "edgeDropped" , this . activeListeners . dropEdgeGraphUpdate ) ;
1715
1695
graph . removeListener ( "edgeAttributesUpdated" , this . activeListeners . softGraphUpdate ) ;
1716
1696
graph . removeListener ( "eachEdgeAttributesUpdated" , this . activeListeners . graphUpdate ) ;
1717
- graph . removeListener ( "edgesCleared" , this . activeListeners . graphUpdate ) ;
1718
- graph . removeListener ( "cleared" , this . activeListeners . graphUpdate ) ;
1697
+ graph . removeListener ( "edgesCleared" , this . activeListeners . clearEdgesGraphUpdate ) ;
1698
+ graph . removeListener ( "cleared" , this . activeListeners . clearGraphUpdate ) ;
1719
1699
1720
1700
// Releasing cache & state
1721
1701
this . quadtree = new QuadTree ( ) ;
0 commit comments