From 092d2e5c454b98b5d56e98c98eda09256d054d67 Mon Sep 17 00:00:00 2001 From: stephenLYZ <750188453@qq.com> Date: Wed, 13 Apr 2022 16:48:27 +0800 Subject: [PATCH] fix(plugin-chart-echarts): xAxis scale is not correct when setting quarter time grain --- .../src/Timeseries/transformProps.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 1a2200db22097..b8585c6e68ed8 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts @@ -28,6 +28,7 @@ import { isFormulaAnnotationLayer, isIntervalAnnotationLayer, isTimeseriesAnnotationLayer, + TimeGranularity, TimeseriesChartDataResponseResult, } from '@superset-ui/core'; import { EChartsCoreOption, SeriesOption } from 'echarts'; @@ -69,6 +70,14 @@ import { } from './transformers'; import { TIMESERIES_CONSTANTS } from '../constants'; +const TimeGrainToTimestamp = { + [TimeGranularity.HOUR]: 3600 * 1000, + [TimeGranularity.DAY]: 3600 * 1000 * 24, + [TimeGranularity.MONTH]: 3600 * 1000 * 24 * 31, + [TimeGranularity.QUARTER]: 3600 * 1000 * 24 * 31 * 3, + [TimeGranularity.YEAR]: 3600 * 1000 * 24 * 31 * 12, +}; + export default function transformProps( chartProps: EchartsTimeseriesChartProps, ): TimeseriesChartTransformedProps { @@ -126,6 +135,7 @@ export default function transformProps( yAxisTitleMargin, yAxisTitlePosition, sliceId, + timeGrainSqla, }: EchartsTimeseriesFormData = { ...DEFAULT_FORM_DATA, ...formData }; const colorScale = CategoricalColorNamespace.getScale(colorScheme as string); @@ -324,6 +334,10 @@ export default function transformProps( formatter: xAxisFormatter, rotate: xAxisLabelRotation, }, + minInterval: + xAxisType === 'time' && timeGrainSqla + ? TimeGrainToTimestamp[timeGrainSqla] + : 0, }, yAxis: { ...defaultYAxis,