fix(plugin-chart-echarts): omit stacked value labels on zero-height segments - #42756
fix(plugin-chart-echarts): omit stacked value labels on zero-height segments#42756MannXo wants to merge 1 commit into
Conversation
…egments A stacked segment whose value is 0 or null has no height, so it begins and ends at the same coordinate as the top of the segment beneath it. With "Show Value" on and "Only Total" off, echarts draws its label at that shared coordinate, on top of the label belonging to the segment below. The result is two numbers rendered over each other as unreadable text. `percentage_threshold` does not filter these out, and it is not meant to. It defaults to 0, and `thresholdValues[dataIndex] || Number.MIN_SAFE_INTEGER` turns a 0 threshold into "no filtering" rather than "filter at zero" -- which is why negative values also keep their labels at the default. Changing that expression would alter threshold semantics and suppress legitimate negative labels, so the guard is separate: a segment with no height carries no label. Scoped to stacked series. Unstacked labels sit on the bar itself with nothing to collide with, and they return earlier in the formatter. Only-total labels render the stack total and are untouched. This mirrors the rich tooltip, which already omits zero observations from a stacked series in Timeseries/transformProps.ts. Fixes apache#42702
Code Review Agent Run #5e26f6Actionable 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #42756 +/- ##
==========================================
- Coverage 65.59% 65.59% -0.01%
==========================================
Files 2819 2819
Lines 160166 160168 +2
Branches 36569 36570 +1
==========================================
- Hits 105059 105055 -4
- Misses 53059 53065 +6
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
Fixes #42702.
On a stacked
echarts_timeseries_barwith "Show Value" on and "Only Total" off, a series whose value is0for a category still gets a value label. A zero-height stacked segment begins and ends at the same coordinate as the top of the segment beneath it, so echarts draws that label on top of the label belonging to the segment below, and the two numbers render over each other as unreadable text.This adds one guard: a stacked segment with no height carries no label.
One correction to the root cause in the issue. The issue reports that with the default
percentage_threshold: 0the condition becomesnumericValue >= 0. It does not.0is falsy, sothresholdValues[dataIndex] || Number.MIN_SAFE_INTEGERevaluates toNumber.MIN_SAFE_INTEGERand the condition isnumericValue >= Number.MIN_SAFE_INTEGER, which is true for everything. Observed against the label formatter:If the mechanism were
>= 0, that-5would have been dropped. So the||is doing its job: a0threshold means "no threshold filtering", and a real threshold already suppresses zeros. That makes this a label-collision bug rather than a threshold bug, and it is why the fix does not touch the threshold expression. Rewriting that comparison would change threshold semantics for every user and would suppress legitimate negative labels.A second defect on the same code path. A
nullvalue renders the literal string"null"as a chart label, with the production number formatter:A null segment has no height either, so it collides identically. The guard covers both under one rule rather than special-casing zero.
Prior art in this plugin.
Timeseries/transformProps.tsalready omits zero observations from the rich tooltip of a stacked series (if (value.observation === 0 && stack) return;). This applies the same judgement to the per-series value label.Scope: stacked series only. Unstacked labels sit on the bar itself with nothing to collide with, and they return earlier in the formatter. Only-total labels render the stack total and are unaffected. The
stack &&clause is deliberate for legibility even though the earlier!stackreturn makes it defensive rather than load-bearing, matching how the tooltip guard above spells out the same condition.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Stacked bar, two metrics, "Show Value" on, "Only Total" off, default percentage threshold, with the upper series at
0for two categories.The label coordinates from the rendered SVG, so the images and the numbers agree:
TESTING INSTRUCTIONS
Manual:
echarts_timeseries_barchart with two metrics, for exampleAandB.0and the one below it is not, for example{"category": "1-3g", "B": 32, "A": 0}.0label is drawn over the32label as doubled text. After it, only32is labelled.0; turning on "Only Total" still shows the stack total.Automated, in
plugins/plugin-chart-echarts/test/Timeseries/transformers.test.ts:Five cases cover zero and null suppressed when stacked, non-zero and negative kept, zero kept when not stacked,
percentage_thresholdstill filtering below-threshold values, and only-total labels unchanged.Gates run locally on Node 24.16.0, using the commands from
.github/workflows/superset-frontend.yml:Each new assertion was checked by reverting the behaviour it covers and confirming the intended test fails: removing the guard fails the zero-height case, and guarding zero without null fails it too. One further sabotage, removing the
stack &&clause, is not caught, because the!stackbranch returns before the guard is reached, so no test can distinguish it. Noting that rather than presenting the set as complete.ADDITIONAL INFORMATION