feat(stack by dimension): add a stack by dimension dropdown list (#32707)

Co-authored-by: CAPELLI Giampaolo <giampaolo.capelli@docaposte.fr>
This commit is contained in:
Giampaolo Capelli
2025-05-22 16:10:18 +02:00
committed by GitHub
parent 875f538d54
commit 5b2f1bbf9e
3 changed files with 53 additions and 1 deletions

View File

@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { t } from '@superset-ui/core';
import { JsonArray, t } from '@superset-ui/core';
import {
ControlPanelConfig,
ControlPanelsContainerProps,
@@ -45,6 +45,7 @@ import {
DEFAULT_FORM_DATA,
TIME_SERIES_DESCRIPTION_TEXT,
} from '../../constants';
import { StackControlsValue } from '../../../constants';
const {
logAxis,
@@ -321,6 +322,38 @@ const config: ControlPanelConfig = {
['color_scheme'],
['time_shift_color'],
...showValueSection,
[
{
name: 'stackDimension',
config: {
type: 'SelectControl',
label: t('Split stack by'),
visibility: ({ controls }) =>
controls?.stack?.value === StackControlsValue.Stack,
renderTrigger: true,
description: t(
'Stack in groups, where each group corresponds to a dimension',
),
shouldMapStateToProps: (
prevState,
state,
controlState,
chartState,
) => true,
mapStateToProps: (state, controlState, chartState) => {
const value: JsonArray = state.controls.groupby
.value as JsonArray;
const valueAsStringArr: string[][] = value.map(v => {
if (v) return [v.toString(), v.toString()];
return ['', ''];
});
return {
choices: valueAsStringArr,
};
},
},
},
],
[minorTicks],
[
{

View File

@@ -191,6 +191,7 @@ export default function transformProps(
yAxisTitleMargin,
yAxisTitlePosition,
zoomable,
stackDimension,
}: EchartsTimeseriesFormData = { ...DEFAULT_FORM_DATA, ...formData };
const refs: Refs = {};
const groupBy = ensureIsArray(groupby);
@@ -418,6 +419,23 @@ export default function transformProps(
}
});
if (
stack === StackControlsValue.Stack &&
stackDimension &&
chartProps.rawFormData.groupby
) {
const idxSelectedDimension =
formData.metrics.length > 1
? 1
: 0 + chartProps.rawFormData.groupby.indexOf(stackDimension);
for (const s of series) {
if (s.id) {
const columnsArr = labelMap[s.id];
(s as any).stack = columnsArr[idxSelectedDimension];
}
}
}
// axis bounds need to be parsed to replace incompatible values with undefined
const [xAxisMin, xAxisMax] = (xAxisBounds || []).map(parseAxisBound);
let [yAxisMin, yAxisMax] = (yAxisBounds || []).map(parseAxisBound);

View File

@@ -74,6 +74,7 @@ export type EchartsTimeseriesFormData = QueryFormData & {
rowLimit: number;
seriesType: EchartsTimeseriesSeriesType;
stack: StackType;
stackDimension: string;
timeCompare?: string[];
tooltipTimeFormat?: string;
showTooltipTotal?: boolean;