import type { IArrayDesc , IColumnDesc } from '../../model' ; export default class ColumnBuilder < T extends IColumnDesc = IColumnDesc > { protected readonly desc : T ; constructor ( type , column ) { this . desc = { column , type , label : column ? column [ 0 ] . toUpperCase ( ) + column . slice ( 1 ) : type } as any ; } /**
     * column label
     */ label ( label ) { this . desc . label = label ; return this ; } /**
     * hide this column by default
     */ hidden ( ) { this . desc . visible = false ; return this ; } /**
     * column summary text (subtitle)
     */ summary ( summary ) { this . desc . summary = summary ; return this ; } /**
     * column description
     */ description ( description ) { this . desc . description = description ; return this ; } /**
     * sets the frozen state of this column, i.e is sticky to the left side when scrolling horizontally
     */ frozen ( ) { this . desc . frozen = true ; return this ; } param { string } renderer param { string } groupRenderer param { string } summaryRenderer renderer ( renderer ? , groupRenderer ? , summaryRenderer ? ) { if ( renderer ) { this . desc . renderer = renderer ; } if ( groupRenderer ) { this . desc . groupRenderer = groupRenderer ; } if ( summaryRenderer ) { this . desc . summaryRenderer = summaryRenderer ; } return this ; } param { string } key param value custom ( key , value ) { ( this . desc as any ) [ key ] = value ; return this ; } /**
     * sets the default width of the column
     */ width ( width ) { this . desc . width = width ; return this ; } deprecated color ( _color ) { return this ; } param { string [ ] | number } labels asArray ( labels ? ) { console . assert ( [ 'boolean' , 'categorical' , 'date' , 'number' , 'string' , 'link' ] . includes ( this . desc . type ! ) ) ; this . desc . type += 's' ; const a = this . desc as IArrayDesc ; if ( Array . isArray ( labels ) ) { a . labels = labels ; a . dataLength = labels . length ; } else if ( typeof labels === 'number' ) { a . dataLength = labels ; } return this ; } /**
     * converts the column type to be a map type, supports only base types: categorical, date, number, and string
     */ asMap ( ) { console . assert ( [ 'categorical' , 'date' , 'number' , 'string' , 'link' ] . includes ( this . desc . type ! ) ) ; this . desc . type += 'Map' ; return this ; } /**
     * build the column description
     */ build ( _data ) { return this . desc as any ; } } param { string } type param { string } column returns { ColumnBuilder < IColumnDesc > } export function buildColumn ( type , column ) { return new ColumnBuilder ( type , column ) ; }