import { AEventDispatcher , ISequence , similar , fixCSS , IEventListener } from '../internal' ; import { isSortingAscByDefault } from './annotations' ; import { IColumnDump , ISortCriteria , defaultGroup , ECompareValueType , IColumnDesc , IDataRow , IGroup , IColumnParent , IColumnMetaData , IFlatColumn , ICompareValue , ITypeFactory , } from './interfaces' ; import type Ranking from './Ranking' ; type { string } export const DEFAULT_COLOR = '#C1C1C1' ; asMemberOf event export declare function widthChanged ( previous , current ) ; asMemberOf event export declare function labelChanged ( previous , current ) ; asMemberOf event export declare function metaDataChanged ( previous , current ) ; asMemberOf event export declare function dirty ( ) ; asMemberOf event export declare function dirtyHeader ( ) ; asMemberOf event export declare function dirtyValues ( ) ; asMemberOf event export declare function dirtyCaches ( ) ; asMemberOf event export declare function rendererTypeChanged ( previous , current ) ; asMemberOf event export declare function groupRendererChanged ( previous , current ) ; asMemberOf event export declare function summaryRendererChanged ( previous , current ) ; asMemberOf event export declare function visibilityChanged ( previous , current ) ; /**
 * a column in LineUp
 */ export default class Column extends AEventDispatcher { type { number } static readonly FLAT_ALL_COLUMNS = - 1 ; static readonly EVENT_WIDTH_CHANGED = 'widthChanged' ; static readonly EVENT_LABEL_CHANGED = 'labelChanged' ; static readonly EVENT_METADATA_CHANGED = 'metaDataChanged' ; static readonly EVENT_DIRTY = 'dirty' ; static readonly EVENT_DIRTY_HEADER = 'dirtyHeader' ; static readonly EVENT_DIRTY_VALUES = 'dirtyValues' ; static readonly EVENT_DIRTY_CACHES = 'dirtyCaches' ; static readonly EVENT_RENDERER_TYPE_CHANGED = 'rendererTypeChanged' ; static readonly EVENT_GROUP_RENDERER_TYPE_CHANGED = 'groupRendererChanged' ; static readonly EVENT_SUMMARY_RENDERER_TYPE_CHANGED = 'summaryRendererChanged' ; static readonly EVENT_VISIBILITY_CHANGED = 'visibilityChanged' ; /**
     * the id of this column
     */ private uid : string ; type { number } private private width = 100 ; /**
     * parent column of this column, set when added to a ranking or combined column
     */ parent : Readonly < IColumnParent > | null = null ; private metadata : Readonly < IColumnMetaData > ; private renderer : string ; private groupRenderer : string ; private summaryRenderer : string ; private visible : boolean ; constructor ( id , public readonly desc ) { super ( ) ; this . uid = fixCSS ( id ) ; this . renderer = this . desc . renderer || this . desc . type ; this . groupRenderer = this . desc . groupRenderer || this . desc . type ; this . summaryRenderer = this . desc . summaryRenderer || this . desc . type ; this . width = this . desc . width != null && this . desc . width > 0 ? this . desc . width : 100 ; this . visible = this . desc . visible !== false ; this . metadata = { label : desc . label || this . id , summary : desc . summary || '' , description : desc . description || '' , } ; } get fixed ( ) { return Boolean ( this . desc . fixed ) ; } get frozen ( ) { return Boolean ( this . desc . frozen ) ; } get id ( ) { return this . uid ; } assignNewId ( idGenerator ) { this . uid = fixCSS ( idGenerator ( ) ) ; } get label ( ) { return this . metadata . label ; } get description ( ) { return this . metadata . description ; } returns { string } get fqid ( ) { return this . parent ? `${ this . parent . fqid }_${ this . id }` : this . id ; } get fqpath ( ) { return this . parent ? `${ this . parent . fqpath }@${ this . parent . indexOf ( this ) }` : '' ; } protected createEventList ( ) { return super . createEventList ( ) . concat ( [ Column . EVENT_WIDTH_CHANGED , Column . EVENT_LABEL_CHANGED , Column . EVENT_METADATA_CHANGED , Column . EVENT_VISIBILITY_CHANGED , Column . EVENT_SUMMARY_RENDERER_TYPE_CHANGED , Column . EVENT_RENDERER_TYPE_CHANGED , Column . EVENT_GROUP_RENDERER_TYPE_CHANGED , Column . EVENT_DIRTY , Column . EVENT_DIRTY_HEADER , Column . EVENT_DIRTY_VALUES , Column . EVENT_DIRTY_CACHES , ] ) ; } 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 ) ; } getWidth ( ) { return this . width ; } hide ( ) { this . setVisible ( false ) ; } show ( ) { this . setVisible ( true ) ; } isVisible ( ) { return this . visible ; } getVisible ( ) { return this . isVisible ( ) ; } setVisible ( value ) { if ( this . visible === value ) { return ; } this . fire ( [ Column . EVENT_VISIBILITY_CHANGED , Column . EVENT_DIRTY_HEADER , Column . EVENT_DIRTY_VALUES , Column . EVENT_DIRTY ] , this . visible , ( this . visible = value ) ) ; } param { IFlatColumn } r param { number } offset param { number } _levelsToGo param { number } _padding returns { number } flatten ( r , offset , _levelsToGo = 0 , _padding = 0 ) { const w = this . getWidth ( ) ; r . push ( { col : this , offset , width : w } ) ; return w ; } setWidth ( value ) { if ( similar ( this . width , value , 0.5 ) ) { return ; } this . fire ( [ Column . EVENT_WIDTH_CHANGED , Column . EVENT_DIRTY_HEADER , Column . EVENT_DIRTY_VALUES , Column . EVENT_DIRTY ] , this . width , ( this . width = value ) ) ; } setWidthImpl ( value ) { this . width = value ; } setMetaData ( value ) { if ( value . label === this . label && this . description === value . description && this . metadata . summary === value . summary ) { return ; } const bak = this . getMetaData ( ) ; this . metadata = { label : value . label , summary : value . summary , description : value . description , } ; this . fire ( [ Column . EVENT_LABEL_CHANGED , Column . EVENT_METADATA_CHANGED , Column . EVENT_DIRTY_HEADER , Column . EVENT_DIRTY ] , bak , this . getMetaData ( ) ) ; } getMetaData ( ) { return Object . assign ( { } , this . metadata ) ; } param ascending param priority returns { boolean } sortByMe ( ascending = isSortingAscByDefault ( this ) , priority = 0 ) { const r = this . findMyRanker ( ) ; if ( r ) { return r . sortBy ( this , ascending , priority ) ; } return false ; } groupByMe ( ) { const r = this . findMyRanker ( ) ; if ( r ) { return r . toggleGrouping ( this ) ; } return false ; } return { number } isGroupedBy ( ) { const r = this . findMyRanker ( ) ; if ( ! r ) { return - 1 ; } return r . getGroupCriteria ( ) . indexOf ( this ) ; } returns { boolean } toggleMySorting ( ) { const r = this . findMyRanker ( ) ; if ( r ) { return r . toggleSorting ( this ) ; } return false ; } private isSortedByMeImpl ( selector ) { const ranker = this . findMyRanker ( ) ; if ( ! ranker ) { return { asc : undefined , priority : undefined } ; } const criterias = selector ( ranker ) ; const index = criterias . findIndex ( ( c ) => c . col === this ) ; if ( index < 0 ) { return { asc : undefined , priority : undefined } ; } return { asc : criterias [ index ] . asc ? 'asc' : 'desc' , priority : index , } ; } isSortedByMe ( ) { return this . isSortedByMeImpl ( ( r ) => r . getSortCriteria ( ) ) ; } groupSortByMe ( ascending = isSortingAscByDefault ( this ) , priority = 0 ) { const r = this . findMyRanker ( ) ; if ( r ) { return r . groupSortBy ( this , ascending , priority ) ; } return false ; } toggleMyGroupSorting ( ) { const r = this . findMyRanker ( ) ; if ( r ) { return r . toggleGroupSorting ( this ) ; } return false ; } isGroupSortedByMe ( ) { return this . isSortedByMeImpl ( ( r ) => r . getGroupSortCriteria ( ) ) ; } returns { boolean } removeMe ( ) { if ( this . fixed ) { return false ; } if ( this . parent ) { return this . parent . remove ( this ) ; } return false ; } /**
     * called when the columns added to a ranking
     */ attach ( parent ) { this . parent = parent ; } /**
     * called when the column is removed from the ranking
     */ detach ( ) { this . parent = null ; } param col returns { boolean } insertAfterMe ( col ) { if ( this . parent ) { return this . parent . insertAfter ( col , this ) != null ; } return false ; } returns { Ranking | null } findMyRanker ( ) { if ( this . parent ) { return this . parent . findMyRanker ( ) ; } return null ; } param toDescRef returns { any } dump ( toDescRef ) { const r = { id : this . id , desc : toDescRef ( this . desc ) , width : this . width , } ; if ( this . label !== ( this . desc . label || this . id ) ) { r . label = this . label ; } if ( this . metadata . summary ) { r . summary = this . metadata . summary ; } if ( this . getRenderer ( ) !== this . desc . type ) { r . renderer = this . getRenderer ( ) ; } if ( this . getGroupRenderer ( ) !== this . desc . type ) { r . groupRenderer = this . getGroupRenderer ( ) ; } if ( this . getSummaryRenderer ( ) !== this . desc . type ) { r . summaryRenderer = this . getSummaryRenderer ( ) ; } return r ; } param dump param _factory restore ( dump , _factory ) { this . uid = dump . id ; this . width = dump . width || this . width ; this . metadata = { label : dump . label || this . label , summary : dump . summary || '' , description : this . description , } ; if ( dump . renderer || dump . rendererType ) { this . renderer = dump . renderer || dump . rendererType || this . renderer ; } if ( dump . groupRenderer ) { this . groupRenderer = dump . groupRenderer ; } if ( dump . summaryRenderer ) { this . summaryRenderer = dump . summaryRenderer ; } } param row return { string } getLabel ( row ) { const v = this . getValue ( row ) ; return v == null ? '' : String ( v ) ; } param _row return getValue ( _row ) { return '' ; } param format getExportValue ( row , format ) { return format === 'text' ? this . getLabel ( row ) : this . getValue ( row ) ; } getColor ( _row ) { return DEFAULT_COLOR ; } toCompareValue ( _row , _valueCache ? ) { return 0 ; } toCompareValueType ( ) { return ECompareValueType . UINT8 ; } param _row return { IGroup } group ( _row , _valueCache ? ) { return Object . assign ( { } , defaultGroup ) ; } toCompareGroupValue ( _rows , group , _valueCache ? ) { return group . name . toLowerCase ( ) ; } toCompareGroupValueType ( ) { return ECompareValueType . STRING ; } return { boolean } isFiltered ( ) { return false ; } return { boolean } clearFilter ( ) { return false ; } param row return { boolean } filter ( row , _valueCache ? ) { return row != null ; } return { string } getRenderer ( ) { return this . renderer ; } getGroupRenderer ( ) { return this . groupRenderer ; } getSummaryRenderer ( ) { return this . summaryRenderer ; } setRenderer ( renderer ) { if ( renderer === this . renderer ) { return ; } this . fire ( [ Column . EVENT_RENDERER_TYPE_CHANGED , Column . EVENT_DIRTY_VALUES , Column . EVENT_DIRTY ] , this . renderer , ( this . renderer = renderer ) ) ; } setGroupRenderer ( renderer ) { if ( renderer === this . groupRenderer ) { return ; } this . fire ( [ Column . EVENT_GROUP_RENDERER_TYPE_CHANGED , Column . EVENT_DIRTY_VALUES , Column . EVENT_DIRTY ] , this . groupRenderer , ( this . groupRenderer = renderer ) ) ; } setSummaryRenderer ( renderer ) { if ( renderer === this . summaryRenderer ) { return ; } this . fire ( [ Column . EVENT_SUMMARY_RENDERER_TYPE_CHANGED , Column . EVENT_DIRTY_HEADER , Column . EVENT_DIRTY ] , this . summaryRenderer , ( this . summaryRenderer = renderer ) ) ; } param type markDirty ( type = 'all' ) { switch ( type ) { case 'header' : return this . fire ( [ Column . EVENT_DIRTY_HEADER , Column . EVENT_DIRTY ] ) ; case 'values' : return this . fire ( [ Column . EVENT_DIRTY_VALUES , Column . EVENT_DIRTY_CACHES , Column . EVENT_DIRTY ] ) ; default : return this . fire ( [ Column . EVENT_DIRTY_HEADER , Column . EVENT_DIRTY_VALUES , Column . EVENT_DIRTY_CACHES , Column . EVENT_DIRTY , ] ) ; } } }