This is an automated email from the ASF dual-hosted git repository.
EnxDev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 7a92154b4cd fix(echarts): show Mixed chart stack totals on each
query's top series (#45257)
7a92154b4cd is described below
commit 7a92154b4cd2f1679721fa4feed59397a502882f
Author: raams95 <[email protected]>
AuthorDate: Mon Nov 16 11:49:16 2026 -0600
fix(echarts): show Mixed chart stack totals on each query's top series
(#45257)
Co-authored-by: JanakiRamChittineni
<[email protected]>
Co-authored-by: Evan Rusackas <[email protected]>
---
.../src/MixedTimeseries/controlPanel.tsx | 4 +-
.../src/MixedTimeseries/transformProps.ts | 23 ++++---
.../plugin-chart-echarts/src/utils/series.ts | 20 +++++-
.../test/MixedTimeseries/controlPanel.test.ts | 29 ++++++++
.../test/MixedTimeseries/transformProps.test.ts | 80 ++++++++++++++++++++++
.../plugin-chart-echarts/test/utils/series.test.ts | 26 +++++++
6 files changed, 171 insertions(+), 11 deletions(-)
diff --git
a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/controlPanel.tsx
b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/controlPanel.tsx
index 6f91efe9e41..b33159df28d 100644
---
a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/controlPanel.tsx
+++
b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/controlPanel.tsx
@@ -241,8 +241,8 @@ function createCustomizeSection(
'Only show the total value on the stacked chart, and not show on
the selected category',
),
visibility: ({ controls }: ControlPanelsContainerProps) =>
- Boolean(controls?.show_value?.value) &&
- Boolean(controls?.stack?.value),
+ Boolean(controls?.[`show_value${controlSuffix}`]?.value) &&
+ Boolean(controls?.[`stack${controlSuffix}`]?.value),
},
},
],
diff --git
a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts
b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts
index 6c945a019cf..f311aeeded8 100644
---
a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts
+++
b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts
@@ -437,14 +437,6 @@ export default function transformProps(
primarySeries.add(seriesOption.id as string);
}
};
- const showValueIndexesA = extractShowValueIndexes(rawSeriesA, {
- stack,
- onlyTotal,
- });
- const showValueIndexesB = extractShowValueIndexes(rawSeriesB, {
- stack,
- onlyTotal,
- });
annotationLayers
.filter((layer: AnnotationLayer) => layer.show)
@@ -522,6 +514,15 @@ export default function transformProps(
const displayLabelMap: Record<string, string[]> = {};
const displayLabelMapB: Record<string, string[]> = {};
+ // Value labels are matched against the ECharts series index, which also
+ // counts the annotation series and, for Query B, the Query A series
+ // rendered before them.
+ const showValueIndexesA = extractShowValueIndexes(rawSeriesA, {
+ stack,
+ onlyTotal,
+ seriesIndexOffset: series.length,
+ });
+
rawSeriesA.forEach(entry => {
const entryName = String(entry.name || '');
const seriesName = inverted[entryName] || entryName;
@@ -628,6 +629,12 @@ export default function transformProps(
}
});
+ const showValueIndexesB = extractShowValueIndexes(rawSeriesB, {
+ stack: stackB,
+ onlyTotal: onlyTotalB,
+ seriesIndexOffset: series.length,
+ });
+
rawSeriesB.forEach(entry => {
const entryName = String(entry.name || '');
const seriesEntry = inverted[entryName] || entryName;
diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts
b/superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts
index 219b3e72266..9712463e0fc 100644
--- a/superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts
+++ b/superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts
@@ -506,6 +506,8 @@ const DEFAULT_STACK_GROUP = '__default__';
* @param opts.legendState Active legend state (hidden series are skipped).
* @param opts.seriesStackIds Optional per-series stack-group key (parallel to
* `series`). Defaults to a single shared group.
+ * @param opts.seriesIndexOffset Rendered index of `series[0]`, for charts
+ * that render other series before these ones.
* @returns A `Record<stackGroupKey, number[]>` where each inner array maps
* `dataIndex → seriesIndex` of the topmost series in that group.
*/
@@ -517,10 +519,18 @@ export function extractShowValueIndexes(
isHorizontal?: boolean;
legendState?: LegendState;
seriesStackIds?: string[];
+ seriesIndexOffset?: number;
},
): Record<string, number[]> {
const result: Record<string, number[]> = Object.create(null);
- const { legendState, stack, isHorizontal, onlyTotal, seriesStackIds } = opts;
+ const {
+ legendState,
+ stack,
+ isHorizontal,
+ onlyTotal,
+ seriesStackIds,
+ seriesIndexOffset = 0,
+ } = opts;
if (!stack) {
return result;
}
@@ -552,6 +562,14 @@ export function extractShowValueIndexes(
});
});
+ if (seriesIndexOffset) {
+ Object.values(result).forEach(showValueIndexes => {
+ showValueIndexes.forEach((seriesIndex, dataIndex) => {
+ showValueIndexes[dataIndex] = seriesIndex + seriesIndexOffset;
+ });
+ });
+ }
+
return result;
}
diff --git
a/superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/controlPanel.test.ts
b/superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/controlPanel.test.ts
index 7be498a0735..e75115753cf 100644
---
a/superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/controlPanel.test.ts
+++
b/superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/controlPanel.test.ts
@@ -107,3 +107,32 @@ test('should have correct visibility for label_positionB',
() => {
} as unknown as ControlPanelsContainerProps),
).toBe(false);
});
+
+test('should show only_totalB based on the Query B value and stack controls',
() => {
+ const onlyTotalBCtrl = getControl(
+ 'only_totalB',
+ ) as unknown as VisibilityControl;
+ expect(onlyTotalBCtrl).toBeDefined();
+
+ expect(
+ onlyTotalBCtrl.config.visibility({
+ controls: {
+ show_value: { value: false },
+ stack: { value: false },
+ show_valueB: { value: true },
+ stackB: { value: true },
+ },
+ } as unknown as ControlPanelsContainerProps),
+ ).toBe(true);
+
+ expect(
+ onlyTotalBCtrl.config.visibility({
+ controls: {
+ show_value: { value: true },
+ stack: { value: true },
+ show_valueB: { value: false },
+ stackB: { value: false },
+ },
+ } as unknown as ControlPanelsContainerProps),
+ ).toBe(false);
+});
diff --git
a/superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/transformProps.test.ts
b/superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/transformProps.test.ts
index 3aca26c7e0a..0f053e6a317 100644
---
a/superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/transformProps.test.ts
+++
b/superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/transformProps.test.ts
@@ -549,6 +549,86 @@ test('threads labelPosition and labelPositionB to series A
and B', () => {
expect(seriesB?.label?.position).toBe(LabelPositionEnum.Bottom);
});
+function formatFirstValueLabels(series: SeriesOption[]) {
+ const labels: Record<string, string | number | undefined> = {};
+ // ECharts passes each series' position in the rendered series array.
+ series.forEach((option, seriesIndex) => {
+ const formatter = (option as SeriesWithLabelFormatter).label?.formatter;
+ if (formatter) {
+ labels[String(option.name)] = formatter({
+ dataIndex: 0,
+ seriesIndex,
+ seriesName: String(option.name),
+ value: (option.data as [number, number][])[0],
+ });
+ }
+ });
+ return labels;
+}
+
+test('shows the Query B stack total on its topmost series', () => {
+ const chartProps = createEchartsTimeseriesTestChartProps<
+ EchartsMixedTimeseriesFormData,
+ EchartsMixedTimeseriesProps
+ >({
+ ...MIXED_TIMESERIES_CHART_PROPS_DEFAULTS,
+ defaultQueriesData: queriesData,
+ formData: {
+ ...formData,
+ showQueryIdentifiers: true,
+ stack: false,
+ showValueB: true,
+ onlyTotalB: true,
+ },
+ queriesData,
+ });
+
+ const { echartOptions } = transformProps(chartProps);
+
+ expect(
+ formatFirstValueLabels(echartOptions.series as SeriesOption[]),
+ ).toMatchObject({
+ 'sum__num (Query B), girl': '',
+ 'sum__num (Query B), boy': '3',
+ });
+});
+
+test('keeps the Query A stack total on its topmost series when annotations are
shown', () => {
+ const formula: FormulaAnnotationLayer = {
+ name: 'My Formula',
+ annotationType: AnnotationType.Formula,
+ value: 'x*2',
+ style: AnnotationStyle.Solid,
+ show: true,
+ showLabel: false,
+ };
+ const chartProps = createEchartsTimeseriesTestChartProps<
+ EchartsMixedTimeseriesFormData,
+ EchartsMixedTimeseriesProps
+ >({
+ ...MIXED_TIMESERIES_CHART_PROPS_DEFAULTS,
+ defaultQueriesData: queriesData,
+ formData: {
+ ...formData,
+ annotationLayers: [formula],
+ showQueryIdentifiers: true,
+ seriesType: EchartsTimeseriesSeriesType.Bar,
+ showValue: true,
+ onlyTotal: true,
+ },
+ queriesData,
+ });
+
+ const { echartOptions } = transformProps(chartProps);
+
+ expect(
+ formatFirstValueLabels(echartOptions.series as SeriesOption[]),
+ ).toMatchObject({
+ 'sum__num (Query A), girl': '',
+ 'sum__num (Query A), boy': '3',
+ });
+});
+
describe('legend sorting', () => {
const getChartProps = (overrides = {}) =>
createEchartsTimeseriesTestChartProps<
diff --git
a/superset-frontend/plugins/plugin-chart-echarts/test/utils/series.test.ts
b/superset-frontend/plugins/plugin-chart-echarts/test/utils/series.test.ts
index ce80d9a38bc..d23650a218b 100644
--- a/superset-frontend/plugins/plugin-chart-echarts/test/utils/series.test.ts
+++ b/superset-frontend/plugins/plugin-chart-echarts/test/utils/series.test.ts
@@ -1165,6 +1165,32 @@ describe('extractShowValueIndexes', () => {
});
});
+ test('should shift the indexes by the series rendered before them', () => {
+ expect(
+ extractShowValueIndexes(
+ [
+ {
+ id: 'abc',
+ name: 'abc',
+ data: [
+ ['Jan', 10],
+ ['Feb', null],
+ ],
+ },
+ {
+ id: 'def',
+ name: 'def',
+ data: [
+ ['Jan', 20],
+ ['Feb', null],
+ ],
+ },
+ ],
+ { stack: true, onlyTotal: true, seriesIndexOffset: 3 },
+ ),
+ ).toEqual({ __default__: [4, undefined] });
+ });
+
test('should safely handle stack groups with prototype property names like
__proto__ or constructor', () => {
const result = extractShowValueIndexes(
[