Skip to content

Conversation

@alettsy
Copy link
Contributor

@alettsy alettsy commented Jul 9, 2025

This pull request is to resolve #1952.

This should allow the user to set a property to make the first and last bars touch the sides of the container when they would otherwise overflow and get auto-spaced (in spaceEvenly()).

When shrinkWrapOnWidthOverflow is set to true, the first and last bars in the chart should be touching the sides instead of having space at the start/end.

The bars should still be spaced evenly.

Checklist

  • Unit tests pass
  • Manually tested
  • Formatted correctly
  • Doc comments

Screenshots:

With shrinkWrapOnWidthOverflow = true:
image

With shrinkWrapOnWidthOverflow = false:
image

When shrinkWrapOnWidthOverflow is set to true,
the first and last bars in the chart should be touching
the sides instead of having space at the start/end. The
bars should still be spaced evenly.

Fixes imaNNeo#1952
@imaNNeo imaNNeo requested a review from Copilot August 1, 2025 22:42
Copy link

Copilot AI left a comment

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 adds a new feature to allow bar charts to shrink wrap when content would overflow, making the first and last bars touch the container edges instead of having padding. This resolves issue #1952 by providing better space utilization when chart content exceeds available width.

Key changes:

  • Added shrinkWrapOnWidthOverflow boolean property to BarChartData
  • Modified spacing logic to eliminate edge padding when shrink wrap is enabled
  • Updated data class methods to support the new property

Reviewed Changes

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

File Description
lib/src/chart/bar_chart/bar_chart_data.dart Adds the new shrinkWrapOnWidthOverflow boolean property to the data model with proper constructor, copyWith, and lerp support
lib/src/extensions/bar_chart_data_extension.dart Implements the spacing logic to conditionally remove edge spacing when shrink wrap is enabled

@alettsy
Copy link
Contributor Author

alettsy commented Aug 7, 2025

I have pushed changes to address the Copilot code review 😊

@imaNNeo
Copy link
Owner

imaNNeo commented Aug 21, 2025

Does it matter what type of Alignment we're using for BarChartAlignment?
Or it just works in all the cases?

@alettsy
Copy link
Contributor Author

alettsy commented Aug 21, 2025

Hi 👋

I have added the property into props, as requested.

As for your question:

The shrinkWrapOnWidthOverflow: true only applies when the items would overflow the chart area, which causes the spaceEvenly function to get called.

This case happens when BarChartAlignment is start, end, or center and the total width of all items and spacing is greater than the chart width (tempX > viewWidth), or when it's set to spaceEvenly. When BarChartAlignment is spaceAround or spaceBetween, the spacing is calculated differently than the spaceEvenly function.

This can be seen in lib/src/extensions/bar_chart_data_extension.dart.

Please let me know if there are any other issues 😊

@codecov
Copy link

codecov bot commented Aug 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@be5b449). Learn more about missing BASE report.
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1953   +/-   ##
=======================================
  Coverage        ?   92.52%           
=======================================
  Files           ?       50           
  Lines           ?     3717           
  Branches        ?        0           
=======================================
  Hits            ?     3439           
  Misses          ?      278           
  Partials        ?        0           
Flag Coverage Δ
flutter 92.52% <100.00%> (?)

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

☔ View full report in Codecov by Sentry.
📢 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.

@alettsy
Copy link
Contributor Author

alettsy commented Aug 25, 2025

I added a test that should make for 100% coverage now 😊

@imaNNeo
Copy link
Owner

imaNNeo commented Aug 31, 2025

To be honest, I don't see this flag as the fix to the bug that happens when you define start, end or center with a spacing that leads to overflow.
I think when it happens, we should render them edge-to-edge (just like when shrinkWrapOnWidthOverflow is true in your implementation). So we simply say if the required with is more than the available with, we can set spaceBetween (under the hood).
Or maybe we can define an overflowFallbackAlignment that is spaceEvenly() by default and users can change it to spaceBetween().

What do you think?

@alettsy
Copy link
Contributor Author

alettsy commented Aug 31, 2025

Yeah, that makes sense if it just automatically applies if there would be overflow, rather than setting the property manually.

My thought was that some people might not want the bars to touch the edge so having a property to alter the behaviour when there is an overflow accounted for that.

But for ease-of-use, I think you're right it's better to let it get worked out behind the scenes when there is an overflow, and users can calculate the appropriate spacing based on their container size if they want to avoid the overflow behaviour.

I will update it 😊

@alettsy
Copy link
Contributor Author

alettsy commented Aug 31, 2025

Is that what you had in mind? 😊

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to get rid of the extra spacing at the chart's left/ride side?

2 participants