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

[Viz] legend duplicates percentile options when chart has both left & right Y axes #113073

Merged
merged 5 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
40 changes: 39 additions & 1 deletion src/plugins/vis_types/xy/public/utils/accessors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
* Side Public License, v 1.
*/

import { COMPLEX_SPLIT_ACCESSOR, getComplexAccessor } from './accessors';
import {
COMPLEX_SPLIT_ACCESSOR,
getComplexAccessor,
isPercentileIdEqualToSeriesId,
} from './accessors';
import { BUCKET_TYPES } from '../../../../data/common';
import { AccessorFn, Datum } from '@elastic/charts';

Expand Down Expand Up @@ -99,3 +103,37 @@ describe('XY chart datum accessors', () => {
expect(accessor).toBeUndefined();
});
});

describe('isPercentileIdEqualToSeriesId', () => {
it('should be equal for plain column ids', () => {
const seriesColumnId = 'col-0-1';
const columnId = `${seriesColumnId}`;

const isEqual = isPercentileIdEqualToSeriesId(columnId, seriesColumnId);
expect(isEqual).toBeTruthy();
});

it('should be equal for column with percentile', () => {
const seriesColumnId = '1';
const columnId = `${seriesColumnId}.95`;

const isEqual = isPercentileIdEqualToSeriesId(columnId, seriesColumnId);
expect(isEqual).toBeTruthy();
});

it('should not be equal for column with percentile equal to seriesColumnId', () => {
const seriesColumnId = '1';
const columnId = `2.1`;

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`;

const isEqual = isPercentileIdEqualToSeriesId(columnId, seriesColumnId);
expect(isEqual).toBeFalsy();
});
});
13 changes: 12 additions & 1 deletion src/plugins/vis_types/xy/public/utils/accessors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { AccessorFn, Accessor } from '@elastic/charts';
import { BUCKET_TYPES } from '../../../../data/public';
import { FakeParams } from '../../../../visualizations/public';
import { Aspect } from '../types';
import type { Aspect } from '../types';

export const COMPLEX_X_ACCESSOR = '__customXAccessor__';
export const COMPLEX_SPLIT_ACCESSOR = '__complexSplitAccessor__';
Expand Down Expand Up @@ -77,3 +77,14 @@ export const getSplitSeriesAccessorFnMap = (

return m;
};

// For percentile, the aggregation id is coming in the form %s.%d, where %s is agg_id and %d - percents
export const isPercentileIdEqualToSeriesId = (columnId: number | string, seriesColumnId: string) =>
columnId.toString().split('.')[0] === seriesColumnId;

export const isValidSeriesForDimension = (
seriesColumnId: string,
{ aggId, accessor }: Partial<Aspect>
) =>
(aggId === seriesColumnId || isPercentileIdEqualToSeriesId(aggId ?? '', seriesColumnId)) &&
accessor !== null;
16 changes: 4 additions & 12 deletions src/plugins/vis_types/xy/public/utils/render_all_series.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import {
} from '@elastic/charts';

import { DatatableRow } from '../../../../expressions/public';
import { METRIC_TYPES } from '../../../../data/public';

import { ChartType } from '../../common';
import { SeriesParam, VisConfig } from '../types';
import { isValidSeriesForDimension } from './accessors';

/**
* Matches vislib curve to elastic charts
Expand Down Expand Up @@ -82,17 +82,9 @@ export const renderAllSeries = (
interpolate,
type,
}) => {
const yAspects = aspects.y.filter(({ aggId, aggType, accessor }) => {
if (
aggType === METRIC_TYPES.PERCENTILES ||
aggType === METRIC_TYPES.PERCENTILE_RANKS ||
aggType === METRIC_TYPES.STD_DEV
) {
return aggId?.includes(paramId) && accessor !== null;
} else {
return aggId === paramId && accessor !== null;
}
});
const yAspects = aspects.y.filter(({ aggId, accessor }) =>
isValidSeriesForDimension(paramId, { aggId, accessor })
);
if (!show || !yAspects.length) {
return null;
}
Expand Down