Skip to content

fix(mixed chart): respect truncate_metric setting for series names - #45555

Open
rusackas wants to merge 7 commits into
masterfrom
fix/mixed-chart-truncate-metric-adopted
Open

rusackas wants to merge 7 commits into
masterfrom
fix/mixed-chart-truncate-metric-adopted

Conversation

@rusackas

Copy link
Copy Markdown
Member

SUMMARY

Adopts #38451 from @MelikHajlawi, which fixes truncate_metric/truncate_metricB having no effect on the Mixed Timeseries chart's series names. With a groupby set, a grouped series always rendered as "<metric>, <dimension>" regardless of the Truncate Metric checkbox, unlike the single-query Timeseries chart.

Adds truncateMetric/truncateMetricB handling in MixedTimeseries/transformProps.ts: when the flag is on and there's a groupby, the series name drops the metric prefix and shows only the groupby/dimension value(s), reusing the same metric-vs-dimension split the existing "metric, dimension" branch already applies to the label-map tuple. This runs ahead of the shared displayLabelMap/displayLabelMapB population, so formatter lookups keyed by the truncated name still resolve correctly.

This PR also resolves everything raised across the original PR's review threads:

  • The query-identifier suffix ("(Query A)"/"(Query B)") is now preserved when truncating and showQueryIdentifiers is on, so Query A and Query B stay distinguishable when they share a groupby value (sadpandajoe/codeant, Aug 21).
  • displayLabelMap/displayLabelMapB population already covers the truncated name on current master (this was a real gap back when the original PR was opened, but master has since grown a shared population step that runs after either branch sets displayName).
  • The any[] test-assertion nit, the duplicate-debug-log and stray generated files from early revisions, and the "no groupby → blank name" case are all already clean/resolved in this rebuild.
  • One thread asked whether DEFAULT_FORM_DATA's truncateMetric/truncateMetricB should default to true to match the shared control's default. Deliberately left as false: the sibling renameOperator (which implements the same setting server-side for the single-query Timeseries chart) explicitly treats an omitted field as off (truncate_metric !== undefined && !!truncate_metric), not as the control's UI default. The control's default: true only seeds a brand-new chart's checkbox state in Explore; defaulting the transform layer to true would silently start truncating every existing saved Mixed Timeseries chart with a groupby the next time it renders. Flagging this explicitly in case there's a reason to revisit it, but matching the backend's own semantics seemed safer.
  • One thread flagged that inverted[entryName] || entryName (used to resolve Query B's label-map key) could theoretically collide if a groupby value happens to equal another column's verbose label. That's pre-existing shared code the untruncated "metric, dimension" branch already relies on for the exact same lookup, not something this change introduces, so it's out of scope here and worth its own follow-up if it's a real-world problem.

Closes #38451

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

See #38451 for the original before/after screenshots - this PR is a straight rebuild of that same fix (plus the thread fixes above) against current master, with no further UI changes.

TESTING INSTRUCTIONS

  1. Create a Mixed Timeseries chart with a groupby on both queries.
  2. Toggle "Truncate Metric" on for Query A and/or Query B and confirm the legend/tooltip series names drop the metric prefix for whichever query has it enabled.
  3. With truncation on, also enable "Show Query Identifiers" and confirm series still show (Query A)/(Query B) so overlapping groupby values from both queries stay distinguishable.
  4. npx jest --runInBand plugins/plugin-chart-echarts/test/MixedTimeseries/transformProps.test.ts — the new truncateMetric / truncateMetricB describe block covers all of the above.

ADDITIONAL INFORMATION

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 <melik.hajlawi@medtech.tn>
Co-Authored-By: Evan Rusackas <evan@preset.io>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟡  Medium Risk

  • The PR needs attention before merging.
  • With metric truncation enabled, multi-metric series sharing a groupby value receive the same name, so cross-filter lookups can use the wrong label-map entry.

Assessed commit: 4ba9d18877cb

@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.84%. Comparing base (2350348) to head (1961806).
⚠️ Report is 62 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #45555       +/-   ##
===========================================
- Coverage   84.63%   65.84%   -18.79%     
===========================================
  Files        3069     3070        +1     
  Lines      205446   202416     -3030     
  Branches    48306    47608      -698     
===========================================
- Hits       173879   133283    -40596     
- Misses      28277    66181    +37904     
+ Partials     3290     2952      -338     
Flag Coverage Δ
javascript 80.80% <100.00%> (-0.01%) ⬇️
postgres ?
unit ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

… series name

Co-Authored-By: Evan Rusackas <evan@preset.io>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@rusackas
rusackas requested review from sadpandajoe and a balanced review from Copilot October 21, 2026 17:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

6 open issues
What changed in this PR

Fixes Mixed Timeseries series naming to honor truncateMetric/truncateMetricB when groupby is set, aligning behavior with single-query Timeseries and preserving query identifier suffixes when enabled.

Changes:

  • Add truncateMetric/truncateMetricB form-data fields (with defaults) for Mixed Timeseries.
  • Update MixedTimeseries/transformProps.ts to drop metric prefixes from series names when truncation is enabled and groupby is present (optionally preserving (Query A/B)).
  • Add Jest coverage for truncation behavior (including multi-dimension groupby and query identifier suffix retention).
File Description
superset-frontend/​plugins/​plugin-chart-echarts/​src/​MixedTimeseries/​transformProps.ts Implements truncation-aware series naming for Query A/B when groupby is present.
superset-frontend/​plugins/​plugin-chart-echarts/​src/​MixedTimeseries/​types.ts Adds form-data fields + defaults for truncateMetric and truncateMetricB.
superset-frontend/​plugins/​plugin-chart-echarts/​test/​MixedTimeseries/​transformProps.test.ts Adds tests validating truncation behavior and identifier suffix handling.

Review effort: Lite

…mparison

Co-Authored-By: Evan Rusackas <evan@preset.io>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@rusackas
rusackas requested a review from sadpandajoe October 22, 2026 00:07
@netlify

netlify Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit b330673
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6ae2c34f75a3087691099590
😎 Deploy Preview https://deploy-preview-45555--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

rusackas and others added 2 commits October 22, 2026 18:42
Co-Authored-By: Evan Rusackas <evan@preset.io>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ames

Co-Authored-By: Evan Rusackas <evan@preset.io>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
expect(seriesNames).not.toContain('m1, boy (Query A)');
});

test('applies the metric count per query: one metric for A, two for B', () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the new cases enable truncation together with a time comparison, or with an empty groupby, so the !hasTimeComparison / !hasTimeComparisonB and groupby.length > 0 guards in transformProps.ts aren't exercised by any test. Swapping time_compare and time_compare_b in those two conditions, or dropping either guard, would still pass this suite, and a comparison series would then collapse into the same truncated name as the current one.

Could you add a case with truncateMetric: true, showQueryIdentifiers: true, and time_compare set only for Query A (then time_compare_b set only for Query B), asserting the compared query keeps its offset-based names while the other query still drops the metric prefix? A mirrored case with groupby: [] and truncation on, asserting the verbose metric name is unchanged, would cover the other guard.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added cases for time_compare on A only, time_compare_b on B only, and an empty groupby with truncation on. Swapping the flags or dropping either guard now fails.

…pty groupby

Co-Authored-By: Evan Rusackas <evan@preset.io>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants