From a6a0ee4aa2663e893f2d02aa8dc8f2f3636cffff Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Tue, 25 Jan 2022 13:06:21 +0100 Subject: [PATCH 1/3] fix percentile lookup --- .../vis_types/xy/public/utils/accessors.test.ts | 16 ++++++++++++++++ .../vis_types/xy/public/utils/accessors.tsx | 12 ++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) 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, From ed5fb83f42ec5c021666fb721b7c3df00ebc5fd0 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Wed, 26 Jan 2022 09:35:05 +0100 Subject: [PATCH 2/3] Update src/plugins/vis_types/xy/public/utils/accessors.tsx Co-authored-by: Marco Liberati --- src/plugins/vis_types/xy/public/utils/accessors.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/vis_types/xy/public/utils/accessors.tsx b/src/plugins/vis_types/xy/public/utils/accessors.tsx index 0acde395bbdb7..bb15f2ab0f2f3 100644 --- a/src/plugins/vis_types/xy/public/utils/accessors.tsx +++ b/src/plugins/vis_types/xy/public/utils/accessors.tsx @@ -86,7 +86,7 @@ export const getSafeId = (columnId?: number | string | null) => { if (!isMultiValueId) { return id; } - const baseId = id.substring(0, id.indexOf('[') !== -1 ? id.indexOf('[') : id.indexOf('.')); + const baseId = id.substring(0, Math.max(id.indexOf('['), id.indexOf('.'))); return baseId; }; From 7ea99d740b678e287cf503e7d17f04201e71ff3f Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Wed, 26 Jan 2022 10:36:11 +0100 Subject: [PATCH 3/3] fix base id check --- src/plugins/vis_types/xy/public/utils/accessors.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/vis_types/xy/public/utils/accessors.tsx b/src/plugins/vis_types/xy/public/utils/accessors.tsx index bb15f2ab0f2f3..0acde395bbdb7 100644 --- a/src/plugins/vis_types/xy/public/utils/accessors.tsx +++ b/src/plugins/vis_types/xy/public/utils/accessors.tsx @@ -86,7 +86,7 @@ export const getSafeId = (columnId?: number | string | null) => { if (!isMultiValueId) { return id; } - const baseId = id.substring(0, Math.max(id.indexOf('['), id.indexOf('.'))); + const baseId = id.substring(0, id.indexOf('[') !== -1 ? id.indexOf('[') : id.indexOf('.')); return baseId; };