mirror of
https://github.com/apache/superset.git
synced 2026-04-18 23:55:00 +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
@@ -17,11 +17,13 @@
|
||||
* under the License.
|
||||
*/
|
||||
import { getNumberFormatter, NumberFormats } from '@superset-ui/core';
|
||||
import { SeriesOption } from 'echarts';
|
||||
import {
|
||||
extractForecastSeriesContext,
|
||||
extractForecastValuesFromTooltipParams,
|
||||
formatForecastTooltipSeries,
|
||||
rebaseForecastDatum,
|
||||
reorderForecastSeries,
|
||||
} from '../../src/utils/forecast';
|
||||
import { ForecastSeriesEnum } from '../../src/types';
|
||||
|
||||
@@ -46,6 +48,47 @@ describe('extractForecastSeriesContext', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('reorderForecastSeries', () => {
|
||||
it('should reorder the forecast series and preserve values', () => {
|
||||
const input: SeriesOption[] = [
|
||||
{ id: `series${ForecastSeriesEnum.Observation}`, data: [10, 20, 30] },
|
||||
{ id: `series${ForecastSeriesEnum.ForecastTrend}`, data: [15, 25, 35] },
|
||||
{ id: `series${ForecastSeriesEnum.ForecastLower}`, data: [5, 15, 25] },
|
||||
{ id: `series${ForecastSeriesEnum.ForecastUpper}`, data: [25, 35, 45] },
|
||||
];
|
||||
const expectedOutput: SeriesOption[] = [
|
||||
{ id: `series${ForecastSeriesEnum.ForecastLower}`, data: [5, 15, 25] },
|
||||
{ id: `series${ForecastSeriesEnum.ForecastUpper}`, data: [25, 35, 45] },
|
||||
{ id: `series${ForecastSeriesEnum.ForecastTrend}`, data: [15, 25, 35] },
|
||||
{ id: `series${ForecastSeriesEnum.Observation}`, data: [10, 20, 30] },
|
||||
];
|
||||
expect(reorderForecastSeries(input)).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it('should handle an empty array', () => {
|
||||
expect(reorderForecastSeries([])).toEqual([]);
|
||||
});
|
||||
|
||||
it('should not reorder if no relevant series are present', () => {
|
||||
const input: SeriesOption[] = [{ id: 'some-other-series' }];
|
||||
expect(reorderForecastSeries(input)).toEqual(input);
|
||||
});
|
||||
|
||||
it('should handle undefined ids', () => {
|
||||
const input: SeriesOption[] = [
|
||||
{ id: `series${ForecastSeriesEnum.ForecastLower}` },
|
||||
{ id: undefined },
|
||||
{ id: `series${ForecastSeriesEnum.ForecastTrend}` },
|
||||
];
|
||||
const expectedOutput: SeriesOption[] = [
|
||||
{ id: `series${ForecastSeriesEnum.ForecastLower}` },
|
||||
{ id: `series${ForecastSeriesEnum.ForecastTrend}` },
|
||||
{ id: undefined },
|
||||
];
|
||||
expect(reorderForecastSeries(input)).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
|
||||
describe('rebaseForecastDatum', () => {
|
||||
it('should subtract lower confidence level from upper value', () => {
|
||||
expect(
|
||||
|
||||
Reference in New Issue
Block a user