fix(plugin-chart-echarts): normalize temporal string groupbys (#24134)
This commit is contained in:
parent
d0687d04eb
commit
f817c10422
|
|
@ -29,6 +29,7 @@ import {
|
|||
NumberFormatter,
|
||||
TimeFormatter,
|
||||
SupersetTheme,
|
||||
normalizeTimestamp,
|
||||
} from '@superset-ui/core';
|
||||
import { SortSeriesType } from '@superset-ui/chart-controls';
|
||||
import { format, LegendComponentOption, SeriesOption } from 'echarts';
|
||||
|
|
@ -336,7 +337,12 @@ export function formatSeriesName(
|
|||
return name.toString();
|
||||
}
|
||||
if (name instanceof Date || coltype === GenericDataType.TEMPORAL) {
|
||||
const d = name instanceof Date ? name : new Date(name);
|
||||
const normalizedName =
|
||||
typeof name === 'string' ? normalizeTimestamp(name) : name;
|
||||
const d =
|
||||
normalizedName instanceof Date
|
||||
? normalizedName
|
||||
: new Date(normalizedName);
|
||||
|
||||
return timeFormatter ? timeFormatter(d) : d.toISOString();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
import { SortSeriesType } from '@superset-ui/chart-controls';
|
||||
import {
|
||||
DataRecord,
|
||||
GenericDataType,
|
||||
getNumberFormatter,
|
||||
getTimeFormatter,
|
||||
supersetTheme as theme,
|
||||
|
|
@ -628,6 +629,17 @@ describe('formatSeriesName', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('should normalize non-UTC string based timestamp', () => {
|
||||
const annualTimeFormatter = getTimeFormatter('%Y');
|
||||
expect(
|
||||
formatSeriesName('1995-01-01 00:00:00.000000', {
|
||||
timeFormatter: annualTimeFormatter,
|
||||
coltype: GenericDataType.TEMPORAL,
|
||||
}),
|
||||
).toEqual('1995');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getLegendProps', () => {
|
||||
it('should return the correct props for scroll type with top orientation without zoom', () => {
|
||||
expect(
|
||||
|
|
@ -719,12 +731,7 @@ describe('formatSeriesName', () => {
|
|||
|
||||
it('should return the correct props for plain type with bottom orientation', () => {
|
||||
expect(
|
||||
getLegendProps(
|
||||
LegendType.Plain,
|
||||
LegendOrientation.Bottom,
|
||||
false,
|
||||
theme,
|
||||
),
|
||||
getLegendProps(LegendType.Plain, LegendOrientation.Bottom, false, theme),
|
||||
).toEqual({
|
||||
show: false,
|
||||
bottom: 0,
|
||||
|
|
@ -850,4 +857,3 @@ describe('formatSeriesName', () => {
|
|||
expect(formatter.format(50000)).toEqual('50000');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue