Skip to content

Commit

Permalink
refactor(xy): cleaup loops (#2538)
Browse files Browse the repository at this point in the history
  • Loading branch information
markov00 authored Oct 16, 2024
1 parent 76fd0bb commit 1b39f63
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ export function fillSeries(

const noFillRequired = isXFillNotRequired(spec, groupScaleType, isStacked);
if (data.length === xValues.size || noFillRequired) {
return {
...series,
data,
};
return series;
}
const filledData: typeof data = [];
const missingValues = new Set(xValues);
Expand Down
18 changes: 6 additions & 12 deletions packages/charts/src/chart_types/xy_chart/utils/series.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export function splitSeriesDataByAccessors(
isBanded = false,
stackMode?: StackMode,
groupBySpec?: SmallMultiplesGroupBy,
deselectedDataSeries: SeriesIdentifier[] = [],
): {
dataSeries: Map<SeriesKey, DataSeries>;
xValues: Array<string | number>;
Expand Down Expand Up @@ -210,7 +211,7 @@ export function splitSeriesDataByAccessors(
spec,
insertOrder: insertOrder + dataSeries.size,
sortOrder: 0,
isFiltered: false,
isFiltered: deselectedDataSeries.some(({ key: deselectedKey }) => seriesKey === deselectedKey),
});
}

Expand Down Expand Up @@ -368,7 +369,7 @@ export function getDataSeriesFromSpecs(
smHValues: Set<string | number>;
fallbackScale?: XScaleType;
} {
let globalDataSeries: DataSeries[] = [];
const globalDataSeries: DataSeries[] = [];
const mutatedXValueSums = new Map<string | number, number>();

// the unique set of values along the x axis
Expand Down Expand Up @@ -399,25 +400,18 @@ export function getDataSeriesFromSpecs(
isBanded,
specGroup?.stackMode,
groupBySpec,
deselectedDataSeries,
);

insertOrder += dataSeries.size;

// filter deselected DataSeries
let filteredDataSeries: DataSeries[] = [...dataSeries.values()];
if (deselectedDataSeries.length > 0) {
filteredDataSeries = filteredDataSeries.map((series) => ({
...series,
isFiltered: deselectedDataSeries.some(({ key: deselectedKey }) => series.key === deselectedKey),
}));
for (const [, ds] of dataSeries) {
globalDataSeries.push(ds);
}

globalDataSeries = [...globalDataSeries, ...filteredDataSeries];

// check the nature of the x values. If all of them are numbers
// we can use a continuous scale, if not we should use an ordinal scale.
// The xValue is already casted to be a valid number or a string
// eslint-disable-next-line no-restricted-syntax
for (const xValue of xValues) {
if (isNumberArray && typeof xValue !== 'number') {
isNumberArray = false;
Expand Down

0 comments on commit 1b39f63

Please sign in to comment.