fix(plugin-chart-echarts): exclude series limit metric from stacked total - #42755
fix(plugin-chart-echarts): exclude series limit metric from stacked total#42755gkhnelbstn wants to merge 1 commit into
Conversation
…otal The stacked "Show Total"/"Only Total" label on Timeseries charts summed every non x-axis column of each row, including a timeseries_limit_metric that is only added to the query for sorting/limiting. Such a metric is excluded from the rendered series and never appears in the legend, so legendState could not filter it out either, and the displayed total was inflated by its value. extractDataTotalValues now accepts the extraMetricLabels already computed for extractSeries and excludes them alongside the x-axis column.
Code Review Agent Run #333f74Actionable 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 |
| const extraMetricLabels = extractExtraMetrics(chartProps.rawFormData).map( | ||
| getMetricLabel, | ||
| ); |
There was a problem hiding this comment.
Suggestion: extraMetricLabels contains raw query metric labels, but rebasedData uses keys normalized by rebaseForecastDatum, including verboseMap display names and time-comparison suffixes. When the series-limit metric is verbose-mapped or time-compared, excludedKeys.has(curr) will not match its actual data key, so the supposedly hidden metric still contributes to totalStackedValues (and the same labels also fail to exclude it from extractSeries). Normalize the extra labels using the same key transformation as the data before passing them to both helpers. [api mismatch]
Severity Level: Major ⚠️
- ❌ Displayed stacked totals include hidden sort metrics.
- ❌ Hidden metrics can reappear in rendered series.
- ⚠️ Time-comparison totals use mismatched metric keys.(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts
**Line:** 307:309
**Comment:**
*Api Mismatch: `extraMetricLabels` contains raw query metric labels, but `rebasedData` uses keys normalized by `rebaseForecastDatum`, including `verboseMap` display names and time-comparison suffixes. When the series-limit metric is verbose-mapped or time-compared, `excludedKeys.has(curr)` will not match its actual data key, so the supposedly hidden metric still contributes to `totalStackedValues` (and the same labels also fail to exclude it from `extractSeries`). Normalize the extra labels using the same key transformation as the data before passing them to both helpers.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix|
The flagged issue is correct. The To resolve this, you should normalize the Would you like me to implement this normalization fix and check the rest of the PR comments for further issues? superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #42755 +/- ##
=======================================
Coverage 65.59% 65.59%
=======================================
Files 2819 2819
Lines 160166 160167 +1
Branches 36569 36570 +1
=======================================
+ Hits 105059 105061 +2
+ Misses 53059 53058 -1
Partials 2048 2048
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:
|
SUMMARY
On a stacked Timeseries Bar/Area chart with "Show Total"/"Only Total" enabled,
extractDataTotalValues(plugins/plugin-chart-echarts/src/utils/series.ts) summed every non x-axis column of each data row into the stacked total. This included thetimeseries_limit_metric("Sort by" metric), which is added to the query purely for sorting/limiting the x-axis and is correctly excluded from the rendered series/legend byextractSeriesviaextraMetricLabels. Since that column never appears as a legend entry,legendStatecould not exclude it either, so its value silently leaked into the displayed total.This threads
extraMetricLabels(already computed inTimeseries/transformProps.tsforextractSeries) intoextractDataTotalValuesand excludes those keys the same way the x-axis column is excluded.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A (data-only bug, see reproduction in linked issue)
TESTING INSTRUCTIONS
echarts_timeseries_barchart with 2 metricsA,B, Stacked, "Only Total" enabled.timeseries_limit_metric("Sort Series By") to a metric not among the displayed metrics, e.g.MIN(some_sequence_column).32 + 0 + 2 = 34) instead of the correct sum of only the displayed metrics (32 + 0 = 32).plugins/plugin-chart-echarts/test/utils/series.test.tscoveringextractDataTotalValueswith and withoutextraMetricLabels, combined withlegendStateand non-stacked mode.ADDITIONAL INFORMATION