import { similar , IEventListener } from '../internal' ; import { toolbar } from './annotations' ; import Column , { widthChanged , labelChanged , metaDataChanged , dirty , dirtyHeader , dirtyValues , rendererTypeChanged , groupRendererChanged , summaryRendererChanged , visibilityChanged , dirtyCaches , } from './Column' ; import CompositeColumn , { addColumn , filterChanged , moveColumn , removeColumn } from './CompositeColumn' ; import type { IDataRow , IColumnDesc , IFlatColumn , IMultiLevelColumn , ITypeFactory } from './interfaces' ; import { integrateDefaults } from './internal' ; import StackColumn from './StackColumn' ; asMemberOf event export declare function collapseChanged_MC ( previous , current ) ; asMemberOf event export declare function nestedChildRatio_MC ( previous , current ) ; export declare type IMultiLevelCompositeColumnDesc = IColumnDesc & { default showNestedSummaries ? : boolean ; } ; @ toolbar ( 'compress' , 'expand' ) export default class MultiLevelCompositeColumn extends CompositeColumn implements IMultiLevelColumn { static readonly EVENT_COLLAPSE_CHANGED = StackColumn . EVENT_COLLAPSE_CHANGED ; static readonly EVENT_MULTI_LEVEL_CHANGED = StackColumn . EVENT_MULTI_LEVEL_CHANGED ; static readonly COLLAPSED_RENDERER = 'default' ; private readonly adaptChange : ( old : number , newValue : number ) => void ; type { boolean } private private collapsed = false ; constructor ( id , desc ) { super ( id , integrateDefaults ( desc , { summaryRenderer : 'nested' , } ) ) ; const that = this ; this . adaptChange = function ( old , newValue ) { that . adaptWidthChange ( old , newValue ) ; } ; } protected createEventList ( ) { return super . createEventList ( ) . concat ( [ MultiLevelCompositeColumn . EVENT_COLLAPSE_CHANGED , MultiLevelCompositeColumn . EVENT_MULTI_LEVEL_CHANGED ] ) ; } on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) { return super . on ( type , listener ) ; } setCollapsed ( value ) { if ( this . collapsed === value ) { return ; } this . fire ( [ StackColumn . EVENT_COLLAPSE_CHANGED , Column . EVENT_DIRTY_HEADER , Column . EVENT_DIRTY_VALUES , Column . EVENT_DIRTY ] , this . collapsed , ( this . collapsed = value ) ) ; } getCollapsed ( ) { return this . collapsed ; } isShowNestedSummaries ( ) { return ( this . desc as IMultiLevelCompositeColumnDesc ) . showNestedSummaries !== false ; } dump ( toDescRef ) { const r = super . dump ( toDescRef ) ; r . collapsed = this . collapsed ; return r ; } restore ( dump , factory ) { this . collapsed = dump . collapsed === true ; super . restore ( dump , factory ) ; } flatten ( r , offset , levelsToGo = 0 , padding = 0 ) { return StackColumn . prototype . flatten . call ( this , r , offset , levelsToGo , padding ) ; } param col param index insert ( col , index ) { col . on ( `${ Column . EVENT_WIDTH_CHANGED }.stack` , this . adaptChange ) ; super . setWidth ( this . length === 0 ? col . getWidth ( ) : this . getWidth ( ) + col . getWidth ( ) ) ; return super . insert ( col , index ) ; } param oldValue param newValue private adaptWidthChange ( oldValue , newValue ) { if ( similar ( oldValue , newValue , 0.5 ) ) { return ; } const act = this . getWidth ( ) ; const next = act + ( newValue - oldValue ) ; this . fire ( [ MultiLevelCompositeColumn . EVENT_MULTI_LEVEL_CHANGED , Column . EVENT_DIRTY_HEADER , Column . EVENT_DIRTY ] , act , next ) ; super . setWidth ( next ) ; } removeImpl ( child , index ) { child . on ( `${ Column . EVENT_WIDTH_CHANGED }.stack` , null ) ; super . setWidth ( this . length === 0 ? 100 : this . getWidth ( ) - child . getWidth ( ) ) ; return super . removeImpl ( child , index ) ; } setWidth ( value ) { const act = this . getWidth ( ) ; const factor = value / act ; this . _children . forEach ( ( child ) => { child . setWidthImpl ( child . getWidth ( ) * factor ) ; } ) ; if ( ! similar ( act , value , 0.5 ) ) { this . fire ( [ MultiLevelCompositeColumn . EVENT_MULTI_LEVEL_CHANGED , Column . EVENT_DIRTY_HEADER , Column . EVENT_DIRTY ] , act , value ) ; } super . setWidth ( value ) ; } getRenderer ( ) { if ( this . getCollapsed ( ) ) { return MultiLevelCompositeColumn . COLLAPSED_RENDERER ; } return super . getRenderer ( ) ; } getExportValue ( row , format ) { if ( format === 'json' ) { return { children : this . children . map ( ( d ) => d . getExportValue ( row , format ) ) , } ; } return super . getExportValue ( row , format ) ; } }