You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/10/21 05:07:18 UTC

(superset) branch fix/mixed-chart-truncate-metric-adopted updated (4a49fde17f5 -> a3e170d9df5)

This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a change to branch fix/mixed-chart-truncate-metric-adopted
in repository https://gitbox.apache.org/repos/asf/superset.git


 discard 4a49fde17f5 fix(mixed chart): respect truncate_metric setting for series names
     new a3e170d9df5 fix(mixed chart): respect truncate_metric setting for series names

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (4a49fde17f5)
            \
             N -- N -- N   refs/heads/fix/mixed-chart-truncate-metric-adopted (a3e170d9df5)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../src/MixedTimeseries/transformProps.ts              | 18 ++++++++++++++----
 .../test/MixedTimeseries/transformProps.test.ts        | 15 +++++++++++++++
 2 files changed, 29 insertions(+), 4 deletions(-)


(superset) 01/01: fix(mixed chart): respect truncate_metric setting for series names

Posted by ru...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a commit to branch fix/mixed-chart-truncate-metric-adopted
in repository https://gitbox.apache.org/repos/asf/superset.git

commit a3e170d9df5dd3dca212fa3c6479d01a56270dc6
Author: Evan Rusackas <ev...@rusackas.com>
AuthorDate: Tue Oct 20 21:59:00 2026 -0700

    fix(mixed chart): respect truncate_metric setting for series names
    
    Adds truncateMetric/truncateMetricB to MixedTimeseries so a grouped
    series can drop the "metric, " prefix and show only the groupby/dimension
    values, matching the single-query Timeseries truncate_metric behavior.
    Reuses the same metric-vs-dimension split the existing "metric, dimension"
    branch already applies to the label-map tuple, and runs before the shared
    displayLabelMap/displayLabelMapB population so formatter lookups keyed by
    the truncated name still resolve correctly.
    
    Also keeps the query-identifier suffix ("(Query A)"/"(Query B)") when
    showQueryIdentifiers is on, even while truncating, or Query A and Query B
    become indistinguishable whenever they share a groupby value.
    
    Adopted from #38451 (MelikHajlawi), rebuilt against current master since
    that branch's history had diverged too far to rebase cleanly.
    
    Co-Authored-By: MelikHajlawi <me...@medtech.tn>
    Co-Authored-By: Evan Rusackas <ev...@preset.io>
    Co-Authored-By: Claude Sonnet 5 <no...@anthropic.com>
---
 .../src/MixedTimeseries/transformProps.ts          | 40 ++++++++++++-
 .../src/MixedTimeseries/types.ts                   |  4 ++
 .../test/MixedTimeseries/transformProps.test.ts    | 65 ++++++++++++++++++++++
 3 files changed, 107 insertions(+), 2 deletions(-)

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 c7d26641657..9a6174685f5 100644
--- a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts
+++ b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts
@@ -256,6 +256,8 @@ export default function transformProps(
     showQueryIdentifiers = false,
     metrics = [],
     metricsB = [],
+    truncateMetric,
+    truncateMetricB,
   }: EchartsMixedTimeseriesFormData = { ...DEFAULT_FORM_DATA, ...formData };
 
   const refs: Refs = {};
@@ -544,7 +546,24 @@ export default function transformProps(
 
     let displayName: string;
 
-    if (groupby.length > 0) {
+    if (truncateMetric && groupby.length > 0) {
+      // Drop the metric part entirely and show only the groupby/dimension
+      // values, same metric-vs-dimension split the branch below uses: the
+      // label-map tuple is [metric, ...dimensions] when it has more than
+      // one entry, otherwise the whole tuple is the dimension (no metric
+      // index at all). Still apply the query-identifier suffix when asked
+      // for, or Query A and Query B become indistinguishable whenever they
+      // share a groupby value (#38451).
+      const groupbyValues =
+        labelMapValues && labelMapValues.length > 1
+          ? labelMapValues.slice(1)
+          : (labelMapValues ?? []);
+      const truncatedName =
+        groupbyValues.length > 0 ? groupbyValues.join(', ') : entryName;
+      displayName = showQueryIdentifiers
+        ? `${truncatedName} (Query A)`
+        : truncatedName;
+    } else if (groupby.length > 0) {
       // When we have groupby, format as "metric, dimension". Each series
       // belongs to the metric recorded in its label-map tuple
       // ([metric, ...dimensions]) — always using the first metric would
@@ -651,7 +670,24 @@ export default function transformProps(
 
     let displayName: string;
 
-    if (groupbyB.length > 0) {
+    if (truncateMetricB && groupbyB.length > 0) {
+      // Drop the metric part entirely and show only the groupby/dimension
+      // values, same metric-vs-dimension split the branch below uses: the
+      // label-map tuple is [metric, ...dimensions] when it has more than
+      // one entry, otherwise the whole tuple is the dimension (no metric
+      // index at all). Still apply the query-identifier suffix when asked
+      // for, or Query A and Query B become indistinguishable whenever they
+      // share a groupby value (#38451).
+      const groupbyValues =
+        labelMapValuesB && labelMapValuesB.length > 1
+          ? labelMapValuesB.slice(1)
+          : (labelMapValuesB ?? []);
+      const truncatedName =
+        groupbyValues.length > 0 ? groupbyValues.join(', ') : entryName;
+      displayName = showQueryIdentifiers
+        ? `${truncatedName} (Query B)`
+        : truncatedName;
+    } else if (groupbyB.length > 0) {
       // When we have groupby, format as "metric, dimension". Each series
       // belongs to the metric recorded in its label-map tuple
       // ([metric, ...dimensions]) — always using the first metric would
diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/types.ts b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/types.ts
index de1a267aefd..db4ac80c9bf 100644
--- a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/types.ts
+++ b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/types.ts
@@ -108,6 +108,8 @@ export type EchartsMixedTimeseriesFormData = QueryFormData & {
   yAxisIndexB?: number;
   groupby: QueryFormColumn[];
   groupbyB: QueryFormColumn[];
+  truncateMetric?: boolean;
+  truncateMetricB?: boolean;
 } & LegendFormData &
   TitleFormData;
 
@@ -160,6 +162,8 @@ export const DEFAULT_FORM_DATA: EchartsMixedTimeseriesFormData = {
   zoomable: TIMESERIES_DEFAULTS.zoomable,
   richTooltip: TIMESERIES_DEFAULTS.richTooltip,
   showQueryIdentifiers: false,
+  truncateMetric: false,
+  truncateMetricB: false,
   xAxisLabelRotation: TIMESERIES_DEFAULTS.xAxisLabelRotation,
   xAxisLabelInterval: TIMESERIES_DEFAULTS.xAxisLabelInterval,
   ...DEFAULT_TITLE_FORM_DATA,
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 360209244df..be8d398857f 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
@@ -1967,3 +1967,68 @@ test('converts xAxisLabelInterval string "0" to number 0', () => {
   // "All" must also disable hideOverlap so ECharts never drops a label.
   expect(xAxis.axisLabel.hideOverlap).toBe(false);
 });
+
+describe('truncateMetric / truncateMetricB', () => {
+  const getSeriesNames = (
+    overrides: Partial<EchartsMixedTimeseriesFormData>,
+  ) => {
+    const chartProps = createEchartsTimeseriesTestChartProps<
+      EchartsMixedTimeseriesFormData,
+      EchartsMixedTimeseriesProps
+    >({
+      ...MIXED_TIMESERIES_CHART_PROPS_DEFAULTS,
+      defaultQueriesData: queriesData,
+      formData: { ...formData, ...overrides },
+      queriesData,
+    });
+    const transformed = transformProps(chartProps);
+    return (transformed.echartOptions.series as SeriesOption[]).map(
+      s => s.name,
+    );
+  };
+
+  test('drops the metric prefix for both queries when both flags are on', () => {
+    const seriesNames = getSeriesNames({
+      truncateMetric: true,
+      truncateMetricB: true,
+    });
+
+    expect(seriesNames).toContain('boy');
+    expect(seriesNames).toContain('girl');
+    expect(seriesNames).not.toContain('sum__num, boy');
+    expect(seriesNames).not.toContain('sum__num, girl');
+  });
+
+  test('keeps the "metric, dimension" name when both flags are off', () => {
+    const seriesNames = getSeriesNames({});
+
+    expect(seriesNames).toContain('sum__num, boy');
+    expect(seriesNames).toContain('sum__num, girl');
+  });
+
+  test('truncateMetricB truncates query B independently of query A', () => {
+    const seriesNames = getSeriesNames({ truncateMetricB: true });
+
+    // Query A (not truncated) keeps the metric prefix.
+    expect(seriesNames).toContain('sum__num, boy');
+    expect(seriesNames).toContain('sum__num, girl');
+    // Query B (truncated) drops it.
+    expect(seriesNames).toContain('boy');
+    expect(seriesNames).toContain('girl');
+  });
+
+  test('still appends the query identifier when truncating, so Query A and B stay distinguishable (#38451)', () => {
+    const seriesNames = getSeriesNames({
+      truncateMetric: true,
+      truncateMetricB: true,
+      showQueryIdentifiers: true,
+    });
+
+    expect(seriesNames).toContain('boy (Query A)');
+    expect(seriesNames).toContain('girl (Query A)');
+    expect(seriesNames).toContain('boy (Query B)');
+    expect(seriesNames).toContain('girl (Query B)');
+    // The metric is still dropped - only the query suffix is added back.
+    expect(seriesNames).not.toContain('sum__num, boy (Query A)');
+  });
+});