'use strict' ; import type DataEventEmitter from '../DataEventEmitter' ; import DataModifier from './DataModifier.js' ; import DataTable from '../DataTable.js' ; import U from '../../Core/Utilities.js' ; const { merge } = U ; private class ChainModifier extends DataModifier < ChainModifier . Event > { /**
     * Default option for the ordered modifier chain.
     */ public static readonly defaultOptions : ChainModifier . Options = { modifier : 'Chain' , reverse : false } ; param { DeepPartial < ChainModifier . Options > } options param { ... DataModifier } modifiers public constructor ( options ? , ... modifiers ) { super ( ) ; this . modifiers = modifiers ; this . options = merge ( ChainModifier . defaultOptions , options ) ; } /**
     * Ordered modifiers.
     */ public readonly modifiers : Array < DataModifier > ; /**
     * Options of the modifier chain.
     */ public readonly options : ChainModifier . Options ; param { DataModifier } modifier param { DataEventEmitter . EventDetail } eventDetail public add ( modifier , eventDetail ? ) { this . emit ( { type : 'addModifier' , detail : eventDetail , modifier } ) ; this . modifiers . push ( modifier ) ; this . emit ( { type : 'addModifier' , detail : eventDetail , modifier } ) ; } param { DataEventEmitter . EventDetail } eventDetail public clear ( eventDetail ? ) { this . emit ( { type : 'clearChain' , detail : eventDetail } ) ; this . modifiers . length = 0 ; this . emit ( { type : 'afterClearChain' , detail : eventDetail } ) ; } param { Highcharts . DataTable } table param { string } columnName param { number | undefined } rowIndex param { Highcharts . DataTableCellType } cellValue param { Highcharts . DataTableEventDetail } eventDetail return { Highcharts . DataTable } public modifyCell < T extends DataTable > ( table , columnName , rowIndex , cellValue , eventDetail ? ) { const modifiers = ( this . options . reverse ? this . modifiers . reverse ( ) : this . modifiers ) ; if ( modifiers . length ) { let clone = table . clone ( ) ; for ( let i = 0 , iEnd = modifiers . length ; i < iEnd ; ++ i ) { modifiers [ i ] . modifyCell ( clone , columnName , rowIndex , cellValue , eventDetail ) ; clone = clone . modified ; } table . modified = clone ; } return table ; } param { Highcharts . DataTable } table param { Highcharts . DataTableColumnCollection } columns param { number } rowIndex param { Highcharts . DataTableEventDetail } eventDetail return { Highcharts . DataTable } public modifyColumns < T extends DataTable > ( table , columns , rowIndex , eventDetail ? ) { const modifiers = ( this . options . reverse ? this . modifiers . reverse ( ) : this . modifiers . slice ( ) ) ; if ( modifiers . length ) { let clone = table . clone ( ) ; for ( let i = 0 , iEnd = modifiers . length ; i < iEnd ; ++ i ) { modifiers [ i ] . modifyColumns ( clone , columns , rowIndex , eventDetail ) ; clone = clone . modified ; } table . modified = clone ; } return table ; } param { Highcharts . DataTable } table param { Array < ( Highcharts . DataTableRow | Highcharts . DataTableRowObject ) > } rows param { number } rowIndex param { Highcharts . DataTableEventDetail } eventDetail return { Highcharts . DataTable } public modifyRows < T extends DataTable > ( table , rows , rowIndex , eventDetail ? ) { const modifiers = ( this . options . reverse ? this . modifiers . reverse ( ) : this . modifiers . slice ( ) ) ; if ( modifiers . length ) { let clone = table . clone ( ) ; for ( let i = 0 , iEnd = modifiers . length ; i < iEnd ; ++ i ) { modifiers [ i ] . modifyRows ( clone , rows , rowIndex , eventDetail ) ; clone = clone . modified ; } table . modified = clone ; } return table ; } param { DataTable } table param { DataEventEmitter . EventDetail } eventDetail return { DataTable } emits emits public modifyTable < T extends DataTable > ( table , eventDetail ? ) { const chain = this ; chain . emit ( { type : 'modify' , detail : eventDetail , table } ) ; const modifiers = ( chain . options . reverse ? chain . modifiers . reverse ( ) : chain . modifiers . slice ( ) ) ; let modified = table . modified ; for ( let i = 0 , iEnd = modifiers . length , modifier ; i < iEnd ; ++ i ) { modifier = modifiers [ i ] ; modified = modifier . modifyTable ( modified ) . modified ; } table . modified = modified ; chain . emit ( { type : 'afterModify' , detail : eventDetail , table } ) ; return table ; } param { DataModifier } modifier param { DataEventEmitter . EventDetail } eventDetail public remove ( modifier , eventDetail ? ) { const modifiers = this . modifiers ; this . emit ( { type : 'removeModifier' , detail : eventDetail , modifier } ) ; modifiers . splice ( modifiers . indexOf ( modifier ) , 1 ) ; this . emit ( { type : 'afterRemoveModifier' , detail : eventDetail , modifier } ) ; } } /**
 * Additionally provided types for modifier events and options, and JSON
 * conversion.
 */ namespace ChainModifier { /**
     * Event object
     */ export interface ChainEvent extends DataEventEmitter . Event { readonly type : ( 'clearChain' | 'afterClearChain' | DataModifier . Event [ 'type' ] ) ; readonly table ? : DataTable ; } /**
     * Event information.
     */ export type Event = ( ChainEvent | ModifierEvent ) ; /**
     * Event information for modifier operations.
     */ export interface ModifierEvent extends DataEventEmitter . Event { readonly type : ( 'addModifier' | 'afterAddModifier' | 'removeModifier' | 'afterRemoveModifier' ) ; readonly modifier : DataModifier ; } /**
     * Options to configure the modifier.
     */ export interface Options extends DataModifier . Options { /**
         * Whether to revert the order before execution.
         */ reverse : boolean ; } } DataModifier . addModifier ( ChainModifier ) ; declare module './ModifierType' { interface ModifierTypeRegistry { Chain : typeof ChainModifier ; } } export default ChainModifier ;