@@ -27,7 +27,7 @@ interface IntervalValuesRange {
2727export interface CalculateHistogramIntervalParams {
2828 interval : string ;
2929 maxBucketsUiSettings : number ;
30- maxBucketsUserInput ?: number ;
30+ maxBucketsUserInput ?: number | '' ;
3131 intervalBase ?: number ;
3232 values ?: IntervalValuesRange ;
3333}
@@ -77,12 +77,7 @@ const calculateForGivenInterval = (
7777 - The lower power of 10, times 2
7878 - The lower power of 10, times 5
7979 **/
80- const calculateAutoInterval = (
81- diff : number ,
82- maxBucketsUiSettings : CalculateHistogramIntervalParams [ 'maxBucketsUiSettings' ] ,
83- maxBucketsUserInput : CalculateHistogramIntervalParams [ 'maxBucketsUserInput' ]
84- ) => {
85- const maxBars = Math . min ( maxBucketsUiSettings , maxBucketsUserInput ?? maxBucketsUiSettings ) ;
80+ const calculateAutoInterval = ( diff : number , maxBars : number ) => {
8681 const exactInterval = diff / maxBars ;
8782
8883 const lowerPower = Math . pow ( 10 , Math . floor ( Math . log10 ( exactInterval ) ) ) ;
@@ -122,7 +117,11 @@ export const calculateHistogramInterval = ({
122117
123118 if ( diff ) {
124119 calculatedInterval = isAuto
125- ? calculateAutoInterval ( diff , maxBucketsUiSettings , maxBucketsUserInput )
120+ ? calculateAutoInterval (
121+ diff ,
122+ // Mind maxBucketsUserInput can be an empty string, hence we need to ensure it here
123+ Math . min ( maxBucketsUiSettings , maxBucketsUserInput || maxBucketsUiSettings )
124+ )
126125 : calculateForGivenInterval ( diff , calculatedInterval , maxBucketsUiSettings ) ;
127126 }
128127 }
0 commit comments