fix: categorical x-axis can't apply the label of column (#21869)

This commit is contained in:
Yongjie Zhao 2022-10-19 18:47:02 +08:00 committed by GitHub
parent 47b1e0ca9d
commit 9aa804e070
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 14 deletions

View File

@ -30,6 +30,8 @@ import {
TimeseriesChartDataResponseResult, TimeseriesChartDataResponseResult,
TimeseriesDataRecord, TimeseriesDataRecord,
getXAxisLabel, getXAxisLabel,
isPhysicalColumn,
isDefined,
} from '@superset-ui/core'; } from '@superset-ui/core';
import { EChartsCoreOption, SeriesOption } from 'echarts'; import { EChartsCoreOption, SeriesOption } from 'echarts';
import { import {
@ -152,23 +154,29 @@ export default function transformProps(
const colorScale = CategoricalColorNamespace.getScale(colorScheme as string); const colorScale = CategoricalColorNamespace.getScale(colorScheme as string);
const xAxisCol = getXAxisLabel( let xAxisLabel = getXAxisLabel(
chartProps.rawFormData as QueryFormData, chartProps.rawFormData as QueryFormData,
) as string; ) as string;
if (
isPhysicalColumn(chartProps.rawFormData?.x_axis) &&
isDefined(verboseMap[xAxisLabel])
) {
xAxisLabel = verboseMap[xAxisLabel];
}
const rebasedDataA = rebaseForecastDatum(data1, verboseMap); const rebasedDataA = rebaseForecastDatum(data1, verboseMap);
const rawSeriesA = extractSeries(rebasedDataA, { const rawSeriesA = extractSeries(rebasedDataA, {
fillNeighborValue: stack ? 0 : undefined, fillNeighborValue: stack ? 0 : undefined,
xAxis: xAxisCol, xAxis: xAxisLabel,
}); });
const rebasedDataB = rebaseForecastDatum(data2, verboseMap); const rebasedDataB = rebaseForecastDatum(data2, verboseMap);
const rawSeriesB = extractSeries(rebasedDataB, { const rawSeriesB = extractSeries(rebasedDataB, {
fillNeighborValue: stackB ? 0 : undefined, fillNeighborValue: stackB ? 0 : undefined,
xAxis: xAxisCol, xAxis: xAxisLabel,
}); });
const dataTypes = getColtypesMapping(queriesData[0]); const dataTypes = getColtypesMapping(queriesData[0]);
const xAxisDataType = dataTypes?.[xAxisCol] ?? dataTypes?.[xAxisOrig]; const xAxisDataType = dataTypes?.[xAxisLabel] ?? dataTypes?.[xAxisOrig];
const xAxisType = getAxisType(xAxisDataType); const xAxisType = getAxisType(xAxisDataType);
const series: SeriesOption[] = []; const series: SeriesOption[] = [];
const formatter = getNumberFormatter(contributionMode ? ',.0%' : yAxisFormat); const formatter = getNumberFormatter(contributionMode ? ',.0%' : yAxisFormat);
@ -205,7 +213,7 @@ export default function transformProps(
{ {
stack, stack,
percentageThreshold, percentageThreshold,
xAxisCol, xAxisCol: xAxisLabel,
}, },
); );
const { const {
@ -214,7 +222,7 @@ export default function transformProps(
} = extractDataTotalValues(rebasedDataB, { } = extractDataTotalValues(rebasedDataB, {
stack: Boolean(stackB), stack: Boolean(stackB),
percentageThreshold, percentageThreshold,
xAxisCol, xAxisCol: xAxisLabel,
}); });
annotationLayers annotationLayers
@ -225,7 +233,7 @@ export default function transformProps(
transformFormulaAnnotation( transformFormulaAnnotation(
layer, layer,
data1, data1,
xAxisCol, xAxisLabel,
xAxisType, xAxisType,
colorScale, colorScale,
sliceId, sliceId,
@ -502,7 +510,7 @@ export default function transformProps(
onContextMenu, onContextMenu,
xValueFormatter: tooltipFormatter, xValueFormatter: tooltipFormatter,
xAxis: { xAxis: {
label: xAxisCol, label: xAxisLabel,
type: xAxisType, type: xAxisType,
}, },
}; };

View File

@ -30,6 +30,8 @@ import {
t, t,
AxisType, AxisType,
getXAxisLabel, getXAxisLabel,
isPhysicalColumn,
isDefined,
} from '@superset-ui/core'; } from '@superset-ui/core';
import { isDerivedSeries } from '@superset-ui/chart-controls'; import { isDerivedSeries } from '@superset-ui/chart-controls';
import { EChartsCoreOption, SeriesOption } from 'echarts'; import { EChartsCoreOption, SeriesOption } from 'echarts';
@ -148,19 +150,25 @@ export default function transformProps(
const colorScale = CategoricalColorNamespace.getScale(colorScheme as string); const colorScale = CategoricalColorNamespace.getScale(colorScheme as string);
const rebasedData = rebaseForecastDatum(data, verboseMap); const rebasedData = rebaseForecastDatum(data, verboseMap);
const xAxisCol = getXAxisLabel(chartProps.rawFormData) as string; let xAxisLabel = getXAxisLabel(chartProps.rawFormData) as string;
if (
isPhysicalColumn(chartProps.rawFormData?.x_axis) &&
isDefined(verboseMap[xAxisLabel])
) {
xAxisLabel = verboseMap[xAxisLabel];
}
const isHorizontal = orientation === OrientationType.horizontal; const isHorizontal = orientation === OrientationType.horizontal;
const { totalStackedValues, thresholdValues } = extractDataTotalValues( const { totalStackedValues, thresholdValues } = extractDataTotalValues(
rebasedData, rebasedData,
{ {
stack, stack,
percentageThreshold, percentageThreshold,
xAxisCol, xAxisCol: xAxisLabel,
}, },
); );
const rawSeries = extractSeries(rebasedData, { const rawSeries = extractSeries(rebasedData, {
fillNeighborValue: stack && !forecastEnabled ? 0 : undefined, fillNeighborValue: stack && !forecastEnabled ? 0 : undefined,
xAxis: xAxisCol, xAxis: xAxisLabel,
removeNulls: seriesType === EchartsTimeseriesSeriesType.Scatter, removeNulls: seriesType === EchartsTimeseriesSeriesType.Scatter,
stack, stack,
totalStackedValues, totalStackedValues,
@ -175,7 +183,7 @@ export default function transformProps(
Object.values(rawSeries).map(series => series.name as string), Object.values(rawSeries).map(series => series.name as string),
); );
const isAreaExpand = stack === AreaChartExtraControlsValue.Expand; const isAreaExpand = stack === AreaChartExtraControlsValue.Expand;
const xAxisDataType = dataTypes?.[xAxisCol] ?? dataTypes?.[xAxisOrig]; const xAxisDataType = dataTypes?.[xAxisLabel] ?? dataTypes?.[xAxisOrig];
const xAxisType = getAxisType(xAxisDataType); const xAxisType = getAxisType(xAxisDataType);
const series: SeriesOption[] = []; const series: SeriesOption[] = [];
@ -229,7 +237,7 @@ export default function transformProps(
transformFormulaAnnotation( transformFormulaAnnotation(
layer, layer,
data, data,
xAxisCol, xAxisLabel,
xAxisType, xAxisType,
colorScale, colorScale,
sliceId, sliceId,
@ -452,7 +460,7 @@ export default function transformProps(
onContextMenu, onContextMenu,
xValueFormatter: tooltipFormatter, xValueFormatter: tooltipFormatter,
xAxis: { xAxis: {
label: xAxisCol, label: xAxisLabel,
type: xAxisType, type: xAxisType,
}, },
}; };