import { format } from 'd3-format' ; import CompositeColumn from './CompositeColumn' ; import type { IDataRow , IGroup , IColumnDesc } from './interfaces' ; import { isMissingValue } from './missing' ; import NumberColumn from './NumberColumn' ; import { SortByDefault , toolbar } from './annotations' ; import type { ISequence } from '../internal' ; import type { INumberColumn } from './INumberColumn' ; export interface ICompositeNumberDesc extends IColumnDesc { default numberFormat ? : string ; } export declare type ICompositeNumberColumnDesc = ICompositeNumberDesc & IColumnDesc ; /**
 * implementation of a combine column, standard operations how to select
 */ @ toolbar ( 'rename' , 'clone' , 'sort' , 'sortBy' , 'group' , 'groupBy' ) @ SortByDefault ( 'descending' ) export default class CompositeNumberColumn extends CompositeColumn implements INumberColumn { private readonly numberFormat : ( n : number ) => string = format ( '.3n' ) ; constructor ( id , desc ) { super ( id , desc ) ; if ( desc . numberFormat ) { this . numberFormat = format ( desc . numberFormat ) ; } } getNumberFormat ( ) { return this . numberFormat ; } getLabel ( row ) { if ( ! this . isLoaded ( ) ) { return '' ; } const v = this . getValue ( row ) ; return String ( typeof v === 'number' && ! Number . isNaN ( v ) && isFinite ( v ) ? this . numberFormat ( v ) : v ) ; } getValue ( row ) { if ( ! this . isLoaded ( ) ) { return null ; } const v = this . compute ( row ) ; if ( isMissingValue ( v ) ) { return null ; } return v ; } protected compute ( _row ) { return NaN ; } getNumber ( row ) { const r = this . getValue ( row ) ; return r == null ? NaN : r ; } getRawNumber ( row ) { return this . getNumber ( row ) ; } iterNumber ( row ) { return [ this . getNumber ( row ) ] ; } iterRawNumber ( row ) { return [ this . getRawNumber ( row ) ] ; } getExportValue ( row , format ) { if ( format === 'json' ) { return { value : this . getRawNumber ( row ) , children : this . children . map ( ( d ) => d . getExportValue ( row , format ) ) , } ; } return super . getExportValue ( row , format ) ; } toCompareValue ( row ) { return NumberColumn . prototype . toCompareValue . call ( this , row ) ; } toCompareValueType ( ) { return NumberColumn . prototype . toCompareValueType . call ( this ) ; } toCompareGroupValue ( rows , group ) { return NumberColumn . prototype . toCompareGroupValue . call ( this , rows , group ) ; } toCompareGroupValueType ( ) { return NumberColumn . prototype . toCompareGroupValueType . call ( this ) ; } getRenderer ( ) { return NumberColumn . prototype . getRenderer . call ( this ) ; } }