fl_chart icon indicating copy to clipboard operation
fl_chart copied to clipboard

fix: wrong bar chart color with small value

Open artshooter opened this issue 2 months ago • 3 comments

Fixed incorrect bar chart color display when bar data values are small with large border radius set.

Fixes #1757

Root Cause

  1. The bar's main body (background) has a default background color
  2. Since the bar body's height cannot be lower than the border radius, the rendered bar body may be taller than the actual rendered height of the bar stack items (rodStackItems)
  3. The rendering logic draws the bar body background first, then overlays the bar stack items. When the stack items' height is insufficient to cover the entire bar body, the default background color becomes visible

Solution

When the actual height of the bar stack is smaller than the minimum height required for the corner radius, a scale factor is introduced to proportionally expand the rendered height of the bar stack items. This ensures they fully cover the bar body's height while maintaining the proportional relationships among stack items.

Changes

  • Modified drawBars method in lib/src/chart/bar_chart/bar_chart_painter.dart
  • Added scale factor calculation logic, applied only when necessary
  • Added unit tests to verify the fix

Testing

  • ✅ Added unit test covering small values with large border radius scenario
  • ✅ Verified scaled stack items have correct heights and proportions
  • ✅ All existing tests pass

artshooter avatar Oct 16 '25 15:10 artshooter

LGTM!

imaNNeo avatar Oct 25 '25 22:10 imaNNeo

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 92.51%. Comparing base (32e75f5) to head (39422af).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2018      +/-   ##
==========================================
+ Coverage   92.49%   92.51%   +0.01%     
==========================================
  Files          50       50              
  Lines        3731     3740       +9     
==========================================
+ Hits         3451     3460       +9     
  Misses        280      280              
Flag Coverage Δ
flutter 92.51% <100.00%> (+0.01%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Oct 25 '25 22:10 codecov[bot]

There's a codestyle issue, please fix that.

imaNNeo avatar Oct 26 '25 19:10 imaNNeo