Skip to content

Commit

Permalink
fix: Bar stacking on v2 doesn't work if the x-axis is value type
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomedina248 committed Jul 2, 2022
1 parent b870a21 commit cfb8974
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
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

0 comments on commit cfb8974

Please sign in to comment.