mirror of
https://github.com/apache/superset.git
synced 2026-04-18 15:44:57 +00:00
fix: Reordering echart props to fix confidence interval in Mixed Charts (#30716)
Co-authored-by: Vedant Prajapati <40185967+vedantprajapati@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
23d9f46d30
commit
f4efce3475
@@ -78,6 +78,7 @@ import {
|
||||
extractForecastValuesFromTooltipParams,
|
||||
formatForecastTooltipSeries,
|
||||
rebaseForecastDatum,
|
||||
reorderForecastSeries,
|
||||
} from '../utils/forecast';
|
||||
import { convertInteger } from '../utils/convertInteger';
|
||||
import { defaultGrid, defaultYAxis } from '../defaults';
|
||||
@@ -661,7 +662,7 @@ export default function transformProps(
|
||||
.map(entry => entry.name || '')
|
||||
.concat(extractAnnotationLabels(annotationLayers, annotationData)),
|
||||
},
|
||||
series: dedupSeries(series),
|
||||
series: dedupSeries(reorderForecastSeries(series) as SeriesOption[]),
|
||||
toolbox: {
|
||||
show: zoomable,
|
||||
top: TIMESERIES_CONSTANTS.toolboxTop,
|
||||
|
||||
@@ -80,6 +80,7 @@ import {
|
||||
extractForecastValuesFromTooltipParams,
|
||||
formatForecastTooltipSeries,
|
||||
rebaseForecastDatum,
|
||||
reorderForecastSeries,
|
||||
} from '../utils/forecast';
|
||||
import { convertInteger } from '../utils/convertInteger';
|
||||
import { defaultGrid, defaultYAxis } from '../defaults';
|
||||
@@ -624,7 +625,7 @@ export default function transformProps(
|
||||
),
|
||||
data: legendData as string[],
|
||||
},
|
||||
series: dedupSeries(series),
|
||||
series: dedupSeries(reorderForecastSeries(series) as SeriesOption[]),
|
||||
toolbox: {
|
||||
show: zoomable,
|
||||
top: TIMESERIES_CONSTANTS.toolboxTop,
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
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,
|
||||
@@ -149,3 +149,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: 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 =>
|
||||
item.id &&
|
||||
sortOrder.hasOwnProperty(extractForecastSeriesContext(item.id).type),
|
||||
)
|
||||
) {
|
||||
return row;
|
||||
}
|
||||
|
||||
return row.sort((a, b) => {
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user