fix: Detect touches on downward (negative) BarChartRodStackItems#2103
Open
ultramcu wants to merge 1 commit into
Open
fix: Detect touches on downward (negative) BarChartRodStackItems#2103ultramcu wants to merge 1 commit into
ultramcu wants to merge 1 commit into
Conversation
BarChartPainter.handleTouch iterated rodStackItems and checked `dy <= fromPixel && dy >= toPixel` to decide which stack segment was touched. That inequality silently fails for downward (negative) stack items, where fromY > toY and therefore fromPixel < toPixel in screen space (Flutter Y grows downward). As a result, BarTouchResponse's touchedStackItem was always null and touchedStackItemIndex was always -1 for negative rod stacks, breaking tooltip and touch callbacks on common financial / loss-style bar charts. Compute the touch range with min/max so the check is orientation-agnostic and works for both upward and downward stacks. Upward behavior is unchanged (same min/max bounds, same inclusive range). Adds a regression test in the existing handleTouch() group: a single group with one downward rod (fromY: 0, toY: -10) and one stack item; a touch in the middle of the chart returns touchedStackItemIndex == 0 (was -1 before the fix).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
BarChartPainter.handleTouchiteratesrodStackItemsand checksdy <= fromPixel && dy >= toPixelto decide which stack segment was touched.That inequality silently fails for downward (negative) stack items, where
fromY > toYand thereforefromPixel < toPixelin screen space (Flutter Ygrows downward).
As a result,
BarTouchResponse.touchedStackItemwas alwaysnullandtouchedStackItemIndexwas always-1for negative rod stacks, which breakstooltips and
getTooltipItem/ touch callbacks on common financial /loss-style bar charts.
This PR makes the range check orientation-agnostic by computing
topPixel = min(fromPixel, toPixel)andbottomPixel = max(fromPixel, toPixel),then testing
dy >= topPixel && dy <= bottomPixel. Upward behaviour isunchanged (same bounds, same inclusive range); downward behaviour is now correct.
A regression test is added in the existing
handleTouch()group: a singlegroup with one downward rod (
fromY: 0,toY: -10) and one stack itemspanning the whole rod — a touch in the middle of the chart now returns
touchedStackItemIndex == 0; before the fix it returned-1(verifiedfail-before / pass-after locally).
Checklist
///. (Internal-loop fix; no public API surface change.)example. (Bug fix in existing behaviour; example app unchanged.)Breaking Change?
Related Issues
Closes #2104.