rusackas commented on code in PR #30716: URL: https://github.com/apache/superset/pull/30716#discussion_r1876718841
########## superset-frontend/plugins/plugin-chart-echarts/src/utils/forecast.ts: ########## @@ -150,3 +150,34 @@ export function rebaseForecastDatum( return newRow; }); } + +// 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 Review Comment: Not sure how guaranteed the context and type are, so you could add safeguards if you think it's warranted: `const aOrder = (aContext?.type && sortOrder[aContext.type]) || Number.MAX_SAFE_INTEGER;` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org