@@ -143,8 +143,8 @@ export default class Sigma<
143
143
private nodesWithForcedLabels : Set < string > = new Set < string > ( ) ;
144
144
private edgesWithForcedLabels : Set < string > = new Set < string > ( ) ;
145
145
private nodeExtent : { x : Extent ; y : Extent } = { x : [ 0 , 1 ] , y : [ 0 , 1 ] } ;
146
- private nodeZExtent : [ number , number ] = [ Infinity , - Infinity ] ;
147
- private edgeZExtent : [ number , number ] = [ Infinity , - Infinity ] ;
146
+ private nodeDepths : Record < string , number > = { } ;
147
+ private edgeDepths : Record < string , number > = { } ;
148
148
149
149
private matrix : Float32Array = identity ( ) ;
150
150
private invMatrix : Float32Array = identity ( ) ;
@@ -631,13 +631,13 @@ export default class Sigma<
631
631
private bindGraphHandlers ( ) : this {
632
632
const graph = this . graph ;
633
633
634
- const LAYOUT_IMPACTING_FIELDS = new Set ( [ "x" , "y" , "zIndex" , " type"] ) ;
634
+ const LAYOUT_IMPACTING_FIELDS = new Set ( [ "x" , "y" , "type" ] ) ;
635
635
this . activeListeners . eachNodeAttributesUpdatedGraphUpdate = ( e : { hints ?: { attributes ?: string [ ] } } ) => {
636
636
const updatedFields = e . hints ?. attributes ;
637
637
// we process all nodes
638
638
this . graph . forEachNode ( ( node ) => this . updateNode ( node ) ) ;
639
639
640
- // if coord, type or zIndex have changed, we need to schedule a render
640
+ // if coord or type have changed, we need to schedule a render
641
641
// (zIndex for the programIndex)
642
642
const layoutChanged = ! updatedFields || updatedFields . some ( ( f ) => LAYOUT_IMPACTING_FIELDS . has ( f ) ) ;
643
643
this . refresh ( { partialGraph : { nodes : graph . nodes ( ) } , skipIndexation : ! layoutChanged , schedule : true } ) ;
@@ -647,7 +647,7 @@ export default class Sigma<
647
647
const updatedFields = e . hints ?. attributes ;
648
648
// we process all edges
649
649
this . graph . forEachEdge ( ( edge ) => this . updateEdge ( edge ) ) ;
650
- const layoutChanged = updatedFields && [ "zIndex" , "type" ] . some ( ( f ) => updatedFields ?. includes ( f ) ) ;
650
+ const layoutChanged = updatedFields ?. includes ( "type" ) ;
651
651
this . refresh ( { partialGraph : { edges : graph . edges ( ) } , skipIndexation : ! layoutChanged , schedule : true } ) ;
652
652
} ;
653
653
@@ -816,7 +816,7 @@ export default class Sigma<
816
816
const itemIDsIndex : typeof this . itemIDsIndex = { } ;
817
817
let incrID = 1 ;
818
818
819
- let nodes = graph . nodes ( ) ;
819
+ const nodes = graph . nodes ( ) ;
820
820
821
821
// Do some indexation on the whole graph
822
822
for ( let i = 0 , l = nodes . length ; i < l ; i ++ ) {
@@ -849,13 +849,16 @@ export default class Sigma<
849
849
}
850
850
851
851
// Order nodes by zIndex before to add them to program
852
- if ( this . settings . zIndex && this . nodeZExtent [ 0 ] !== this . nodeZExtent [ 1 ] )
853
- nodes = zIndexOrdering < string > (
854
- this . nodeZExtent ,
852
+ this . nodeDepths = { } ;
853
+ if ( this . settings . zIndex ) {
854
+ const sortedNodes = zIndexOrdering < string > (
855
855
( node : string ) : number => this . nodeDataCache [ node ] . zIndex ,
856
- nodes ,
856
+ nodes . slice ( 0 ) ,
857
857
) ;
858
858
859
+ for ( let i = 0 , l = sortedNodes . length ; i < l ; i ++ ) this . nodeDepths [ sortedNodes [ i ] ] = l - 1 - i ;
860
+ }
861
+
859
862
// Add data to programs
860
863
for ( let i = 0 , l = nodes . length ; i < l ; i ++ ) {
861
864
const node = nodes [ i ] ;
@@ -873,7 +876,7 @@ export default class Sigma<
873
876
//
874
877
875
878
const edgesPerPrograms : Record < string , number > = { } ;
876
- let edges = graph . edges ( ) ;
879
+ const edges = graph . edges ( ) ;
877
880
878
881
// Allocate memory to programs
879
882
for ( let i = 0 , l = edges . length ; i < l ; i ++ ) {
@@ -883,13 +886,16 @@ export default class Sigma<
883
886
}
884
887
885
888
// Order edges by zIndex before to add them to program
886
- if ( this . settings . zIndex && this . edgeZExtent [ 0 ] !== this . edgeZExtent [ 1 ] )
887
- edges = zIndexOrdering < string > (
888
- this . edgeZExtent ,
889
+ this . edgeDepths = { } ;
890
+ if ( this . settings . zIndex ) {
891
+ const sortedEdges = zIndexOrdering < string > (
889
892
( edge : string ) : number => this . edgeDataCache [ edge ] . zIndex ,
890
- edges ,
893
+ edges . slice ( 0 ) ,
891
894
) ;
892
895
896
+ for ( let i = 0 , l = sortedEdges . length ; i < l ; i ++ ) this . edgeDepths [ sortedEdges [ i ] ] = l - 1 - i ;
897
+ }
898
+
893
899
for ( const type in this . edgePrograms ) {
894
900
if ( ! hasOwnProperty . call ( this . edgePrograms , type ) ) {
895
901
throw new Error ( `Sigma: could not find a suitable program for edge type "${ type } "!` ) ;
@@ -930,8 +936,10 @@ export default class Sigma<
930
936
this . camera . setState ( this . camera . validateState ( this . camera . getState ( ) ) ) ;
931
937
932
938
if ( oldSettings ) {
939
+ const zIndexingUpdated = ! ! oldSettings . zIndex !== ! ! settings . zIndex ;
940
+
933
941
// Check edge programs:
934
- if ( oldSettings . edgeProgramClasses !== settings . edgeProgramClasses ) {
942
+ if ( zIndexingUpdated || oldSettings . edgeProgramClasses !== settings . edgeProgramClasses ) {
935
943
for ( const type in settings . edgeProgramClasses ) {
936
944
if ( settings . edgeProgramClasses [ type ] !== oldSettings . edgeProgramClasses [ type ] ) {
937
945
this . registerEdgeProgram ( type , settings . edgeProgramClasses [ type ] ) ;
@@ -944,6 +952,7 @@ export default class Sigma<
944
952
945
953
// Check node programs:
946
954
if (
955
+ zIndexingUpdated ||
947
956
oldSettings . nodeProgramClasses !== settings . nodeProgramClasses ||
948
957
oldSettings . nodeHoverProgramClasses !== settings . nodeHoverProgramClasses
949
958
) {
@@ -1194,6 +1203,8 @@ export default class Sigma<
1194
1203
1195
1204
program . render ( {
1196
1205
matrix : this . matrix ,
1206
+ maxEdgesDepth : this . graph . size + 1 ,
1207
+ maxNodesDepth : this . graph . order + 1 ,
1197
1208
width : this . width ,
1198
1209
height : this . height ,
1199
1210
pixelRatio : this . pixelRatio ,
@@ -1291,6 +1302,8 @@ export default class Sigma<
1291
1302
1292
1303
const params : RenderParams = {
1293
1304
matrix : this . matrix ,
1305
+ maxEdgesDepth : this . graph . size + 1 ,
1306
+ maxNodesDepth : this . graph . order + 1 ,
1294
1307
width : this . width ,
1295
1308
height : this . height ,
1296
1309
pixelRatio : this . pixelRatio ,
@@ -1356,12 +1369,6 @@ export default class Sigma<
1356
1369
// update
1357
1370
this . highlightedNodes . delete ( key ) ;
1358
1371
if ( data . highlighted && ! data . hidden ) this . highlightedNodes . add ( key ) ;
1359
-
1360
- // zIndex
1361
- if ( this . settings . zIndex ) {
1362
- if ( data . zIndex < this . nodeZExtent [ 0 ] ) this . nodeZExtent [ 0 ] = data . zIndex ;
1363
- if ( data . zIndex > this . nodeZExtent [ 1 ] ) this . nodeZExtent [ 1 ] = data . zIndex ;
1364
- }
1365
1372
}
1366
1373
1367
1374
/**
@@ -1387,7 +1394,7 @@ export default class Sigma<
1387
1394
delete this . nodeDataCache [ key ] ;
1388
1395
// Remove from node program index
1389
1396
delete this . nodeProgramIndex [ key ] ;
1390
- // Remove from higlighted nodes
1397
+ // Remove from highlighted nodes
1391
1398
this . highlightedNodes . delete ( key ) ;
1392
1399
// Remove from hovered
1393
1400
if ( this . hoveredNode === key ) this . hoveredNode = null ;
@@ -1417,12 +1424,6 @@ export default class Sigma<
1417
1424
// update
1418
1425
this . edgesWithForcedLabels . delete ( key ) ;
1419
1426
if ( data . forceLabel && ! data . hidden ) this . edgesWithForcedLabels . add ( key ) ;
1420
-
1421
- // Check zIndex
1422
- if ( this . settings . zIndex ) {
1423
- if ( data . zIndex < this . edgeZExtent [ 0 ] ) this . edgeZExtent [ 0 ] = data . zIndex ;
1424
- if ( data . zIndex > this . edgeZExtent [ 1 ] ) this . edgeZExtent [ 1 ] = data . zIndex ;
1425
- }
1426
1427
}
1427
1428
1428
1429
/**
@@ -1461,7 +1462,6 @@ export default class Sigma<
1461
1462
this . nodeDataCache = { } ;
1462
1463
this . edgeProgramIndex = { } ;
1463
1464
this . nodesWithForcedLabels = new Set < string > ( ) ;
1464
- this . nodeZExtent = [ Infinity , - Infinity ] ;
1465
1465
}
1466
1466
1467
1467
/**
@@ -1472,7 +1472,6 @@ export default class Sigma<
1472
1472
this . edgeDataCache = { } ;
1473
1473
this . edgeProgramIndex = { } ;
1474
1474
this . edgesWithForcedLabels = new Set < string > ( ) ;
1475
- this . edgeZExtent = [ Infinity , - Infinity ] ;
1476
1475
}
1477
1476
1478
1477
/**
@@ -1524,7 +1523,7 @@ export default class Sigma<
1524
1523
const data = this . nodeDataCache [ node ] ;
1525
1524
const nodeProgram = this . nodePrograms [ data . type ] ;
1526
1525
if ( ! nodeProgram ) throw new Error ( `Sigma: could not find a suitable program for node type "${ data . type } "!` ) ;
1527
- nodeProgram . process ( fingerprint , position , data ) ;
1526
+ nodeProgram . process ( fingerprint , position , { ... data , zIndex : this . nodeDepths [ node ] } ) ;
1528
1527
// Saving program index
1529
1528
this . nodeProgramIndex [ node ] = position ;
1530
1529
}
@@ -1543,7 +1542,7 @@ export default class Sigma<
1543
1542
const extremities = this . graph . extremities ( edge ) ,
1544
1543
sourceData = this . nodeDataCache [ extremities [ 0 ] ] ,
1545
1544
targetData = this . nodeDataCache [ extremities [ 1 ] ] ;
1546
- edgeProgram . process ( fingerprint , position , sourceData , targetData , data ) ;
1545
+ edgeProgram . process ( fingerprint , position , sourceData , targetData , { ... data , zIndex : this . edgeDepths [ edge ] } ) ;
1547
1546
// Saving program index
1548
1547
this . edgeProgramIndex [ edge ] = position ;
1549
1548
}
0 commit comments