diff --git a/src/plugins/vis_types/xy/public/utils/accessors.test.ts b/src/plugins/vis_types/xy/public/utils/accessors.test.ts index 06920ceebe980..ebb389054af7e 100644 --- a/src/plugins/vis_types/xy/public/utils/accessors.test.ts +++ b/src/plugins/vis_types/xy/public/utils/accessors.test.ts @@ -129,6 +129,22 @@ describe('isPercentileIdEqualToSeriesId', () => { expect(isEqual).toBeFalsy(); }); + it('should be equal for column with percentile with decimal points', () => { + const seriesColumnId = '1'; + const columnId = `${seriesColumnId}['95.5']`; + + const isEqual = isPercentileIdEqualToSeriesId(columnId, seriesColumnId); + expect(isEqual).toBeTruthy(); + }); + + it('should not be equal for column with percentile with decimal points equal to seriesColumnId', () => { + const seriesColumnId = '1'; + const columnId = `2['1.3']`; + + const isEqual = isPercentileIdEqualToSeriesId(columnId, seriesColumnId); + expect(isEqual).toBeFalsy(); + }); + it('should not be equal for column with percentile, where columnId contains seriesColumnId', () => { const seriesColumnId = '1'; const columnId = `${seriesColumnId}2.1`; diff --git a/src/plugins/vis_types/xy/public/utils/accessors.tsx b/src/plugins/vis_types/xy/public/utils/accessors.tsx index 6eccb36d6fa73..0acde395bbdb7 100644 --- a/src/plugins/vis_types/xy/public/utils/accessors.tsx +++ b/src/plugins/vis_types/xy/public/utils/accessors.tsx @@ -79,8 +79,16 @@ export const getSplitSeriesAccessorFnMap = ( }; // For percentile, the aggregation id is coming in the form %s.%d, where %s is agg_id and %d - percents -export const getSafeId = (columnId?: number | string | null) => - (columnId || '').toString().split('.')[0]; +export const getSafeId = (columnId?: number | string | null) => { + const id = String(columnId); + // only multi-value aggs like percentiles are allowed to contain dots and [ + const isMultiValueId = id.includes('[') || id.includes('.'); + if (!isMultiValueId) { + return id; + } + const baseId = id.substring(0, id.indexOf('[') !== -1 ? id.indexOf('[') : id.indexOf('.')); + return baseId; +}; export const isPercentileIdEqualToSeriesId = ( columnId: number | string | null | undefined,