mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[Custom threshold] Fix not showing threshold line in lens preview (#171970)
Closes #171843
## Summary
This PR fixes not showing the threshold line in the following case:
<img
src="fa0af167
-b7f1-499a-a703-b336d4f2414c"
width=500 />
This commit is contained in:
parent
619b8b2f1e
commit
0942bcea04
2 changed files with 20 additions and 2 deletions
|
@ -13,7 +13,7 @@ import { Comparator, Aggregators } from '../../../../../common/custom_threshold_
|
|||
import { useKibana } from '../../../../utils/kibana_react';
|
||||
import { kibanaStartMock } from '../../../../utils/kibana_react.mock';
|
||||
import { MetricExpression } from '../../types';
|
||||
import { PreviewChart } from './preview_chart';
|
||||
import { getBufferThreshold, PreviewChart } from './preview_chart';
|
||||
|
||||
jest.mock('../../../../utils/kibana_react');
|
||||
|
||||
|
@ -70,3 +70,18 @@ describe('Preview chart', () => {
|
|||
expect(wrapper.find('[data-test-subj="thresholdRuleNoChartData"]').exists()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getBufferThreshold', () => {
|
||||
const testData = [
|
||||
{ threshold: undefined, buffer: '0.00' },
|
||||
{ threshold: 0.1, buffer: '0.12' },
|
||||
{ threshold: 0.01, buffer: '0.02' },
|
||||
{ threshold: 0.001, buffer: '0.01' },
|
||||
{ threshold: 0.00098, buffer: '0.01' },
|
||||
{ threshold: 130, buffer: '143.00' },
|
||||
];
|
||||
|
||||
it.each(testData)('getBufferThreshold($threshold) = $buffer', ({ threshold, buffer }) => {
|
||||
expect(getBufferThreshold(threshold)).toBe(buffer);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -44,6 +44,9 @@ const getOperationTypeFromRuleAggType = (aggType: AggType): OperationType => {
|
|||
return aggType;
|
||||
};
|
||||
|
||||
export const getBufferThreshold = (threshold?: number): string =>
|
||||
(Math.ceil((threshold || 0) * 1.1 * 100) / 100).toFixed(2).toString();
|
||||
|
||||
export function PreviewChart({
|
||||
metricExpression,
|
||||
dataView,
|
||||
|
@ -147,7 +150,7 @@ export function PreviewChart({
|
|||
const bufferRefLine = new XYReferenceLinesLayer({
|
||||
data: [
|
||||
{
|
||||
value: Math.round((threshold[0] || 0) * 1.1).toString(),
|
||||
value: getBufferThreshold(threshold[0]),
|
||||
color: 'transparent',
|
||||
fill,
|
||||
format,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue