Skip to content

Commit

Permalink
fix(plugin-chart-echarts): xAxis scale is not correct when setting qu…
Browse files Browse the repository at this point in the history
…arter time grain (#19686)
  • Loading branch information
stephenLYZ authored Apr 13, 2022
1 parent ee85466 commit 059cb4e
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
isFormulaAnnotationLayer,
isIntervalAnnotationLayer,
isTimeseriesAnnotationLayer,
TimeGranularity,
TimeseriesChartDataResponseResult,
} from '@superset-ui/core';
import { EChartsCoreOption, SeriesOption } from 'echarts';
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -126,6 +135,7 @@ export default function transformProps(
yAxisTitleMargin,
yAxisTitlePosition,
sliceId,
timeGrainSqla,
}: EchartsTimeseriesFormData = { ...DEFAULT_FORM_DATA, ...formData };

const colorScale = CategoricalColorNamespace.getScale(colorScheme as string);
Expand Down Expand Up @@ -324,6 +334,10 @@ export default function transformProps(
formatter: xAxisFormatter,
rotate: xAxisLabelRotation,
},
minInterval:
xAxisType === 'time' && timeGrainSqla
? TimeGrainToTimestamp[timeGrainSqla]
: 0,
},
yAxis: {
...defaultYAxis,
Expand Down

0 comments on commit 059cb4e

Please sign in to comment.