Stacked "Only Total" still includes the sort-only metric on time-comparison charts (follow-up to #42881)
- Dominant language
- Python
- Stars
- 74.8k
- Forks
- 18.3k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 685
Description
### Bug description
#42881 fixed the stacked "Only Total" label so it no longer includes a sort-only metric (`timeseries_limit_metric`). It handles the plain and verbose-named cases, but the exclusion is an exact-name match, so **time-comparison derived columns of that same sort-only metric are still summed into the total**.
On master, `extractDataTotalValues` in `superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts`:
```js
const excludedKeys = new Set([xAxisCol, ...(extraMetricLabels ?? [])]);
...
if (excludedKeys.has(curr)) {
return prev;
}
```
`excludedKeys` holds `SortMetric`, so a column named `SortMetric__1 year ago` does not match and is added to the stacked total.
That column is reachable on any time-comparison chart that also uses a sort-only metric:
1. `Timeseries/buildQuery.ts` adds the extra metric into the query — `metrics: [...(baseQueryObject.metrics || []), ...extra_metrics]`
2. `getMetricOffsetsMap` builds an offset key per query metric — `[metric, offset].join(TIME_COMPARISON_SEPARATOR)`, i.e. `SortMetric__1 year ago`
3. `timeComparePivotOperator` pivots both the base and offset keys into the result
4. `extractDataTotalValues` sees the offset column, doesn't match it against `excludedKeys`, and includes it
The same inflated total also feeds `thresholdValues`, so the percentage-threshold cutoff for hiding small labels is off by the same amount.
### How to reproduce
1. Create a Timeseries Bar chart with two metrics, Stacked, **Only Total** enabled
2. Set **Sort By** to a metric that is not among the displayed metrics
3. Enable a **Time Comparison** offset (e.g. `1 year ago`)
4. The total label above each bar exceeds the visible stack height
### Expected results
The total should count only the displayed stacked series, matching the bar height, as it now does without a time offset.
### Actual results
The total is inflated by the value of the sort-only metric's time-shifted column.
### Environment
- Superset version: `master` (as of #42881)
- Browser: any
### Possible fix
Match derived forms as well as the exact label, e.g. treating a key as excluded when it equals an extra metric label **or** begins with `__` (`TIME_COMPARISON_SEPARATOR`). Worth keeping the boundary tight so a distinct metric that merely shares a prefix — `SortTotal` vs `Sort` — is still counted.
Happy to open a PR with a fix and tests if that sounds right.
Contributor guide
Research direction
Start in superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts at extractDataTotalValues, then trace the cited flow through Timeseries/buildQuery.ts, getMetricOffsetsMap, and timeComparePivotOperator. Add regression coverage for a time-comparison sort-only metric and verify that the stacked total and threshold cutoff count only displayed series, including derived columns.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- data-visualization, frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100