@@ -112,57 +112,37 @@ export abstract class ChartData<U extends Entry, T extends IDataSet<U>> {
112
112
* Calc minimum and maximum values (both x and y) over all DataSets.
113
113
*/
114
114
calcMinMax ( ) {
115
- if ( ! this . mDataSets ) return ;
116
-
117
115
this . mYMax = - Infinity ;
118
116
this . mYMin = Infinity ;
119
117
this . mXMax = - Infinity ;
120
118
this . mXMin = Infinity ;
121
119
122
- const visibleDatasets = this . visibleDataSets ;
123
-
124
- for ( const set of visibleDatasets ) {
125
- if ( set . visible ) {
126
- this . calcMinMaxForDataSet ( set ) ;
127
- }
128
- }
129
-
130
120
this . mLeftAxisMax = - Infinity ;
131
121
this . mLeftAxisMin = Infinity ;
132
122
this . mRightAxisMax = - Infinity ;
133
123
this . mRightAxisMin = Infinity ;
124
+ if ( ! this . mDataSets || this . mDataSets . length === 0 ) return ;
134
125
135
- // left axis
136
- const firstLeft = this . getFirstLeft ( visibleDatasets ) ;
137
-
138
- if ( firstLeft ) {
139
- this . mLeftAxisMax = firstLeft . yMax ;
140
- this . mLeftAxisMin = firstLeft . yMin ;
141
-
142
- for ( const dataSet of visibleDatasets ) {
143
- if ( dataSet . axisDependency === AxisDependency . LEFT ) {
144
- if ( dataSet . yMin < this . mLeftAxisMin ) this . mLeftAxisMin = dataSet . yMin ;
126
+ const visibleDatasets = this . visibleDataSets ;
145
127
146
- if ( dataSet . yMax > this . mLeftAxisMax ) this . mLeftAxisMax = dataSet . yMax ;
147
- }
148
- }
128
+ for ( const set of visibleDatasets ) {
129
+ this . calcMinMaxForDataSet ( set ) ;
149
130
}
150
131
151
- // right axis
152
- const firstRight = this . getFirstRight ( visibleDatasets ) ;
153
-
154
- if ( firstRight ) {
155
- this . mRightAxisMax = firstRight . yMax ;
156
- this . mRightAxisMin = firstRight . yMin ;
157
-
158
- for ( const dataSet of visibleDatasets ) {
159
- if ( dataSet . axisDependency === AxisDependency . RIGHT ) {
160
- if ( dataSet . yMin < this . mRightAxisMin ) this . mRightAxisMin = dataSet . yMin ;
161
-
162
- if ( dataSet . yMax > this . mRightAxisMax ) this . mRightAxisMax = dataSet . yMax ;
163
- }
164
- }
165
- }
132
+ // this.mLeftAxisMax = -Infinity;
133
+ // this.mLeftAxisMin = Infinity;
134
+ // this.mRightAxisMax = -Infinity;
135
+ // this.mRightAxisMin = Infinity;
136
+ // for (let i = 0; i < visibleDatasets.length; i++) {
137
+ // const set = visibleDatasets[i];
138
+ // if (set.axisDependency === AxisDependency.RIGHT) {
139
+ // this.mRightAxisMin = Math.min(this.mRightAxisMin, set.yMin);
140
+ // this.mRightAxisMax = Math.min(this.mRightAxisMax, set.yMax);
141
+ // } else {
142
+ // this.mLeftAxisMin = Math.min(this.mLeftAxisMin, set.yMin);
143
+ // this.mLeftAxisMax = Math.min(this.mLeftAxisMax, set.yMax);
144
+ // }
145
+ // }
166
146
}
167
147
168
148
/** ONLY GETTERS AND SETTERS BELOW THIS */
@@ -426,22 +406,19 @@ export abstract class ChartData<U extends Entry, T extends IDataSet<U>> {
426
406
* @param axis
427
407
*/
428
408
protected calcMinMaxForEntry ( set : IDataSet < Entry > , e : Entry , entryIndex : number , axis : AxisDependency ) {
429
- const xKey = set . xProperty ;
430
- const yKey = set . yProperty ;
431
409
const xValue = set . getEntryXValue ( e , entryIndex ) ;
432
- const yValue = e [ yKey ] ;
433
- if ( this . mYMax < yValue ) this . mYMax = yValue ;
434
- if ( this . mYMin > yValue ) this . mYMin = yValue ;
435
-
436
- if ( this . mXMax < xValue ) this . mXMax = xValue ;
437
- if ( this . mXMin > xValue ) this . mXMin = xValue ;
410
+ const yValue = e [ set . yProperty ] ;
411
+ this . mYMin = Math . min ( this . mYMin , yValue ) ;
412
+ this . mYMax = Math . max ( this . mYMax , yValue ) ;
413
+ this . mXMin = Math . min ( this . mXMin , xValue ) ;
414
+ this . mXMax = Math . max ( this . mXMax , xValue ) ;
438
415
439
416
if ( axis === AxisDependency . LEFT ) {
440
- if ( this . mLeftAxisMax < yValue ) this . mLeftAxisMax = yValue ;
441
- if ( this . mLeftAxisMin > yValue ) this . mLeftAxisMin = yValue ;
417
+ this . mLeftAxisMin = Math . min ( this . mLeftAxisMin , yValue ) ;
418
+ this . mLeftAxisMax = Math . max ( this . mLeftAxisMax , yValue ) ;
442
419
} else {
443
- if ( this . mRightAxisMax < yValue ) this . mRightAxisMax = yValue ;
444
- if ( this . mRightAxisMin > yValue ) this . mRightAxisMin = yValue ;
420
+ this . mRightAxisMin = Math . min ( this . mRightAxisMin , yValue ) ;
421
+ this . mRightAxisMax = Math . max ( this . mRightAxisMax , yValue ) ;
445
422
}
446
423
}
447
424
@@ -451,18 +428,17 @@ export abstract class ChartData<U extends Entry, T extends IDataSet<U>> {
451
428
* @param d
452
429
*/
453
430
protected calcMinMaxForDataSet ( d : T ) {
454
- if ( this . mYMax < d . yMax ) this . mYMax = d . yMax ;
455
- if ( this . mYMin > d . yMin ) this . mYMin = d . yMin ;
456
-
457
- if ( this . mXMax < d . xMax ) this . mXMax = d . xMax ;
458
- if ( this . mXMin > d . xMin ) this . mXMin = d . xMin ;
431
+ this . mXMin = Math . min ( this . mXMin , d . xMin ) ;
432
+ this . mXMax = Math . max ( this . mXMax , d . xMax ) ;
433
+ this . mYMin = Math . min ( this . mYMin , d . yMin ) ;
434
+ this . mYMax = Math . max ( this . mYMax , d . yMax ) ;
459
435
460
436
if ( d . axisDependency === AxisDependency . LEFT ) {
461
- if ( this . mLeftAxisMax < d . yMax ) this . mLeftAxisMax = d . yMax ;
462
- if ( this . mLeftAxisMin > d . yMin ) this . mLeftAxisMin = d . yMin ;
437
+ this . mLeftAxisMin = Math . min ( this . mLeftAxisMin , d . yMin ) ;
438
+ this . mLeftAxisMax = Math . max ( this . mLeftAxisMax , d . yMax ) ;
463
439
} else {
464
- if ( this . mRightAxisMax < d . yMax ) this . mRightAxisMax = d . yMax ;
465
- if ( this . mRightAxisMin > d . yMin ) this . mRightAxisMin = d . yMin ;
440
+ this . mRightAxisMin = Math . min ( this . mRightAxisMin , d . yMin ) ;
441
+ this . mRightAxisMax = Math . max ( this . mRightAxisMax , d . yMax ) ;
466
442
}
467
443
}
468
444
0 commit comments