import type { ICategoricalDesc , ICategory , ICategoricalLikeColumn , ICategoricalColorMappingFunction , } from './ICategoricalColumn' ; import type { IDataRow , ITypeFactory } from './interfaces' ; import MapColumn , { IMapColumnDesc } from './MapColumn' ; import { DEFAULT_CATEGORICAL_COLOR_FUNCTION } from './CategoricalColorMappingFunction' ; import CategoricalColumn from './CategoricalColumn' ; 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 { toolbar } from './annotations' ; import { toCategories } from './internalCategorical' ; export declare type ICategoricalMapColumnDesc = ICategoricalDesc & IMapColumnDesc < string | null > ; asMemberOf event export declare function colorMappingChanged_CMC ( previous , current ) ; @ toolbar ( 'rename' , 'colorMappedCategorical' ) export default class CategoricalMapColumn extends MapColumn < string | null > implements ICategoricalLikeColumn { static readonly EVENT_COLOR_MAPPING_CHANGED = CategoricalColumn . EVENT_COLOR_MAPPING_CHANGED ; readonly categories : ICategory [ ] ; private readonly lookup = new Map < string , Readonly < ICategory > > ( ) ; private colorMapping : ICategoricalColorMappingFunction ; constructor ( id , desc ) { super ( id , desc ) ; this . categories = toCategories ( desc ) ; this . categories . forEach ( ( d ) => this . lookup . set ( d . name , d ) ) ; this . colorMapping = DEFAULT_CATEGORICAL_COLOR_FUNCTION ; } protected createEventList ( ) { return super . createEventList ( ) . concat ( [ CategoricalMapColumn . 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 ) ; } private parseValue ( v ) { if ( ! v ) { return null ; } const vs = String ( v ) ; return this . lookup . has ( vs ) ? this . lookup . get ( vs ) ! : null ; } getCategoryMap ( row ) { return super . getMap ( row ) . map ( ( { key , value } ) => ( { key , value : this . parseValue ( value ) , } ) ) ; } getCategories ( row ) { return this . getCategoryMap ( row ) . map ( ( d ) => d . value ) ; } getColors ( row ) { return this . getCategoryMap ( row ) . map ( ( { key , value } ) => ( { key , value : value ? this . colorMapping . apply ( value ) : DEFAULT_COLOR , } ) ) ; } getValue ( row ) { const r = this . getCategoryMap ( row ) ; return r . length === 0 ? null : r . map ( ( { key , value } ) => ( { key , value : value ? value . name : null , } ) ) ; } getLabels ( row ) { return this . getCategoryMap ( row ) . map ( ( { key , value } ) => ( { key , value : value ? value . label : '' , } ) ) ; } 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 ) ; } iterCategory ( row ) { return this . getCategories ( row ) ; } }