Repository navigation
fix(explore): stacked Timeseries Bar total excludes the sort-only metric - #42881
Conversation
On a stacked Timeseries Bar chart with "Only Total"/"Show Total" enabled, the displayed stacked total silently included the timeseries_limit_metric value when that sort/limit metric differed from the chart's displayed metrics. The metric is correctly excluded from the rendered series/legend by extractSeries via extraMetricLabels, but extractDataTotalValues summed every remaining numeric column except the x-axis column, so the sort metric's value still leaked into the total. extractDataTotalValues now accepts an optional extraMetricLabels list and excludes those columns the same way it already excludes the x-axis column. transformProps.ts computes extraMetricLabels once, above both call sites that need it, instead of after extractDataTotalValues had already run without it. Closes #42701
Code Review Agent Run #83afb7Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
|
The flagged issue is correct. The To resolve this, you should map the const extraMetricLabels = extractExtraMetrics(chartProps.rawFormData).map(
(metric) => verboseMap[getMetricLabel(metric)] || getMetricLabel(metric),
);This ensures the exclusion set uses the same labels as the rebased data rows. superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts |
…luding rebasedData's keys have already been through rebaseForecastDatum, which renames a key to its verboseMap entry when one is configured for that metric. extraMetricLabels was still the raw metric label, so a sort-only metric with a verbose_name set would silently fail to match the exclusion set in extractDataTotalValues (and in extractSeries, which has the same requirement and was already using this variable). Added a regression test in transformProps.test.ts covering a verbose-named sort-only metric end to end. Thanks to the Bito AI review on this PR for catching this.
|
Good catch — pushed a fix. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #42881 +/- ##
==========================================
+ Coverage 57.10% 66.36% +9.26%
==========================================
Files 2857 2857
Lines 161125 161047 -78
Branches 37060 37048 -12
==========================================
+ Hits 92014 106883 +14869
+ Misses 68259 52148 -16111
- Partials 852 2016 +1164
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Code Review Agent Run #5a5350Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
|
@vjymisal0 thanks for the PR! Since there is a visual component to your change, can you add before and after screenshots of your fix into the PR description? |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
Suppressed comments (1)
superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/transformProps.test.ts:758
- The test name references issue
#42881, but this PR (and the new unit test inseries.test.ts) is about#42701. Updating the reference avoids confusion when triaging failures or searching history.
test('should exclude a verbose-named sort-only metric from the stacked total (#42881)', () => {
Fixes the oxfmt-frontend pre-commit CI failure (destructuring assignment exceeded the configured printWidth).
|
Pushed 3d2b7bc — ran oxfmt on series.ts to fix the oxfmt-frontend pre-commit CI failure (a destructuring assignment exceeded the configured printWidth). No logic change. |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Code Review Agent Run #f4bdf3Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
rusackas
left a comment
There was a problem hiding this comment.
Thanks for chasing down the verboseMap edge case too, that's exactly the kind of thing that would've bitten someone later. Tests look solid (both the unit-level exclusion logic and a real end-to-end verboseMap repro) and CI's green. LGTM, merging!
apache#42881 excluded sort-only metrics from the "Only Total" label by exact name match. Time comparison post-processing emits a derived column per query metric named `<label>__<offset>`, and sort-only metrics are part of the query, so `Sort__1 year ago` still slipped into the total on time-comparison charts. The same inflated total feeds thresholdValues, so the percentage-threshold cutoff was off by the same amount. Match keys beginning with `<label>` + TIME_COMPARISON_SEPARATOR as well as the exact label. Keying on the separator keeps a distinct metric that merely shares a prefix (`SortTotal` vs `Sort`) counted in the total. Fixes apache#43068 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
apache#42881 excluded sort-only metrics from the "Only Total" label by exact name match. Time comparison post-processing emits a derived column per query metric named `<label>__<offset>`, and sort-only metrics are part of the query, so `Sort__1 year ago` still slipped into the total on time-comparison charts. The same inflated total feeds thresholdValues, so the percentage-threshold cutoff was off by the same amount. Match keys beginning with `<label>` + TIME_COMPARISON_SEPARATOR as well as the exact label. Keying on the separator keeps a distinct metric that merely shares a prefix (`SortTotal` vs `Sort`) counted in the total. Fixes apache#43068 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
SUMMARY
On a stacked Timeseries Bar chart (
echarts_timeseries_bar) with "Show Total"/"Only Total" enabled, the displayed stacked total was silently inflated when the chart also used atimeseries_limit_metric(the "Sort by" metric used to order/limit the x-axis) that isn't one of the chart's displayed metrics.extraMetricLabels— which correctly excludes series-limit/sort-only metrics when building the actual rendered series viaextractSeries— was computed inTimeseries/transformProps.tsafterextractDataTotalValuesran, and was never passed into it.extractDataTotalValuessummed every remaining numeric key in each row except the x-axis column, so the sort-only metric's value leaked into the total even though it never appeared in the legend.Fix:
extractDataTotalValues(utils/series.ts) now accepts an optionalextraMetricLabelslist and excludes those columns the same way it already excludes the x-axis column.transformProps.tsnow computesextraMetricLabelsonce, above both call sites that need it (it was already being computed below, forextractSeries), instead of afterextractDataTotalValueshad already run without it.This is easy to hit in practice:
timeseries_limit_metricis the standard way to control x-axis category ordering when the natural order isn't alphabetical (e.g. binned/bucketed labels like1-3d,4-6d), which is precisely the situation where the sort metric is likely to differ from the displayed metrics.Closes #42701
TESTING INSTRUCTIONS
Added two unit tests to
test/utils/series.test.ts:extractDataTotalValues excludes extraMetricLabels from the stacked total (#42701)— reproduces the bug on the unfixed path (verifies the pre-fix behavior with a comment) and asserts the fixed behavior withextraMetricLabelspassed.extractDataTotalValues still respects legendState alongside extraMetricLabels— confirms the existing legend-toggle exclusion still works together with the new one.Ran locally:
All pass (102 + 112 tests, oxlint clean).
tsc --noEmiton the package reports pre-existing errors from unbuilt monorepo package type declarations and other unrelated files/lines (confirmed identical patterns exist elsewhere in the same untouched file); none are on the lines this PR changes.Manual repro steps are in the linked issue (stacked bar chart, 2+ metrics,
timeseries_limit_metricset to a non-displayed metric, "Only Total" enabled).ADDITIONAL INFORMATION