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: Bar stacking on v2 doesn't work if the x-axis is value type #20591

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ export type TabOverride = 'data' | 'customize' | boolean;
* show a warning based on the value of another component. It's also possible to bind
* arbitrary data from the redux store to the component this way.
* - tabOverride: set to 'data' if you want to force a renderTrigger to show up on the `Data`
tab, or 'customize' if you want it to show up on that tam. Otherwise sections with ALL
`renderTrigger: true` components will show up on the `Customize` tab.
tab, or 'customize' if you want it to show up on that tam. Otherwise sections with ALL
`renderTrigger: true` components will show up on the `Customize` tab.
* - visibility: a function that uses control panel props to check whether a control should
* be visibile.
* be visible. Return undefined if the result of the function call should not be used.
*/
export interface BaseControlConfig<
T extends ControlType = ControlType,
Expand Down Expand Up @@ -230,7 +230,7 @@ export interface BaseControlConfig<
visibility?: (
props: ControlPanelsContainerProps,
controlData: AnyDict,
) => boolean;
) => boolean | undefined;
}

export interface ControlValueValidator<
Expand Down
26 changes: 25 additions & 1 deletion superset-frontend/plugins/plugin-chart-echarts/src/controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import React from 'react';
import { t } from '@superset-ui/core';
import { DTTM_ALIAS, getColumnLabel, t } from '@superset-ui/core';
import {
ControlPanelsContainerProps,
ControlSetItem,
Expand All @@ -26,6 +26,7 @@ import {
} from '@superset-ui/chart-controls';
import { DEFAULT_LEGEND_FORM_DATA } from './constants';
import { DEFAULT_FORM_DATA } from './Timeseries/constants';
import { getAxisType, getColtypesMapping } from './utils/series';

const { legendMargin, legendOrientation, legendType, showLegend } =
DEFAULT_LEGEND_FORM_DATA;
Expand Down Expand Up @@ -120,6 +121,29 @@ export const stackControl: ControlSetItem = {
renderTrigger: true,
default: false,
description: t('Stack series on top of each other'),
visibility: (props: ControlPanelsContainerProps) => {
// Bar stacking is not supported if the x-axis is value type
// Source: https://github.com/apache/echarts/issues/15102
const vizType = props?.form_data?.viz_type;
if (vizType !== 'echarts_timeseries_bar') {
return undefined;
}

const data = props?.chart?.queriesResponse?.[0];
const verboseMap = props?.exploreState?.datasource?.verbose_map ?? {};
const xAxis = props?.form_data?.x_axis;

if (!data || !xAxis) {
return undefined;
}

const dataTypes = getColtypesMapping(data);
const xAxisCol = verboseMap[xAxis] || getColumnLabel(xAxis || DTTM_ALIAS);
const xAxisDataType = dataTypes?.[xAxisCol];
const xAxisType = getAxisType(xAxisDataType);

return xAxisType === 'category';
},
},
};

Expand Down