mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[XY] Fixes the scale type on a terms aggregation on a number field (#115729)
This commit is contained in:
parent
5499bd168d
commit
1eb0f4aecd
2 changed files with 83 additions and 2 deletions
78
src/plugins/vis_types/xy/public/config/get_axis.test.ts
Normal file
78
src/plugins/vis_types/xy/public/config/get_axis.test.ts
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { getScale } from './get_axis';
|
||||
import type { Scale } from '../types';
|
||||
|
||||
describe('getScale', () => {
|
||||
const axisScale = {
|
||||
type: 'linear',
|
||||
mode: 'normal',
|
||||
scaleType: 'linear',
|
||||
} as Scale;
|
||||
|
||||
it('returns linear type for a number', () => {
|
||||
const format = { id: 'number' };
|
||||
const scale = getScale(axisScale, {}, format, true);
|
||||
expect(scale.type).toBe('linear');
|
||||
});
|
||||
|
||||
it('returns ordinal type for a terms aggregation on a number field', () => {
|
||||
const format = {
|
||||
id: 'terms',
|
||||
params: {
|
||||
id: 'number',
|
||||
otherBucketLabel: 'Other',
|
||||
missingBucketLabel: 'Missing',
|
||||
},
|
||||
};
|
||||
const scale = getScale(axisScale, {}, format, true);
|
||||
expect(scale.type).toBe('ordinal');
|
||||
});
|
||||
|
||||
it('returns ordinal type for a terms aggregation on a string field', () => {
|
||||
const format = {
|
||||
id: 'terms',
|
||||
params: {
|
||||
id: 'string',
|
||||
otherBucketLabel: 'Other',
|
||||
missingBucketLabel: 'Missing',
|
||||
},
|
||||
};
|
||||
const scale = getScale(axisScale, {}, format, true);
|
||||
expect(scale.type).toBe('ordinal');
|
||||
});
|
||||
|
||||
it('returns ordinal type for a range aggregation on a number field', () => {
|
||||
const format = {
|
||||
id: 'range',
|
||||
params: {
|
||||
id: 'number',
|
||||
},
|
||||
};
|
||||
const scale = getScale(axisScale, {}, format, true);
|
||||
expect(scale.type).toBe('ordinal');
|
||||
});
|
||||
|
||||
it('returns time type for a date histogram aggregation', () => {
|
||||
const format = {
|
||||
id: 'date',
|
||||
params: {
|
||||
pattern: 'HH:mm',
|
||||
},
|
||||
};
|
||||
const scale = getScale(axisScale, { date: true }, format, true);
|
||||
expect(scale.type).toBe('time');
|
||||
});
|
||||
|
||||
it('returns linear type for an histogram aggregation', () => {
|
||||
const format = { id: 'number' };
|
||||
const scale = getScale(axisScale, { interval: 1 }, format, true);
|
||||
expect(scale.type).toBe('linear');
|
||||
});
|
||||
});
|
|
@ -120,7 +120,7 @@ function getScaleType(
|
|||
return type;
|
||||
}
|
||||
|
||||
function getScale<S extends XScaleType | YScaleType>(
|
||||
export function getScale<S extends XScaleType | YScaleType>(
|
||||
scale: Scale,
|
||||
params: Aspect['params'],
|
||||
format: Aspect['format'],
|
||||
|
@ -130,7 +130,10 @@ function getScale<S extends XScaleType | YScaleType>(
|
|||
isCategoryAxis
|
||||
? getScaleType(
|
||||
scale,
|
||||
format?.id === 'number' || (format?.params?.id === 'number' && format?.id !== 'range'),
|
||||
format?.id === 'number' ||
|
||||
(format?.params?.id === 'number' &&
|
||||
format?.id !== BUCKET_TYPES.RANGE &&
|
||||
format?.id !== BUCKET_TYPES.TERMS),
|
||||
'date' in params,
|
||||
'interval' in params
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue