Sort-only metric's time-comparison column is rendered as a visible series
- Dominant language
- Python
- Stars
- 74.8k
- Forks
- 18.3k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 685
Description
### Bug description
On a Timeseries chart that uses a sort-only metric (`timeseries_limit_metric`) **and** a time comparison, the sort metric's time-shifted column is rendered as a visible series, even though the sort metric itself is correctly hidden.
`extractExtraMetrics` gives the sort-only metric's label, and `transformProps` resolves it through `verboseMap` before passing it to `extractSeries`:
```js
const extraMetricLabels = extractExtraMetrics(chartProps.rawFormData)
.map(getMetricLabel)
.map(label => verboseMap[label] ?? label);
```
`sortAndFilterSeries` then drops those columns by exact match:
```js
.filter(key => !extraMetricLabels.includes(key));
```
Time comparison emits a derived column per query metric, and sort-only metrics are part of the query, so `sort_metric__1 year ago` also exists in the data. Two things stop it matching:
1. it is a different key from the base label, and
2. it keeps the **raw** metric label — `rebaseForecastDatum` only resolves the *forecast context* name through `verboseMap`, which never matches a `__` key
So the base column is filtered out and the derived one is not.
### How to reproduce
1. Create a Timeseries chart with two or more metrics
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. An extra series named `__1 year ago` appears in the chart and legend
Confirmed against `master` by inspecting the transformed series. With metrics `San Francisco` / `New York` / `Boston`, a sort-only metric `sort_metric` carrying `verbose_name` `Sort By Metric`, and offset `1 year ago`:
```
["sort_metric__1 year ago", "San Francisco", "New York", "Boston"]
```
`Sort By Metric` is correctly absent — its derived column is not.
### Expected results
A sort-only metric is not meant to be displayed, so neither is its time-shifted column. Only the displayed metrics and their derived series should be rendered.
### Actual results
An extra series for the sort metric's offset column is drawn and appears in the legend.
### Environment
- Superset version: `master`
- Browser: any
### Possible fix
The same exact keys already needed for the stacked total in #43068 would work here — build `__` from the configured `time_compare` offsets and include them in the list passed to `extractSeries`. Worth checking whether the sort metric should also be excluded from legend data and the tooltip, which read from the same series list.
Happy to open a PR. Noting for reviewers that this is independent of #43116, which only changes the input to `extractDataTotalValues` and leaves the `extractSeries` path untouched.
Contributor guide
Research direction
Start at transformProps and trace how extractExtraMetrics, sortAndFilterSeries, rebaseForecastDatum, and extractSeries handle time-comparison keys. Reproduce the issue with a sort-only metric and a 1 year ago offset, then verify that the sort metric and its derived offset column are absent from the rendered series, legend, and tooltip while displayed metrics remain.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- data-visualization, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100