diff --git a/packages/charts/src/chart_types/xy_chart/legend/legend.ts b/packages/charts/src/chart_types/xy_chart/legend/legend.ts index 4d62c5c36f..37488cd56e 100644 --- a/packages/charts/src/chart_types/xy_chart/legend/legend.ts +++ b/packages/charts/src/chart_types/xy_chart/legend/legend.ts @@ -173,7 +173,7 @@ export function computeLegend( } }); - const legendSortFn = getLegendCompareFn(void 0, (a, b) => { + const legendSortFn = getLegendCompareFn((a, b) => { const aDs = serialIdentifierDataSeriesMap[a.key]; const bDs = serialIdentifierDataSeriesMap[b.key]; return defaultXYLegendSeriesSort(aDs, bDs); diff --git a/packages/charts/src/chart_types/xy_chart/state/selectors/get_tooltip_values_highlighted_geoms.ts b/packages/charts/src/chart_types/xy_chart/state/selectors/get_tooltip_values_highlighted_geoms.ts index 185ec48e4c..2ee15ed055 100644 --- a/packages/charts/src/chart_types/xy_chart/state/selectors/get_tooltip_values_highlighted_geoms.ts +++ b/packages/charts/src/chart_types/xy_chart/state/selectors/get_tooltip_values_highlighted_geoms.ts @@ -191,7 +191,7 @@ function getTooltipAndHighlightFromValue( header = null; } - const tooltipSortFn = getTooltipCompareFn(void 0, (a, b) => { + const tooltipSortFn = getTooltipCompareFn((a, b) => { const aDs = serialIdentifierDataSeriesMap[a.key]; const bDs = serialIdentifierDataSeriesMap[b.key]; return defaultXYLegendSeriesSort(aDs, bDs); diff --git a/packages/charts/src/chart_types/xy_chart/state/utils/utils.ts b/packages/charts/src/chart_types/xy_chart/state/utils/utils.ts index 2dc0bd8c4e..1d4fe160c3 100644 --- a/packages/charts/src/chart_types/xy_chart/state/utils/utils.ts +++ b/packages/charts/src/chart_types/xy_chart/state/utils/utils.ts @@ -126,7 +126,7 @@ export function computeSeriesDomains( // fill series with missing x values const filledDataSeries = fillSeries(dataSeries, xValues, xDomain.type); - const seriesSortFn = getRenderingCompareFn(void 0, (a: SeriesIdentifier, b: SeriesIdentifier) => { + const seriesSortFn = getRenderingCompareFn((a: SeriesIdentifier, b: SeriesIdentifier) => { return defaultXYSeriesSort(a as DataSeries, b as DataSeries); }); diff --git a/packages/charts/src/utils/series_sort.ts b/packages/charts/src/utils/series_sort.ts index 5db19874af..f6c44378ab 100644 --- a/packages/charts/src/utils/series_sort.ts +++ b/packages/charts/src/utils/series_sort.ts @@ -7,7 +7,6 @@ */ import { SeriesIdentifier } from '../common/series_id'; -import { SortSeriesByConfig } from '../specs/settings'; /** * A compare function used to determine the order of the elements. It is expected to return @@ -17,42 +16,13 @@ import { SortSeriesByConfig } from '../specs/settings'; */ export type SeriesCompareFn = (siA: SeriesIdentifier, siB: SeriesIdentifier) => number; -/** @internal */ -export const DEFAULT_SORTING_FN = () => { - return 0; -}; +const DEFAULT_SORTING_FN = () => 0; // this should cause no reorder, as [].sort is now a stable sort in browsers /** @internal */ -export function getRenderingCompareFn( - sortSeriesBy?: SeriesCompareFn | SortSeriesByConfig, - defaultSortFn?: SeriesCompareFn, -): SeriesCompareFn { - return getCompareFn('rendering', sortSeriesBy, defaultSortFn); -} +export const getRenderingCompareFn = (defaultSortFn: SeriesCompareFn = DEFAULT_SORTING_FN) => defaultSortFn; /** @internal */ -export function getLegendCompareFn( - sortSeriesBy?: SeriesCompareFn | SortSeriesByConfig, - defaultSortFn?: SeriesCompareFn, -): SeriesCompareFn { - return getCompareFn('legend', sortSeriesBy, defaultSortFn); -} +export const getLegendCompareFn = (defaultSortFn: SeriesCompareFn = DEFAULT_SORTING_FN) => defaultSortFn; /** @internal */ -export function getTooltipCompareFn( - sortSeriesBy?: SeriesCompareFn | SortSeriesByConfig, - defaultSortFn?: SeriesCompareFn, -): SeriesCompareFn { - return getCompareFn('tooltip', sortSeriesBy, defaultSortFn); -} - -function getCompareFn( - aspect: keyof SortSeriesByConfig, - sortSeriesBy?: SeriesCompareFn | SortSeriesByConfig, - defaultSortFn: SeriesCompareFn = DEFAULT_SORTING_FN, -): SeriesCompareFn { - if (typeof sortSeriesBy === 'object') { - return sortSeriesBy[aspect] ?? sortSeriesBy.default ?? defaultSortFn; - } - return sortSeriesBy ?? defaultSortFn; -} +export const getTooltipCompareFn = (defaultSortFn: SeriesCompareFn = DEFAULT_SORTING_FN) => defaultSortFn;