Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visualize: Bad request when working with histogram aggregation #77684

Merged
merged 4 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,19 @@ describe('calculateHistogramInterval', () => {
})
).toEqual(0.02);
});

test('should correctly fallback to the default value for empty string', () => {
expect(
calculateHistogramInterval({
...params,
maxBucketsUserInput: '',
values: {
min: 0.1,
max: 0.9,
},
})
).toBe(0.01);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface IntervalValuesRange {
export interface CalculateHistogramIntervalParams {
interval: string;
maxBucketsUiSettings: number;
maxBucketsUserInput?: number;
maxBucketsUserInput?: number | '';
intervalBase?: number;
values?: IntervalValuesRange;
}
Expand Down 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,11 @@ export const calculateHistogramInterval = ({

if (diff) {
calculatedInterval = isAuto
? calculateAutoInterval(diff, maxBucketsUiSettings, maxBucketsUserInput)
? calculateAutoInterval(
diff,
// Mind maxBucketsUserInput can be an empty string, hence we need to ensure it here
Math.min(maxBucketsUiSettings, maxBucketsUserInput || maxBucketsUiSettings)
)
: calculateForGivenInterval(diff, calculatedInterval, maxBucketsUiSettings);
}
}
Expand Down