Skip to content

Commit

Permalink
Reordered echart props so confidence interval works
Browse files Browse the repository at this point in the history
  • Loading branch information
geotab-data-platform committed Oct 25, 2024
1 parent 1c56857 commit 871e9fa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import {
extractForecastValuesFromTooltipParams,
formatForecastTooltipSeries,
rebaseForecastDatum,
reorderForecastSeries,
} from '../utils/forecast';
import { convertInteger } from '../utils/convertInteger';
import { defaultGrid, defaultYAxis } from '../defaults';
Expand Down Expand Up @@ -654,7 +655,7 @@ export default function transformProps(
.map(entry => entry.name || '')
.concat(extractAnnotationLabels(annotationLayers, annotationData)),
},
series: dedupSeries(series),
series: dedupSeries(reorderForecastSeries(series)),
toolbox: {
show: zoomable,
top: TIMESERIES_CONSTANTS.toolboxTop,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import {
extractForecastValuesFromTooltipParams,
formatForecastTooltipSeries,
rebaseForecastDatum,
reorderForecastSeries,
} from '../utils/forecast';
import { convertInteger } from '../utils/convertInteger';
import { defaultGrid, defaultYAxis } from '../defaults';
Expand Down Expand Up @@ -615,7 +616,7 @@ export default function transformProps(
),
data: legendData as string[],
},
series: dedupSeries(series),
series: dedupSeries(reorderForecastSeries(series)),
toolbox: {
show: zoomable,
top: TIMESERIES_CONSTANTS.toolboxTop,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,35 @@ export function rebaseForecastDatum(
return newRow;
});
}


Check failure on line 154 in superset-frontend/plugins/plugin-chart-echarts/src/utils/forecast.ts

View workflow job for this annotation

GitHub Actions / frontend-build

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

if (
!row.some(item => {
const context = extractForecastSeriesContext(item.id);
return context && sortOrder.hasOwnProperty(context.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);

const aOrder = sortOrder[aContext.type] || Number.MAX_SAFE_INTEGER; // Put other metrics at the end
const bOrder = sortOrder[bContext.type] || Number.MAX_SAFE_INTEGER; // Put other metrics at the end

return aOrder - bOrder;
});
}

Check failure on line 184 in superset-frontend/plugins/plugin-chart-echarts/src/utils/forecast.ts

View workflow job for this annotation

GitHub Actions / frontend-build

Insert `⏎`

0 comments on commit 871e9fa

Please sign in to comment.