Skip to content

Commit

Permalink
XY Fix percentile with decimals (#123709) (#123807)
Browse files Browse the repository at this point in the history
(cherry picked from commit 03c8d08)

Co-authored-by: Joe Reuter <johannes.reuter@elastic.co>
  • Loading branch information
kibanamachine and flash1293 authored Jan 26, 2022
1 parent 2a14252 commit 919c0d0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/plugins/vis_types/xy/public/utils/accessors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down
12 changes: 10 additions & 2 deletions src/plugins/vis_types/xy/public/utils/accessors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 919c0d0

Please sign in to comment.