diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts index 33df597f923..9b6c6d65bbf 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts @@ -589,7 +589,8 @@ export default function transformProps( ? getXAxisFormatter(xAxisTimeFormat, timeGrainSqla) : String; - const showMaxLabel = xAxisType === AxisType.Time && xAxisLabelRotation === 0; + const showMaxLabel = + xAxisType === AxisType.Time && xAxisLabelRotation === 0 && !!timeGrainSqla; const deduplicatedFormatter = showMaxLabel ? (() => { let lastLabel: string | undefined; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts index 8bf0909489a..1086c5f6a8c 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts @@ -861,7 +861,8 @@ export default function transformProps( // boundary that formats identically to the last data-point tick (e.g. // "2005" appears twice with Year grain). Wrap the formatter to suppress // consecutive duplicate labels. - const showMaxLabel = xAxisType === AxisType.Time && xAxisLabelRotation === 0; + const showMaxLabel = + xAxisType === AxisType.Time && xAxisLabelRotation === 0 && !!timeGrainSqla; const deduplicatedFormatter = showMaxLabel ? (() => { let lastLabel: string | undefined; diff --git a/superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/transformProps.test.ts b/superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/transformProps.test.ts index a43610f3348..78434f33a40 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/transformProps.test.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/transformProps.test.ts @@ -1444,7 +1444,7 @@ test('x-axis formatter deduplicates consecutive identical labels for coarse time const chartProps = createTestChartProps({ formData: { granularity_sqla: 'ds', - time_grain_sqla: TimeGranularity.YEAR, + timeGrainSqla: TimeGranularity.YEAR, xAxisTimeFormat: '%Y', }, queriesData: [ @@ -1473,6 +1473,30 @@ test('x-axis formatter deduplicates consecutive identical labels for coarse time expect(label4).toBe(''); }); +test('x-axis does not force showMaxLabel when no time grain is set', () => { + const data = [ + { __timestamp: Date.UTC(2003, 0, 6), sales: 100 }, + { __timestamp: Date.UTC(2004, 5, 15), sales: 200 }, + { __timestamp: Date.UTC(2005, 4, 31), sales: 300 }, + ]; + + const chartProps = createTestChartProps({ + formData: { + granularity_sqla: 'ds', + timeGrainSqla: undefined, + }, + queriesData: [ + createTestQueryData(data, { + colnames: ['__timestamp', 'sales'], + coltypes: [GenericDataType.Temporal, GenericDataType.Numeric], + }), + ], + }); + + const xAxisResult = transformProps(chartProps).echartOptions.xAxis as any; + expect(xAxisResult.axisLabel.showMaxLabel).not.toBe(true); +}); + test('numeric x coltype routes through the number formatter (not the time formatter)', () => { // Regression guard for echarts-timeseries-epoch-x-axis-labels investigation. // When the query reports a Numeric x-axis coltype (including epoch-ms-like diff --git a/superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/transformers.test.ts b/superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/transformers.test.ts index 54da9c14ea0..19aa1d4a0d6 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/transformers.test.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/transformers.test.ts @@ -16,7 +16,11 @@ * specific language governing permissions and limitations * under the License. */ -import { CategoricalColorScale, ChartProps } from '@superset-ui/core'; +import { + CategoricalColorScale, + ChartProps, + TimeGranularity, +} from '@superset-ui/core'; import { GenericDataType } from '@apache-superset/core/common'; import { supersetTheme } from '@apache-superset/core/theme'; import type { SeriesOption } from 'echarts'; @@ -235,6 +239,7 @@ function buildTimeseriesChartProps( colorScheme: 'bnbColors', datasource: '3__table', granularity_sqla: 'ds', + timeGrainSqla: TimeGranularity.MONTH, metric: 'sum__num', viz_type: 'my_viz', ...overrides, @@ -263,6 +268,7 @@ test('should configure time axis labels to show max label for last month visibil colorScheme: 'bnbColors', datasource: '3__table', granularity_sqla: 'ds', + timeGrainSqla: TimeGranularity.MONTH, metric: 'sum__num', viz_type: 'my_viz', };