import { timeFormat , timeParse } from 'd3-time-format' ; import type { IDateColumn , IDateFilter } from './IDateColumn' ; import type { IKeyValue } from './IArrayColumn' ; import type { IDataRow , ITypeFactory } from './interfaces' ; import MapColumn , { IMapColumnDesc } from './MapColumn' ; import { isMissingValue } from './missing' ; import DatesColumn , { EDateSort , IDatesDesc } from './DatesColumn' ; import DateColumn from './DateColumn' ; import { dialogAddons , toolbar } from './annotations' ; import type { widthChanged , labelChanged , metaDataChanged , dirty , dirtyHeader , dirtyValues , rendererTypeChanged , groupRendererChanged , summaryRendererChanged , visibilityChanged , dirtyCaches , } from './Column' ; import type Column from './Column' ; import type { dataLoaded } from './ValueColumn' ; import type ValueColumn from './ValueColumn' ; import type { IEventListener } from '../internal' ; import { noDateFilter , isDummyDateFilter , restoreDateFilter } from './internalDate' ; import { integrateDefaults } from './internal' ; export declare type IDateMapColumnDesc = IDatesDesc & IMapColumnDesc < Date | null > ; asMemberOf event export declare function sortMethodChanged_DMC ( previous , current ) ; asMemberOf event export declare function filterChanged_DMC ( previous , current ) ; @ toolbar ( 'rename' , 'filterDate' ) @ dialogAddons ( 'sort' , 'sortDates' ) export default class DatesMapColumn extends MapColumn < Date | null > implements IDateColumn { static readonly EVENT_SORTMETHOD_CHANGED = DatesColumn . EVENT_SORTMETHOD_CHANGED ; static readonly EVENT_FILTER_CHANGED = DateColumn . EVENT_FILTER_CHANGED ; private readonly format : ( date : Date | null ) => string ; private readonly parse : ( date : string ) => Date | null ; private sort : EDateSort ; private currentFilter : IDateFilter = noDateFilter ( ) ; constructor ( id , desc ) { super ( id , integrateDefaults ( desc , { renderer : 'default' , } ) ) ; const f = timeFormat ( desc . dateFormat || DateColumn . DEFAULT_DATE_FORMAT ) ; this . format = ( v ) => ( v instanceof Date ? f ( v ) : '' ) ; this . parse = desc . dateParse ? timeParse ( desc . dateParse ) : timeParse ( desc . dateFormat || DateColumn . DEFAULT_DATE_FORMAT ) ; this . sort = desc . sort || EDateSort . median ; } getFormatter ( ) { return this . format ; } protected createEventList ( ) { return super . createEventList ( ) . concat ( [ DatesMapColumn . EVENT_SORTMETHOD_CHANGED , DatesMapColumn . EVENT_FILTER_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 ) ; on ( type , listener ) { return super . on ( type as any , listener ) ; } private parseValue ( v ) { if ( isMissingValue ( v ) ) { return null ; } if ( v instanceof Date ) { return v ; } return this . parse ( String ( v ) ) ; } getDateMap ( row ) { return super . getMap ( row ) . map ( ( { key , value } ) => ( { key , value : this . parseValue ( value ) , } ) ) ; } iterDate ( row ) { return this . getDates ( row ) ; } getValue ( row ) { const r = this . getDateMap ( row ) ; return r . every ( ( d ) => d == null ) ? null : r ; } getLabels ( row ) { return this . getDateMap ( row ) . map ( ( { key , value } ) => ( { key , value : value instanceof Date ? this . format ( value ) : '' , } ) ) ; } getDates ( row ) { return this . getDateMap ( row ) . map ( ( v ) => v . value ) ; } getDate ( row ) { return DatesColumn . prototype . getDate . call ( this , row ) ; } getSortMethod ( ) { return this . sort ; } setSortMethod ( sort ) { return DatesColumn . prototype . setSortMethod . call ( this , sort ) ; } dump ( toDescRef ) { const r = super . dump ( toDescRef ) ; r . sortMethod = this . getSortMethod ( ) ; r . filter = ! isDummyDateFilter ( this . currentFilter ) ? this . currentFilter : null ; return r ; } restore ( dump , factory ) { super . restore ( dump , factory ) ; if ( dump . sortMethod ) { this . sort = dump . sortMethod ; } if ( dump . filter ) { this . currentFilter = restoreDateFilter ( dump . filter ) ; } } isFiltered ( ) { return DateColumn . prototype . isFiltered . call ( this ) ; } getFilter ( ) { return DateColumn . prototype . getFilter . call ( this ) ; } setFilter ( value ) { DateColumn . prototype . setFilter . call ( this , value ) ; } filter ( row ) { return DateColumn . prototype . filter . call ( this , row ) ; } clearFilter ( ) { return DateColumn . prototype . clearFilter . call ( this ) ; } }