@@ -123,18 +123,6 @@ class IrisGridPivotModel<R extends UIPivotRow = UIPivotRow>
123123
124124 private _layoutHints : DhType . LayoutHints | null | undefined ;
125125
126- private _columnHeaderGroupMap : Map < string , PivotColumnHeaderGroup > =
127- new Map ( ) ;
128-
129- private columnHeaderParentMap : Map < string , PivotColumnHeaderGroup > =
130- new Map ( ) ;
131-
132- private _columnHeaderMaxDepth : number | null = null ;
133-
134- private _columnHeaderGroups : PivotColumnHeaderGroup [ ] = [ ] ;
135-
136- private _isColumnHeaderGroupsInitialized = false ;
137-
138126 private _sorts ?: readonly SortDescriptor [ ] = EMPTY_ARRAY ;
139127
140128 private viewportData : UIPivotViewportData < R > | null = null ;
@@ -460,91 +448,81 @@ class IrisGridPivotModel<R extends UIPivotRow = UIPivotRow>
460448 }
461449
462450 /**
463- * Get the cached column header groups.
451+ * Get the cached header groups data, including max depth, parent map, and group map
452+ */
453+ private getCachedParsedColumnHeaderGroups = memoize (
454+ ( groups : readonly PivotColumnHeaderGroup [ ] ) =>
455+ IrisGridUtils . parseColumnHeaderGroups (
456+ this ,
457+ groups ,
458+ args => new PivotColumnHeaderGroup ( args )
459+ )
460+ ) ;
461+
462+ /**
463+ * Get the cached PivotColumnHeaderGroup array for the given snapshot and column data.
464464 * Returns groups for the key columns, totals, and the snapshot column in the current viewport.
465465 * Placeholder columns are not included in the groups.
466466 */
467467 private getCachedColumnHeaderGroups = memoize (
468468 (
469469 snapshotColumns : CorePlusDhType . coreplus . pivot . DimensionData | null ,
470470 groupColumn : PivotDisplayColumn | null ,
471- isRootColumnExpanded ?: boolean ,
472- formatValue ?: ( value : unknown , type : string ) => string
471+ formatter : Formatter ,
472+ isRootColumnExpanded ?: boolean
473473 ) : readonly PivotColumnHeaderGroup [ ] =>
474474 getColumnGroups (
475475 this . pivotTable ,
476476 snapshotColumns ,
477477 isRootColumnExpanded ,
478478 groupColumn != null ,
479- formatValue
479+ ( value , type ) =>
480+ this . getCachedFormattedString ( formatter , value , type , '' )
480481 )
481482 ) ;
482483
483484 get initialColumnHeaderGroups ( ) : readonly PivotColumnHeaderGroup [ ] {
484- const groups = this . getCachedColumnHeaderGroups (
485+ return this . getCachedColumnHeaderGroups (
485486 this . snapshotColumns ,
486487 this . groupColumn ,
487- this . isRootColumnExpanded ,
488- ( value , type ) =>
489- // Ignore name based formatting, pass empty column name
490- this . getCachedFormattedString ( this . formatter , value , type , '' )
488+ this . formatter ,
489+ this . isRootColumnExpanded
491490 ) ;
492- log . debug2 ( 'initialColumnHeaderGroups' , groups ) ;
493- return groups ;
494491 }
495492
496493 get columnHeaderMaxDepth ( ) : number {
497- return this . _columnHeaderMaxDepth ?? 1 ;
494+ const { maxDepth } = this . getCachedParsedColumnHeaderGroups (
495+ this . initialColumnHeaderGroups
496+ ) ;
497+ return maxDepth ;
498498 }
499499
500- private set columnHeaderMaxDepth ( depth : number ) {
501- this . _columnHeaderMaxDepth = depth ;
500+ get columnHeaderParentMap ( ) : Map < string , PivotColumnHeaderGroup > {
501+ const { parentMap } = this . getCachedParsedColumnHeaderGroups (
502+ this . initialColumnHeaderGroups
503+ ) ;
504+ return parentMap ;
502505 }
503506
504507 get columnHeaderGroupMap ( ) : Map < string , PivotColumnHeaderGroup > {
505- this . initializeColumnHeaderGroups ( ) ;
506- return this . _columnHeaderGroupMap ;
508+ const { groupMap } = this . getCachedParsedColumnHeaderGroups (
509+ this . initialColumnHeaderGroups
510+ ) ;
511+ return groupMap ;
507512 }
508513
509514 get columnHeaderGroups ( ) : readonly PivotColumnHeaderGroup [ ] {
510- this . initializeColumnHeaderGroups ( ) ;
511- return this . _columnHeaderGroups ;
515+ const { groups } = this . getCachedParsedColumnHeaderGroups (
516+ this . initialColumnHeaderGroups
517+ ) ;
518+ return groups ;
512519 }
513520
514521 set columnHeaderGroups ( _groups : readonly PivotColumnHeaderGroup [ ] ) {
515522 // no-op
516523 // IrisGridPivotModel manages its own column header groups
517524 }
518525
519- private setInternalColumnHeaderGroups (
520- groups : readonly PivotColumnHeaderGroup [ ]
521- ) {
522- if ( groups === this . _columnHeaderGroups ) {
523- return ;
524- }
525- const {
526- groups : newGroups ,
527- maxDepth,
528- parentMap,
529- groupMap,
530- } = IrisGridUtils . parseColumnHeaderGroups (
531- this ,
532- groups ,
533- args => new PivotColumnHeaderGroup ( args )
534- ) ;
535- this . _columnHeaderGroups = newGroups ;
536- this . columnHeaderMaxDepth = maxDepth ;
537- this . columnHeaderParentMap = parentMap ;
538- this . _columnHeaderGroupMap = groupMap ;
539- this . _isColumnHeaderGroupsInitialized = true ;
540- }
541-
542- private initializeColumnHeaderGroups ( ) : void {
543- if ( ! this . _isColumnHeaderGroupsInitialized ) {
544- this . setInternalColumnHeaderGroups ( this . initialColumnHeaderGroups ) ;
545- }
546- }
547-
548526 textForColumnHeader ( x : ModelIndex , depth = 0 ) : string | undefined {
549527 const header = this . columnAtDepth ( x , depth ) ;
550528 if ( isPivotColumnHeaderGroup ( header ) ) {
@@ -776,9 +754,6 @@ class IrisGridPivotModel<R extends UIPivotRow = UIPivotRow>
776754
777755 this . updatePendingExpandCollapseState ( ) ;
778756
779- // Update column groups based on the new columns and expand/collapse state
780- this . setInternalColumnHeaderGroups ( this . initialColumnHeaderGroups ) ;
781-
782757 log . debug2 ( 'Pivot updated' , {
783758 columns : this . columns ,
784759 snapshot,
0 commit comments