Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
TimeseriesChartDataResponseResult,
TimeseriesDataRecord,
getXAxisLabel,
isPhysicalColumn,
isDefined,
} from '@superset-ui/core';
import { EChartsCoreOption, SeriesOption } from 'echarts';
import {
Expand Down Expand Up @@ -152,23 +154,29 @@ export default function transformProps(

const colorScale = CategoricalColorNamespace.getScale(colorScheme as string);

const xAxisCol = getXAxisLabel(
let xAxisLabel = getXAxisLabel(
chartProps.rawFormData as QueryFormData,
) as string;
if (
isPhysicalColumn(chartProps.rawFormData?.x_axis) &&
isDefined(verboseMap[xAxisLabel])
) {
xAxisLabel = verboseMap[xAxisLabel];
}

const rebasedDataA = rebaseForecastDatum(data1, verboseMap);
const rawSeriesA = extractSeries(rebasedDataA, {
fillNeighborValue: stack ? 0 : undefined,
xAxis: xAxisCol,
xAxis: xAxisLabel,
});
const rebasedDataB = rebaseForecastDatum(data2, verboseMap);
const rawSeriesB = extractSeries(rebasedDataB, {
fillNeighborValue: stackB ? 0 : undefined,
xAxis: xAxisCol,
xAxis: xAxisLabel,
});

const dataTypes = getColtypesMapping(queriesData[0]);
const xAxisDataType = dataTypes?.[xAxisCol] ?? dataTypes?.[xAxisOrig];
const xAxisDataType = dataTypes?.[xAxisLabel] ?? dataTypes?.[xAxisOrig];
const xAxisType = getAxisType(xAxisDataType);
const series: SeriesOption[] = [];
const formatter = getNumberFormatter(contributionMode ? ',.0%' : yAxisFormat);
Expand Down Expand Up @@ -205,7 +213,7 @@ export default function transformProps(
{
stack,
percentageThreshold,
xAxisCol,
xAxisCol: xAxisLabel,
},
);
const {
Expand All @@ -214,7 +222,7 @@ export default function transformProps(
} = extractDataTotalValues(rebasedDataB, {
stack: Boolean(stackB),
percentageThreshold,
xAxisCol,
xAxisCol: xAxisLabel,
});

annotationLayers
Expand All @@ -225,7 +233,7 @@ export default function transformProps(
transformFormulaAnnotation(
layer,
data1,
xAxisCol,
xAxisLabel,
xAxisType,
colorScale,
sliceId,
Expand Down Expand Up @@ -502,7 +510,7 @@ export default function transformProps(
onContextMenu,
xValueFormatter: tooltipFormatter,
xAxis: {
label: xAxisCol,
label: xAxisLabel,
type: xAxisType,
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
t,
AxisType,
getXAxisLabel,
isPhysicalColumn,
isDefined,
} from '@superset-ui/core';
import { isDerivedSeries } from '@superset-ui/chart-controls';
import { EChartsCoreOption, SeriesOption } from 'echarts';
Expand Down Expand Up @@ -148,19 +150,25 @@ export default function transformProps(

const colorScale = CategoricalColorNamespace.getScale(colorScheme as string);
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 { totalStackedValues, thresholdValues } = extractDataTotalValues(
rebasedData,
{
stack,
percentageThreshold,
xAxisCol,
xAxisCol: xAxisLabel,
},
);
const rawSeries = extractSeries(rebasedData, {
fillNeighborValue: stack && !forecastEnabled ? 0 : undefined,
xAxis: xAxisCol,
xAxis: xAxisLabel,
removeNulls: seriesType === EchartsTimeseriesSeriesType.Scatter,
stack,
totalStackedValues,
Expand All @@ -175,7 +183,7 @@ export default function transformProps(
Object.values(rawSeries).map(series => series.name as string),
);
const isAreaExpand = stack === AreaChartExtraControlsValue.Expand;
const xAxisDataType = dataTypes?.[xAxisCol] ?? dataTypes?.[xAxisOrig];
const xAxisDataType = dataTypes?.[xAxisLabel] ?? dataTypes?.[xAxisOrig];

const xAxisType = getAxisType(xAxisDataType);
const series: SeriesOption[] = [];
Expand Down Expand Up @@ -229,7 +237,7 @@ export default function transformProps(
transformFormulaAnnotation(
layer,
data,
xAxisCol,
xAxisLabel,
xAxisType,
colorScale,
sliceId,
Expand Down Expand Up @@ -452,7 +460,7 @@ export default function transformProps(
onContextMenu,
xValueFormatter: tooltipFormatter,
xAxis: {
label: xAxisCol,
label: xAxisLabel,
type: xAxisType,
},
};
Expand Down