fix(stacker): correct stacking for mixed positive/negative values (#2073, #2152) - #2173
Conversation
… signs PR #2085 fixed stacked area with mixed signs (#2073) by accumulating every value into both End and NegativeEnd. That gave area charts an Excel-like continuous baseline but broke stacked column/row series (#2152): a positive bar above a previous negative value started at the negative end instead of 0. Column/row stacks need positives and negatives in separate streams (each grows from 0 in its own direction). Area/line stacks need a single running total to keep the baseline continuous when values cross zero. Stacker now exposes both: End/NegativeEnd are sign-segregated again, and a new CumulativeStart/CumulativeEnd track always accumulates regardless of sign. CoreLineSeries and CoreStepLineSeries read the cumulative track when stacked. Snapshot regressions added for #2073 and #2152. The previous StackedColumnsTests_Basic baseline was captured under the buggy behavior and has been regenerated. The CoreTests ShouldHandleMixedPositiveNegativeValues tests for stacked area / step area, which had been written to assert PR #2085's broken numbers, now assert the correct dual-track + cumulative semantics. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes stacking semantics for mixed positive/negative values by restoring sign-segregated stacking for bar/column/row series while adding a separate cumulative stacking track for stacked line/area series to keep an Excel-like continuous baseline.
Changes:
- Restore sign-segregated
Start/EndvsNegativeStart/NegativeEndstacking for bars/columns/rows and introduceCumulativeStart/CumulativeEndfor continuous stacked line/area baselines. - Update
CoreLineSeriesandCoreStepLineSeriesto use the cumulative stacking track when stacked. - Add/refresh core + snapshot regression tests and update snapshot baselines for issues #2073 and #2152.
Reviewed changes
Copilot reviewed 8 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/LiveChartsCore/Kernel/Stacker.cs | Implements cumulative stacking track while keeping positive/negative tracks sign-segregated. |
| src/LiveChartsCore/Kernel/StackedValue.cs | Adds CumulativeStart/CumulativeEnd to expose cumulative stacking offsets. |
| src/LiveChartsCore/CoreLineSeries.cs | Switches stacked line baseline offset to CumulativeStart. |
| src/LiveChartsCore/CoreStepLineSeries.cs | Switches stacked step-line baseline offset to CumulativeStart. |
| tests/CoreTests/SeriesTests/StackedAreaSeriesTest.cs | Rewrites mixed-sign stacking assertions to validate the new three-track semantics. |
| tests/CoreTests/SeriesTests/StackedStepAreaSeriesTest.cs | Same as above for stacked step-area. |
| tests/SnapshotTests/StackedAreaTests.cs | Adds snapshot regression for #2073 mixed-sign stacked area. |
| tests/SnapshotTests/StackedRowSeriesTests.cs | Adds snapshot regression for #2152 mixed-sign stacked rows. |
| tests/SnapshotTests/Snapshots/StackedAreaTests_Issue2073_MixedSigns.png | New snapshot baseline for #2073 regression. |
| tests/SnapshotTests/Snapshots/StackedRowSeriesTests_Issue2152_MixedSigns.png | New snapshot baseline for #2152 regression. |
| tests/SnapshotTests/Snapshots/StackedColumnsTests_Basic.png | Regenerated baseline to reflect corrected stacking behavior. |
Thanks for your contribution!Benchmark delta — ✅ 6 improvements, no regressionsShow detailsBase: master — Head: c8cdd0b (run)
Build summary for run #347. Packing ✅Download the NuGet packages for this build here (dev-347). Available for 30 days — you can either use them directly or wait for this PR to be merged to have them published to NuGet.org. Tests ✅Show detailsCode Coverage ➡️
|
Aligns CorePolarLineSeries with the cartesian line/step-line variants now that mixed-sign stacking has separate cumulative semantics. Polar line stacking with mixed signs was a pre-existing gap — the spline only ever read .Start and never sign-switched — but for consistency with the other line variants, use CumulativeStart so polar stacked lines get the same continuous baseline. Addresses Copilot review feedback on PR #2173. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…tacker-mixed-signs fix(stacker): correct stacking for mixed positive/negative values (Live-Charts#2073, Live-Charts#2152)
Summary
End/NegativeEndtracks inStackerso stacked column/row bars grow from 0 in their own direction (fixes StackedRowSeries display bug #2152, regression from Fix stack calculation for positive and negative values #2085).CumulativeStart/CumulativeEndtrack that always accumulates regardless of sign;CoreLineSeries/CoreStepLineSeriesuse it when stacked, giving stacked area / step-area the Excel-like continuous baseline that StackedAreaSeries will not display correctly with Negative value #2073 originally asked for.StackedColumnsTests_Basicbaseline (which had been captured under PR Fix stack calculation for positive and negative values #2085's buggy behavior), and rewrites theShouldHandleMixedPositiveNegativeValuescore tests to assert the correct semantics.Background
PR #2085 tried to fix #2073 by accumulating every value into both
EndandNegativeEnd. That gave area charts a continuous baseline but corrupted both tracks: column/row series above a series with a negative value started their positive bar from the negative end (e.g. -52.89) instead of 0 — the visible bug in #2152's docs sample.The two needs are genuinely different:
So
Stackernow keeps both: sign-segregatedEnd/NegativeEndfor columns and rows, plusCumulativeEndfor area/line.Test plan
dotnet test --project tests/CoreTests/ --framework net8.0— 453/453 pass, including the rewrittenShouldHandleMixedPositiveNegativeValuestests for stacked area and stacked step area.dotnet test --project tests/SnapshotTests/— 100/100 pass, including the newStackedAreaTests.Issue2073_MixedSignsandStackedRowSeriesTests.Issue2152_MixedSignsregressions.StackedColumnsTests_Basicbaseline regenerated (the previous baseline locked in PR Fix stack calculation for positive and negative values #2085's broken rendering at indices with mixed signs).🤖 Generated with Claude Code