Skip to content

fix(plugin-chart-echarts): exclude extra metrics from stacked totals - #42855

Open
krishn1301 wants to merge 2 commits into
apache:masterfrom
krishn1301:fix-only-total-excludes-sort-metric
Open

fix(plugin-chart-echarts): exclude extra metrics from stacked totals#42855
krishn1301 wants to merge 2 commits into
apache:masterfrom
krishn1301:fix-only-total-excludes-sort-metric

Conversation

@krishn1301

Copy link
Copy Markdown

SUMMARY

Fixes #42701.

With Stacked Style: Stack and Only Total enabled, the total shown above each bar included the sort metric. In the reported case, metrics A = 32 and B = 0 with a timeseries_limit_metric of 2 displayed a total of 34 instead of 32.

extractDataTotalValues sums every numeric column in each row:

Object.keys(data).reduce((prev, curr) => { ... prev + data[curr] ... })

A sort metric is present in the query result but is never rendered as a series, so it silently inflated the total — and the thresholdValues derived from that total, which decides which labels are shown.

This threads the extra metric labels into extractDataTotalValues and skips those columns when accumulating. The labels were already being computed in transformProps.ts via extractExtraMetrics(...).map(getMetricLabel); that computation just happened after the extractDataTotalValues call, so it's moved above and passed in. The new option is optional, so other callers of extractDataTotalValues are unaffected.

TESTING INSTRUCTIONS

cd superset-frontend
npm run test -- plugins/plugin-chart-echarts/test/utils/series.test.ts

Four tests were added under extractDataTotalValues, using the exact numbers from the issue:

  • excludes extra metrics from the stacked total — A=32, B=0, Sort=2 gives [32] (fails without this change)
  • includes every metric when no extraMetricLabels are passed — the same row gives [34]
  • derives thresholdValues from the total excluding extra metrics (fails without this change)
  • respects legendState alongside the exclusion

Manually: build a Stacked Timeseries Bar chart with two metrics, set a Sort By metric that differs from both, enable Only Total, and confirm the total equals the sum of the visible segments.

ADDITIONAL INFORMATION

extractDataTotalValues summed every numeric column in each row, so a timeseries_limit_metric that is not rendered as a series still inflated the Only Total value. With metrics A=32, B=0 and a sort metric of 2, the total showed 34 instead of 32.

Threads extraMetricLabels into extractDataTotalValues and excludes those columns from both the total and the derived threshold.

Fixes apache#42701

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@dosubot dosubot Bot added viz:charts:echarts Related to Echarts viz:charts:timeseries Related to Timeseries labels Aug 6, 2026
@bito-code-review

bito-code-review Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #05c1eb

Actionable Suggestions - 0
Review Details
  • Files reviewed - 3 · Commit Range: 2b65713..2b65713
    • superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts
    • superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts
    • superset-frontend/plugins/plugin-chart-echarts/test/utils/series.test.ts
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@netlify

netlify Bot commented Aug 6, 2026

Copy link
Copy Markdown

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 88f649c
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a7611105df15500083eaaa4
😎 Deploy Preview https://deploy-preview-42855--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.

@sadpandajoe

Copy link
Copy Markdown
Member

@krishn1301 Glad to see your contribution to the project! Can you add before and after screenshots of your fix into the PR description?

@sadpandajoe
sadpandajoe requested review from eschutho and rusackas and a lite review from Copilot August 7, 2026 17:09
Comment on lines +414 to +416
if (extraMetricLabelsSet.has(curr)) {
return prev;
}

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.

Suggestion: The exclusion only compares the raw column key against extraMetricLabels, but extractDataTotalValues receives rebasedData, whose metric keys may be renamed through verboseMap or suffixed for time-comparison series. In those cases a hidden sort metric such as Sort__1 day ago or its verbose label is not matched and is still added to the stacked total and threshold, so the reported inflation persists for forecast/time-comparison charts. Normalize the extra labels to the same rendered key format, or match derived keys consistently with extractSeries. [api mismatch]

Severity Level: Major ⚠️
- ❌ Time-comparison stacked totals include hidden sort metrics.
- ❌ Verbose-mapped extra metrics inflate displayed totals.
- ⚠️ Incorrect totals affect threshold-based label visibility.

Fix in Cursor Fix in VSCode Claude

(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/utils/series.ts
**Line:** 414:416
**Comment:**
	*Api Mismatch: The exclusion only compares the raw column key against `extraMetricLabels`, but `extractDataTotalValues` receives `rebasedData`, whose metric keys may be renamed through `verboseMap` or suffixed for time-comparison series. In those cases a hidden sort metric such as `Sort__1 day ago` or its verbose label is not matched and is still added to the stacked total and threshold, so the reported inflation persists for forecast/time-comparison charts. Normalize the extra labels to the same rendered key format, or match derived keys consistently with `extractSeries`.

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
👍 | 👎

@bito-code-review

Copy link
Copy Markdown
Contributor

The flagged issue is correct. The current implementation only filters based on the raw metric key, which fails when the data has been transformed (e.g., via verboseMap or time-comparison suffixes). To resolve this, you should normalize the extraMetricLabels to match the rendered keys present in rebasedData before performing the exclusion check.

To implement this, you can update the extractDataTotalValues function to normalize the extra labels using the same logic applied to the series keys, or ensure the extraMetricLabels passed to the function already reflect the final rendered format used in the data records.

superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts

// Normalize extra labels to match the rendered keys in rebasedData
  const normalizedExtraLabels = extraMetricLabels.map(label => 
    // Apply the same transformation logic used for series keys here
    getRenderedKey(label) 
  );
  const extraMetricLabelsSet = new Set(normalizedExtraLabels);

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.

Pull request overview

This PR fixes an issue in the ECharts timeseries stacked “Only Total” label calculation where non-rendered “extra metrics” (e.g., timeseries_limit_metric used only for sorting/limiting) were incorrectly included in the stacked totals, inflating both displayed totals and the derived thresholdValues.

Changes:

  • Extend extractDataTotalValues to accept an optional extraMetricLabels list and exclude those columns from stacked total accumulation.
  • Compute extraMetricLabels earlier in transformProps.ts and pass them into extractDataTotalValues.
  • Add unit tests covering exclusion behavior, the default (backward-compatible) behavior when no extra metrics are passed, and interactions with legendState/thresholdValues.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
superset-frontend/plugins/plugin-chart-echarts/test/utils/series.test.ts Adds focused unit tests for extractDataTotalValues covering the reported regression and expected edge cases.
superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts Updates stacked-total computation to optionally exclude extra (non-rendered) metric columns.
superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts Moves extra-metric label derivation earlier and threads it into total/threshold computation.

@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.37%. Comparing base (79c2cd3) to head (88f649c).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #42855   +/-   ##
=======================================
  Coverage   66.37%   66.37%           
=======================================
  Files        2857     2857           
  Lines      161048   161052    +4     
  Branches    37046    37048    +2     
=======================================
+ Hits       106889   106893    +4     
  Misses      52143    52143           
  Partials     2016     2016           
Flag Coverage Δ
javascript 73.19% <100.00%> (+<0.01%) ⬆️

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.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Timeseries Bar: stacked 'Only Total' sum includes the series-limit/sort metric's value, not just the displayed metrics

3 participants