'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 InvertModifier extends DataModifier { /**
     * Default options for the invert modifier.
     */ public static readonly defaultOptions : InvertModifier . Options = { modifier : 'InvertModifier' } ; param { InvertModifier . Options } options public constructor ( options ? ) { super ( ) ; this . options = merge ( InvertModifier . defaultOptions , options ) ; } /**
     * Options of the invert modifier.
     */ public options : InvertModifier . Options ; 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 modified = table . modified , modifiedRowIndex = modified . getRowIndexBy ( 'columnNames' , columnName ) ; if ( typeof modifiedRowIndex === 'undefined' ) { modified . setColumns ( this . modifyTable ( table . clone ( ) ) . getColumns ( ) , void 0 , eventDetail ) ; } else { modified . setCell ( `${ rowIndex }` , modifiedRowIndex , cellValue , eventDetail ) ; } 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 modified = table . modified , modifiedColumnNames = ( modified . getColumn ( 'columnNames' ) || [ ] ) ; let columnNames = table . getColumnNames ( ) , reset = ( table . getRowCount ( ) !== modifiedColumnNames . length ) ; if ( ! reset ) { for ( let i = 0 , iEnd = columnNames . length ; i < iEnd ; ++ i ) { if ( columnNames [ i ] !== modifiedColumnNames [ i ] ) { reset = true ; break ; } } } if ( reset ) { return this . modifyTable ( table , eventDetail ) ; } columnNames = Object . keys ( columns ) ; for ( let i = 0 , iEnd = columnNames . length , column , columnName , modifiedRowIndex ; i < iEnd ; ++ i ) { columnName = columnNames [ i ] ; column = columns [ columnName ] ; modifiedRowIndex = ( modified . getRowIndexBy ( 'columnNames' , columnName ) || modified . getRowCount ( ) ) ; for ( let j = 0 , j2 = rowIndex , jEnd = column . length ; j < jEnd ; ++ j , ++ j2 ) { modified . setCell ( `${ j2 }` , modifiedRowIndex , column [ j ] , eventDetail ) ; } } 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 columnNames = table . getColumnNames ( ) , modified = table . modified , modifiedColumnNames = ( modified . getColumn ( 'columnNames' ) || [ ] ) ; let reset = ( table . getRowCount ( ) !== modifiedColumnNames . length ) ; if ( ! reset ) { for ( let i = 0 , iEnd = columnNames . length ; i < iEnd ; ++ i ) { if ( columnNames [ i ] !== modifiedColumnNames [ i ] ) { reset = true ; break ; } } } if ( reset ) { return this . modifyTable ( table , eventDetail ) ; } for ( let i = 0 , i2 = rowIndex , iEnd = rows . length , row ; i < iEnd ; ++ i , ++ i2 ) { row = rows [ i ] ; if ( row instanceof Array ) { modified . setColumn ( `${ i2 }` , row ) ; } else { for ( let j = 0 , jEnd = columnNames . length ; j < jEnd ; ++ j ) { modified . setCell ( `${ i2 }` , j , row [ columnNames [ j ] ] , eventDetail ) ; } } } return table ; } param { DataTable } table param { DataEventEmitter . EventDetail } eventDetail return { DataTable } public modifyTable < T extends DataTable > ( table , eventDetail ? ) { const modifier = this ; modifier . emit ( { type : 'modify' , detail : eventDetail , table } ) ; const modified = table . modified ; if ( table . hasColumns ( [ 'columnNames' ] ) ) { const columnNames = ( ( table . deleteColumns ( [ 'columnNames' ] ) || { } ) . columnNames || [ ] ) . map ( ( column ) : string => `${ column }` ) , columns = { } ; for ( let i = 0 , iEnd = table . getRowCount ( ) , row ; i < iEnd ; ++ i ) { row = table . getRow ( i ) ; if ( row ) { columns [ columnNames [ i ] ] = row ; } } modified . deleteColumns ( ) ; modified . setColumns ( columns ) ; } else { const columns = { } ; for ( let i = 0 , iEnd = table . getRowCount ( ) , row ; i < iEnd ; ++ i ) { row = table . getRow ( i ) ; if ( row ) { columns [ `${ i }` ] = row ; } } columns . columnNames = table . getColumnNames ( ) ; modified . deleteColumns ( ) ; modified . setColumns ( columns ) ; } modifier . emit ( { type : 'afterModify' , detail : eventDetail , table } ) ; return table ; } } /**
 * Additionally provided types for modifier events and options, and JSON
 * conversion.
 */ namespace InvertModifier { /**
     * Options to configure the modifier.
     */ export interface Options extends DataModifier . Options { } } DataModifier . addModifier ( InvertModifier ) ; declare module './ModifierType' { interface ModifierTypeRegistry { Invert : typeof InvertModifier ; } } export default InvertModifier ;