Skip to content

Commit

Permalink
fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
vedantprajapati committed Dec 17, 2024
1 parent 38401c8 commit 1f0f5b2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ export default function transformProps(
.map(entry => entry.name || '')
.concat(extractAnnotationLabels(annotationLayers, annotationData)),
},
series: dedupSeries(reorderForecastSeries(series)),
series: dedupSeries(reorderForecastSeries(series) as SeriesOption[]),
toolbox: {
show: zoomable,
top: TIMESERIES_CONSTANTS.toolboxTop,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ export default function transformProps(
),
data: legendData as string[],
},
series: dedupSeries(reorderForecastSeries(series)),
series: dedupSeries(reorderForecastSeries(series) as SeriesOption[]),
toolbox: {
show: zoomable,
top: TIMESERIES_CONSTANTS.toolboxTop,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import { isNumber } from 'lodash';
import { DataRecord, DTTM_ALIAS, ValueFormatter } from '@superset-ui/core';
import type { OptionName } from 'echarts/types/src/util/types';
import type { OptionName, SeriesOption } from 'echarts/types/src/util/types';
import type { TooltipMarker } from 'echarts/types/src/util/format';
import {
ForecastSeriesContext,
Expand Down Expand Up @@ -152,33 +152,32 @@ export function rebaseForecastDatum(
}

// For Confidence Bands, forecast series on mixed charts require the series sent in the following sortOrder:
export function reorderForecastSeries(row: { id: string }[]): { id: string }[] {
// Define the order for sorting using ForecastSeriesEnum
export function reorderForecastSeries(row: SeriesOption[]): SeriesOption[] {
const sortOrder = {
[ForecastSeriesEnum.ForecastLower]: 1,
[ForecastSeriesEnum.ForecastUpper]: 2,
[ForecastSeriesEnum.ForecastTrend]: 3,
[ForecastSeriesEnum.Observation]: 4,
};

// Check if any item needs reordering
if (
!row.some(item => {
const context = extractForecastSeriesContext(item.id);
return context && sortOrder.hasOwnProperty(context.type);
})
!row.some(
item =>
item.id &&
sortOrder.hasOwnProperty(extractForecastSeriesContext(item.id).type),
)
) {
return row;
}

return row.sort((a, b) => {
// Extract the forecast series context from the id to determine the order
const aContext = extractForecastSeriesContext(a.id);
const bContext = extractForecastSeriesContext(b.id);

// Use optional chaining and the nullish coalescing operator for safer access
const aOrder = (aContext?.type && sortOrder[aContext.type]) ?? Number.MAX_SAFE_INTEGER;
const bOrder = (bContext?.type && sortOrder[bContext.type]) ?? Number.MAX_SAFE_INTEGER;

const aOrder =
sortOrder[extractForecastSeriesContext(a.id ?? '').type] ??
Number.MAX_SAFE_INTEGER;
const bOrder =
sortOrder[extractForecastSeriesContext(b.id ?? '').type] ??
Number.MAX_SAFE_INTEGER;
return aOrder - bOrder;
});
}
}

0 comments on commit 1f0f5b2

Please sign in to comment.