@@ -421,32 +421,39 @@ export const assembleVegaChart = (
421
421
} )
422
422
423
423
// Handle nominal axes with many entries
424
- for ( const channel of [ 'x' , 'y' ] ) {
424
+ for ( const channel of [ 'x' , 'y' , 'column' , 'row' , 'xOffset' ] ) {
425
425
const encoding = vgObj . encoding ?. [ channel ] ;
426
426
if ( encoding ?. type === 'nominal' ) {
427
427
const fieldName = encoding . field ;
428
- const uniqueValues = [ ...new Set ( workingTable . map ( r => r [ fieldName ] ) ) ] ;
428
+ const uniqueValues = [ ...new Set ( values . map ( ( r : any ) => r [ fieldName ] ) ) ] ;
429
429
430
+ let valuesToKeep : any [ ] ;
430
431
if ( uniqueValues . length > maxNominalValues ) {
431
- const oppositeChannel = channel === 'x' ? 'y' : 'x' ;
432
- const oppositeEncoding = vgObj . encoding ?. [ oppositeChannel ] ;
433
-
434
- let valuesToKeep : any [ ] ;
435
- if ( oppositeEncoding ?. type === 'quantitative' ) {
436
- // Sort by the quantitative field and take top maxNominalValues
437
- const quantField = oppositeEncoding . field ;
438
- valuesToKeep = uniqueValues
439
- . map ( val => ( {
440
- value : val ,
441
- sum : workingTable
442
- . filter ( r => r [ fieldName ] === val )
443
- . reduce ( ( sum , r ) => sum + ( r [ quantField ] || 0 ) , 0 )
444
- } ) )
445
- . sort ( ( a , b ) => b . sum - a . sum )
446
- . slice ( 0 , maxNominalValues )
447
- . map ( v => v . value ) ;
432
+
433
+ if ( channel == 'x' || channel == 'y' ) {
434
+ const oppositeChannel = channel === 'x' ? 'y' : 'x' ;
435
+ const oppositeEncoding = vgObj . encoding ?. [ oppositeChannel ] ;
436
+
437
+ if ( oppositeEncoding ?. type === 'quantitative' ) {
438
+ // Sort by the quantitative field and take top maxNominalValues
439
+ const quantField = oppositeEncoding . field ;
440
+ valuesToKeep = uniqueValues
441
+ . map ( val => ( {
442
+ value : val ,
443
+ sum : workingTable
444
+ . filter ( r => r [ fieldName ] === val )
445
+ . reduce ( ( sum , r ) => sum + ( r [ quantField ] || 0 ) , 0 )
446
+ } ) )
447
+ . sort ( ( a , b ) => b . sum - a . sum )
448
+ . slice ( 0 , maxNominalValues )
449
+ . map ( v => v . value ) ;
450
+ } else {
451
+ // If no quantitative axis, just take first maxNominalValues
452
+ valuesToKeep = uniqueValues . slice ( 0 , maxNominalValues ) ;
453
+ }
454
+ } else if ( channel == 'row' ) {
455
+ valuesToKeep = uniqueValues . slice ( 0 , 20 ) ;
448
456
} else {
449
- // If no quantitative axis, just take first maxNominalValues
450
457
valuesToKeep = uniqueValues . slice ( 0 , maxNominalValues ) ;
451
458
}
452
459
0 commit comments