@@ -90,10 +90,39 @@ class GraphConfig {
90
90
colorScheme = GraphConfig . ColorScheme . NEIGHBORHOOD ;
91
91
92
92
colorPalette = [
93
- '#1A73E8' , '#E52592' , '#12A4AF' , '#F4511E' ,
94
- '#9334E6' , '#689F38' , '#3949AB' , '#546E7A' ,
95
- '#EF6C00' , '#D93025' , '#1E8E3E' , '#039BE5'
96
- ] ;
93
+ '#1A73E8' ,
94
+ '#E52592' ,
95
+ '#12A4AF' ,
96
+ '#F4511E' ,
97
+ '#9334E6' ,
98
+ '#689F38' ,
99
+ '#3949AB' ,
100
+ '#546E7A' ,
101
+ '#EF6C00' ,
102
+ '#D93025' ,
103
+ '#1E8E3E' ,
104
+ '#039BE5' ,
105
+ '#4682B4' ,
106
+ '#F0E68C' ,
107
+ '#00FFFF' ,
108
+ '#FFB6C1' ,
109
+ '#E6E6FA' ,
110
+ '#7B68EE' ,
111
+ '#CD853F' ,
112
+ '#BDB76B' ,
113
+ '#40E0D0' ,
114
+ '#708090' ,
115
+ '#DA70D6' ,
116
+ '#32CD32' ,
117
+ '#8B008B' ,
118
+ '#B0E0E6' ,
119
+ '#FF7F50' ,
120
+ '#A0522D' ,
121
+ '#6B8E23' ,
122
+ '#DC143C' ,
123
+ '#FFD700' ,
124
+ '#DB7093' ,
125
+ ]
97
126
98
127
// [label: string]: colorString
99
128
nodeColors = { } ;
@@ -181,10 +210,10 @@ class GraphConfig {
181
210
* @param {RawSchema } config.schemaData - Raw schema data from Spanner
182
211
*/
183
212
constructor ( { nodesData, edgesData, colorPalette, colorScheme, rowsData, schemaData, queryResult} ) {
213
+ this . parseSchema ( schemaData ) ;
184
214
this . nodes = this . parseNodes ( nodesData ) ;
185
215
this . nodeCount = Object . keys ( this . nodes ) . length ;
186
216
this . edges = this . parseEdges ( edgesData ) ;
187
- this . parseSchema ( schemaData ) ;
188
217
189
218
this . nodeColors = { } ;
190
219
this . assignColors ( ) ;
@@ -205,8 +234,6 @@ class GraphConfig {
205
234
* Assigns colors for node labels to the existing color map
206
235
*/
207
236
assignColors ( ) {
208
- const colorPalette = this . colorPalette . map ( color => color ) ;
209
-
210
237
const labels = new Set ( ) ;
211
238
212
239
for ( const uid of Object . keys ( this . nodes ) ) {
@@ -228,7 +255,7 @@ class GraphConfig {
228
255
}
229
256
230
257
for ( const label of labels ) {
231
- if ( colorPalette . length === 0 ) {
258
+ if ( this . colorPalette . length === 0 ) {
232
259
console . error ( 'Node labels exceed the color palette. Assigning default color.' ) ;
233
260
continue ;
234
261
}
@@ -239,7 +266,7 @@ class GraphConfig {
239
266
}
240
267
241
268
if ( ! this . nodeColors [ label ] ) {
242
- this . nodeColors [ label ] = colorPalette . shift ( ) ;
269
+ this . nodeColors [ label ] = this . colorPalette . shift ( ) ;
243
270
}
244
271
}
245
272
}
@@ -251,6 +278,7 @@ class GraphConfig {
251
278
*/
252
279
parseSchema ( schemaData ) {
253
280
if ( ! ( schemaData instanceof Object ) ) {
281
+ this . schema = new Schema ( { } ) ;
254
282
return ;
255
283
}
256
284
@@ -313,14 +341,17 @@ class GraphConfig {
313
341
314
342
/** @type {NodeMap } */
315
343
const nodes = { } ;
344
+ const allSchemaStaticLabelSets = this . schema . getAllNodeTableStaticLabelSets ( ) ;
345
+ const containsDynamicLabelElement = this . schema . containsDynamicLabelNode ( ) ;
316
346
nodesData . forEach ( nodeData => {
317
347
if ( ! ( nodeData instanceof Object ) ) {
318
348
console . error ( 'Node data is not an object' , nodeData ) ;
319
349
return ;
320
350
}
351
+ const fullNodeData = { ...nodeData , containsDynamicLabelElement, allSchemaStaticLabelSets } ;
321
352
322
353
// Try to create a Node
323
- const node = new GraphNode ( nodeData ) ;
354
+ const node = new GraphNode ( fullNodeData ) ;
324
355
if ( ! node || ! node . instantiated ) {
325
356
console . error ( 'Unable to instantiate node' , node . instantiationErrorReason ) ;
326
357
return ;
@@ -332,7 +363,7 @@ class GraphConfig {
332
363
}
333
364
} else {
334
365
node . instantiationErrorReason = 'Could not construct an instance of Node' ;
335
- console . error ( node . instantiationErrorReason , { nodeData , node } ) ;
366
+ console . error ( node . instantiationErrorReason , { fullNodeData , node } ) ;
336
367
}
337
368
} ) ;
338
369
@@ -353,14 +384,17 @@ class GraphConfig {
353
384
354
385
/** @type {EdgeMap } */
355
386
const edges = { }
387
+ const allSchemaStaticLabelSets = this . schema . getAllEdgeTableStaticLabelSets ( ) ;
388
+ const containsDynamicLabelElement = this . schema . containsDynamicLabelEdge ( ) ;
356
389
edgesData . forEach ( edgeData => {
357
390
if ( ! ( edgeData instanceof Object ) ) {
358
391
console . error ( 'Edge data is not an object' , edgeData ) ;
359
392
return ;
360
393
}
394
+ const fullEdgeData = { ...edgeData , containsDynamicLabelElement, allSchemaStaticLabelSets } ;
361
395
362
396
// Try to create an Edge
363
- const edge = new GraphEdge ( edgeData ) ;
397
+ const edge = new GraphEdge ( fullEdgeData ) ;
364
398
if ( ! edge || ! edge . instantiated ) {
365
399
console . error ( 'Unable to instantiate edge' , edge . instantiationErrorReason ) ;
366
400
return ;
@@ -372,7 +406,7 @@ class GraphConfig {
372
406
this . _updateEdgeIndices ( edge ) ;
373
407
} else {
374
408
edge . instantiationErrorReason = 'Could not construct an instance of Edge' ;
375
- console . error ( edge . instantiationErrorReason , { edgeData , edge } ) ;
409
+ console . error ( edge . instantiationErrorReason , { fullEdgeData , edge } ) ;
376
410
}
377
411
} ) ;
378
412
0 commit comments