Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.17] XY Fix percentile with decimals (#123709) #123808

Merged
merged 1 commit into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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