Skip to content

Commit

Permalink
Visualize: Bad request when working with histogram aggregation
Browse files Browse the repository at this point in the history
Closes: #77023
  • Loading branch information
alexwizp committed Sep 16, 2020
1 parent b3aabe9 commit 0fae836
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,7 @@ const calculateForGivenInterval = (
- The lower power of 10, times 2
- The lower power of 10, times 5
**/
const calculateAutoInterval = (
diff: number,
maxBucketsUiSettings: CalculateHistogramIntervalParams['maxBucketsUiSettings'],
maxBucketsUserInput: CalculateHistogramIntervalParams['maxBucketsUserInput']
) => {
const maxBars = Math.min(maxBucketsUiSettings, maxBucketsUserInput ?? maxBucketsUiSettings);
const calculateAutoInterval = (diff: number, maxBars: number) => {
const exactInterval = diff / maxBars;

const lowerPower = Math.pow(10, Math.floor(Math.log10(exactInterval)));
Expand Down Expand Up @@ -122,7 +117,10 @@ export const calculateHistogramInterval = ({

if (diff) {
calculatedInterval = isAuto
? calculateAutoInterval(diff, maxBucketsUiSettings, maxBucketsUserInput)
? calculateAutoInterval(
diff,
Math.min(maxBucketsUiSettings, maxBucketsUserInput || maxBucketsUiSettings)
)
: calculateForGivenInterval(diff, calculatedInterval, maxBucketsUiSettings);
}
}
Expand Down

0 comments on commit 0fae836

Please sign in to comment.