File tree 3 files changed +15
-2
lines changed
3 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,10 @@ export abstract class AxisBase extends ComponentBase {
90
90
91
91
protected mCenterAxisLabels = false ;
92
92
93
+ public ensureLastLabel = false ;
94
+
95
+ public allowLastLabelAboveMax = false ;
96
+
93
97
/**
94
98
* the path effect of the axis line that makes dashed lines possible
95
99
*/
Original file line number Diff line number Diff line change @@ -109,6 +109,7 @@ export class YAxis extends AxisBase {
109
109
super ( ) ;
110
110
this . mAxisDependency = position ;
111
111
this . mYOffset = 0 ;
112
+ this . allowLastLabelAboveMax = true ;
112
113
}
113
114
114
115
public getAxisDependency ( ) {
Original file line number Diff line number Diff line change @@ -204,7 +204,10 @@ export abstract class AxisRenderer extends Renderer {
204
204
}
205
205
// use Math.floor(yMax / interval) + 1 instead of
206
206
// Math.floor(yMax / interval) to make sure the axis is showed "above" the higghest value
207
- const last = interval === 0 ? 0 : Utils . nextUp ( Math . floor ( yMax / interval ) * interval ) ;
207
+ let last = interval === 0 ? 0 : Utils . nextUp ( Math . floor ( yMax / interval ) * interval ) ;
208
+ if ( axis . ensureLastLabel && last < max ) {
209
+ last = Math . min ( max , last + interval ) ;
210
+ }
208
211
let f ;
209
212
let i ;
210
213
@@ -213,6 +216,9 @@ export abstract class AxisRenderer extends Renderer {
213
216
++ n ;
214
217
}
215
218
}
219
+ if ( axis . ensureLastLabel && ( n - 1 ) * interval < last ) {
220
+ n ++ ;
221
+ }
216
222
217
223
axis . mEntryCount = n ;
218
224
@@ -222,10 +228,12 @@ export abstract class AxisRenderer extends Renderer {
222
228
axis . mLabels = [ ] ;
223
229
}
224
230
225
- for ( f = first , i = 0 ; i < n ; f += interval , ++ i ) {
231
+ for ( f = first , i = 0 ; i <= n ; f += interval , ++ i ) {
226
232
if ( f === 0.0 ) {
227
233
// Fix for negative zero case (Where value == -0.0, and 0.0 == -0.0)
228
234
f = 0.0 ;
235
+ } else if ( ! axis . allowLastLabelAboveMax && f > max ) {
236
+ f = max ;
229
237
}
230
238
231
239
axis . mEntries [ i ] = f ;
You can’t perform that action at this time.
0 commit comments