@@ -3,7 +3,7 @@ import { interpolateNumberArray } from '../animation';
33import { outlierPositioner , patchInHoveredOutlier } from '../tooltip' ;
44import { defaultStatsOptions , IBaseOptions , IBaseStats } from '../data' ;
55
6- export /* #__PURE__ */ function baseDefaults ( keys : string [ ] ) {
6+ export /* #__PURE__ */ function baseDefaults ( keys : string [ ] ) : Record < string , unknown > {
77 const colorKeys = [ 'borderColor' , 'backgroundColor' ] . concat ( keys . filter ( ( c ) => c . endsWith ( 'Color' ) ) ) ;
88 return {
99 animations : {
@@ -42,7 +42,7 @@ export /* #__PURE__ */ function baseDefaults(keys: string[]) {
4242 } ;
4343}
4444
45- export function defaultOverrides ( ) {
45+ export function defaultOverrides ( ) : Record < string , unknown > {
4646 return {
4747 plugins : {
4848 tooltips : {
@@ -58,15 +58,18 @@ export function defaultOverrides() {
5858export abstract class StatsBase < S extends IBaseStats , C extends Required < IBaseOptions > > extends BarController {
5959 declare options : C ;
6060
61+ // eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
6162 protected _transformStats < T > ( target : any , source : S , mapper : ( v : number ) => T ) : void {
6263 for ( const key of [ 'min' , 'max' , 'median' , 'q3' , 'q1' , 'mean' ] as const ) {
6364 const v = source [ key ] ;
6465 if ( typeof v === 'number' ) {
66+ // eslint-disable-next-line no-param-reassign
6567 target [ key ] = mapper ( v ) ;
6668 }
6769 }
6870 for ( const key of [ 'outliers' , 'items' ] as const ) {
6971 if ( Array . isArray ( source [ key ] ) ) {
72+ // eslint-disable-next-line no-param-reassign
7073 target [ key ] = source [ key ] . map ( mapper ) ;
7174 }
7275 }
@@ -75,20 +78,25 @@ export abstract class StatsBase<S extends IBaseStats, C extends Required<IBaseOp
7578 getMinMax ( scale : Scale , canStack ?: boolean | undefined ) : { min : number ; max : number } {
7679 const bak = scale . axis ;
7780 const config = this . options ;
81+ // eslint-disable-next-line no-param-reassign
7882 scale . axis = config . minStats ;
7983 const { min } = super . getMinMax ( scale , canStack ) ;
84+ // eslint-disable-next-line no-param-reassign
8085 scale . axis = config . maxStats ;
8186 const { max } = super . getMinMax ( scale , canStack ) ;
87+ // eslint-disable-next-line no-param-reassign
8288 scale . axis = bak ;
8389 return { min, max } ;
8490 }
8591
86- parsePrimitiveData ( meta : ChartMeta , data : any [ ] , start : number , count : number ) {
92+ parsePrimitiveData ( meta : ChartMeta , data : any [ ] , start : number , count : number ) : Record < string , unknown > [ ] {
93+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
8794 const vScale = meta . vScale ! ;
95+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
8896 const iScale = meta . iScale ! ;
8997 const labels = iScale . getLabels ( ) ;
9098 const r = [ ] ;
91- for ( let i = 0 ; i < count ; i ++ ) {
99+ for ( let i = 0 ; i < count ; i += 1 ) {
92100 const index = i + start ;
93101 const parsed : any = { } ;
94102 parsed [ iScale . axis ] = iScale . parse ( labels [ index ] , index ) ;
@@ -102,17 +110,18 @@ export abstract class StatsBase<S extends IBaseStats, C extends Required<IBaseOp
102110 return r ;
103111 }
104112
105- parseArrayData ( meta : ChartMeta , data : any [ ] , start : number , count : number ) {
113+ parseArrayData ( meta : ChartMeta , data : any [ ] , start : number , count : number ) : Record < string , unknown > [ ] {
106114 return this . parsePrimitiveData ( meta , data , start , count ) ;
107115 }
108116
109- parseObjectData ( meta : ChartMeta , data : any [ ] , start : number , count : number ) {
117+ parseObjectData ( meta : ChartMeta , data : any [ ] , start : number , count : number ) : Record < string , unknown > [ ] {
110118 return this . parsePrimitiveData ( meta , data , start , count ) ;
111119 }
112120
121+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
113122 protected abstract _parseStats ( value : any , options : C ) : S | undefined ;
114123
115- getLabelAndValue ( index : number ) {
124+ getLabelAndValue ( index : number ) : { label : string ; value : string & { raw : S ; hoveredOutlierIndex : number } & S } {
116125 const r = super . getLabelAndValue ( index ) as any ;
117126 const { vScale } = this . _cachedMeta ;
118127 const parsed = ( this . getParsed ( index ) as unknown ) as S ;
@@ -125,7 +134,7 @@ export abstract class StatsBase<S extends IBaseStats, C extends Required<IBaseOp
125134 } ;
126135 this . _transformStats ( r . value , parsed , ( v ) => vScale . getLabelForValue ( v ) ) ;
127136 const s = this . _toStringStats ( r . value ) ;
128- r . value . toString = function ( ) {
137+ r . value . toString = function toString ( ) {
129138 // custom to string function for the 'value'
130139 if ( this . hoveredOutlierIndex >= 0 ) {
131140 // TODO formatter
@@ -136,20 +145,24 @@ export abstract class StatsBase<S extends IBaseStats, C extends Required<IBaseOp
136145 return r ;
137146 }
138147
139- protected _toStringStats ( b : S ) {
148+ // eslint-disable-next-line class-methods-use-this
149+ protected _toStringStats ( b : S ) : string {
140150 // TODO formatter
141151 const f = ( v : number ) => ( v == null ? 'NaN' : v . toLocaleString ( ) ) ;
142152 return `(min: ${ f ( b . min ) } , 25% quantile: ${ f ( b . q1 ) } , median: ${ f ( b . median ) } , mean: ${ f ( b . mean ) } , 75% quantile: ${ f (
143153 b . q3
144154 ) } , max: ${ f ( b . max ) } )`;
145155 }
146156
157+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
147158 updateElement ( rectangle : Element , index : number , properties : any , mode : UpdateMode ) : void {
148159 const reset = mode === 'reset' ;
149160 const scale = this . _cachedMeta . vScale as LinearScale ;
150161 const parsed = ( this . getParsed ( index ) as unknown ) as S ;
151162 const base = scale . getBasePixel ( ) ;
163+ // eslint-disable-next-line no-param-reassign
152164 properties . _datasetIndex = this . index ;
165+ // eslint-disable-next-line no-param-reassign
153166 properties . _index = index ;
154167 this . _transformStats ( properties , parsed , ( v ) => ( reset ? base : scale . getPixelForValue ( v , index ) ) ) ;
155168 super . updateElement ( rectangle , index , properties , mode ) ;
0 commit comments