import ArrayColumn , { IArrayColumnDesc } from './ArrayColumn' ; import type { ISetColumn , ICategoricalColorMappingFunction } from './ICategoricalColumn' ; import type { IDataRow , ITypeFactory , ECompareValueType } from './interfaces' ; import CategoricalColumn from './CategoricalColumn' ; import { DEFAULT_CATEGORICAL_COLOR_FUNCTION } from './CategoricalColorMappingFunction' ; import type ValueColumn from './ValueColumn' ; import type { dataLoaded } from './ValueColumn' ; import { DEFAULT_COLOR , labelChanged , metaDataChanged , dirty , dirtyHeader , dirtyValues , rendererTypeChanged , groupRendererChanged , summaryRendererChanged , visibilityChanged , widthChanged , dirtyCaches , } from './Column' ; import type Column from './Column' ; import type { IEventListener } from '../internal' ; import { chooseUIntByDataLength , integrateDefaults } from './internal' ; import { toCategory } from './internalCategorical' ; import { toolbar } from './annotations' ; export declare type IBooleansColumnDesc = IArrayColumnDesc < boolean > ; asMemberOf event export declare function colorMappingChanged_BCS ( previous , current ) ; @ toolbar ( 'rename' , 'clone' , 'sort' , 'sortBy' ) export default class BooleansColumn extends ArrayColumn < boolean > implements ISetColumn { static readonly EVENT_COLOR_MAPPING_CHANGED = CategoricalColumn . EVENT_COLOR_MAPPING_CHANGED ; private colorMapping : ICategoricalColorMappingFunction ; constructor ( id , desc ) { super ( id , integrateDefaults ( desc , { renderer : 'upset' , } ) ) ; this . colorMapping = DEFAULT_CATEGORICAL_COLOR_FUNCTION ; } get categories ( ) { return this . labels . map ( ( d , i ) => toCategory ( d , i ) ) ; } getSet ( row ) { const vs = this . getValues ( row ) ; return new Set ( this . categories . filter ( ( _ , i ) => vs [ i ] ) ) ; } toCompareValue ( row ) { const v = this . getValue ( row ) ; if ( v == null ) { return NaN ; } return v . reduce ( ( a , b ) => a + ( b ? 1 : 0 ) , 0 ) ; } toCompareValueType ( ) { return chooseUIntByDataLength ( this . dataLength ) ; } getCategories ( row ) { const categories = this . categories ; return super . getValues ( row ) . map ( ( v , i ) => { return v ? categories [ i ] ! : null ; } ) ; } iterCategory ( row ) { return this . getCategories ( row ) ; } getColors ( row ) { return this . getCategories ( row ) . map ( ( d ) => ( d ? this . colorMapping . apply ( d ) : DEFAULT_COLOR ) ) ; } protected createEventList ( ) { return super . createEventList ( ) . concat ( [ BooleansColumn . EVENT_COLOR_MAPPING_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 ) { return super . on ( type as any , listener ) ; } getColorMapping ( ) { return this . colorMapping . clone ( ) ; } setColorMapping ( mapping ) { return CategoricalColumn . prototype . setColorMapping . call ( this , mapping ) ; } dump ( toDescRef ) { const r = super . dump ( toDescRef ) ; r . colorMapping = this . colorMapping . toJSON ( ) ; return r ; } restore ( dump , factory ) { super . restore ( dump , factory ) ; this . colorMapping = factory . categoricalColorMappingFunction ( dump . colorMapping , this . categories ) ; } }