import { Category } from './annotations' ; import ValueColumn from './ValueColumn' ; import { empty } from '../internal' ; import type { IArrayColumn , IArrayDesc } from './IArrayColumn' ; import type { IDataRow , IValueColumnDesc } from './interfaces' ; export interface IArrayColumnDesc < T > extends IArrayDesc , IValueColumnDesc < T [ ] > { } @ Category ( 'array' ) export default class ArrayColumn < T > extends ValueColumn < T [ ] > implements IArrayColumn < T > { private readonly _dataLength : number | null ; private readonly originalLabels : string [ ] ; constructor ( id , desc ) { super ( id , desc ) ; this . _dataLength = desc . dataLength == null || Number . isNaN ( desc . dataLength ) ? null : desc . dataLength ; this . originalLabels = desc . labels || empty ( this . _dataLength == null ? 0 : this . _dataLength ) . map ( ( _d , i ) => `Column ${ i }` ) ; } get labels ( ) { return this . originalLabels ; } get dataLength ( ) { return this . _dataLength ; } getValue ( row ) { const r = this . getValues ( row ) ; return r . every ( ( d ) => d === null ) ? null : r ; } getValues ( row ) { const r = super . getValue ( row ) ; return r == null ? [ ] : r ; } getLabels ( row ) { return this . getValues ( row ) . map ( String ) ; } getLabel ( row ) { const v = this . getLabels ( row ) ; if ( v . length === 0 ) { return '' ; } return v . toString ( ) ; } getMap ( row ) { const labels = this . labels ; return this . getValues ( row ) . map ( ( value , i ) => ( { key : labels [ i ] , value } ) ) ; } getMapLabel ( row ) { const labels = this . labels ; return this . getLabels ( row ) . map ( ( value , i ) => ( { key : labels [ i ] , value } ) ) ; } }