Skip to content

Commit

Permalink
chore: removed the former vestigial void 0 arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
monfera committed Oct 5, 2021
1 parent 9a96a00 commit f2f27e9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/charts/src/chart_types/xy_chart/legend/legend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
38 changes: 4 additions & 34 deletions packages/charts/src/utils/series_sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

0 comments on commit f2f27e9

Please sign in to comment.