feat: pie chart rounded corners#2024
Conversation
|
Is this functionality intended? There's a maximum limit for the radius in this case: CleanShot.2025-10-26.at.00.37.38.mp4 |
The cornerRadius value is internally clamped inside generateRoundedSectionPath(). Even if a large value is passed (e.g. 40000), it gets limited by:
This means the actual corner radius can’t exceed 30% of the section radius or 15% of the arc length, whichever is smaller. |
|
@Vizten18 Thank you so much for picking this up! I just tried out your branch, and it is working great up to a value of 15 for donut charts:
This is the code I used: PieChart(
PieChartData(
startDegreeOffset: -90,
sections: [
PieChartSectionData(
cornerRadius: 15,
titleStyle: titleStyle,
value: 70,
color: colorScheme.success,
title: '70%',
radius: 50,
),
PieChartSectionData(
cornerRadius: 15,
titleStyle: titleStyle,
value: 20,
color: colorScheme.error,
title: '20%',
radius: 50,
),
PieChartSectionData(
cornerRadius: 15,
titleStyle: titleStyle,
value: 10,
color: colorScheme.leave,
title: '10%',
radius: 50,
),
],
),
)Afterwards, it seems the corner radius is only applied to the corners facing inwards:
It also doesn't pick up any values higher than 40. |
|
There was some work on #2040 about this topic. I just closed that one to have only 1 PR for pie chart rounded corners. |
… all section sizes
|
@imaNNeo Fixed an issue where smaller pie chart sections appeared sharper than larger ones despite having the same Previously, the corner radius was artificially clamped to 15% of the arc length and 30% of the section thickness. This premature clamping prevented smaller sections from reaching the requested radius. By updating the clamping limits to |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2024 +/- ##
==========================================
+ Coverage 92.49% 92.61% +0.12%
==========================================
Files 50 50
Lines 3731 3873 +142
==========================================
+ Hits 3451 3587 +136
- Misses 280 286 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
imaNNeo
left a comment
There was a problem hiding this comment.
PR Review: Rounded Corners for Pie Chart (#2024)
This is a fantastic addition to the library. The geometric logic for rounding both inner and outer corners (especially for donut charts) is well-handled. The clamping logic is robust and ensures segments remain visually stable even when narrow.
Here are a few suggestions to further polish the implementation:
1. Optimization: Redundant Path Construction
In pie_chart_painter.dart, the generateSectionPath method currently performs redundant work when cornerRadius > 0. It builds a standard path first and then builds a rounded one from scratch.
Suggestion: Wrap the standard path logic in an else block to skip it when rounding is active.
2. Geometry: Consistent Section Spacing
The "sharp" path uses a subtraction method that preserves a constant linear gap (parallel lines) between sections. The rounded path currently uses a fixed angular offset, which creates a slight "V" shaped gap (narrower at the center, wider at the edge). While subtle, maintaining a constant linear width would ensure consistency across both modes.
3. Safety: Negative Radius Guard
In the PieChartSectionData constructor, consider clamping cornerRadius to prevent negative values:
cornerRadius = (cornerRadius ?? 0.0).clamp(0, double.infinity),4. Magic Numbers
In generateRoundedSectionPath, the 0.499 multiplier used for clamping is a clever way to avoid rendering artifacts from overlapping segments. Adding a quick comment or a private named constant like _kRadiusSafetyMargin would help future maintainers understand the choice of 0.499 vs 0.5.
Overall, this is a solid PR that addresses a major feature request with high-quality geometry logic. Great work!
|
@Vizten18 I'm playing around with Antigravity to see if it can help me to speed up my work here in fl_chart. Feel free to have a look to see if you can improve that. |
…pie chart sections
|
the last commit has the following changes:
|
|
Perfect! There are only two things before the merge:
|
All Pie Chart Tests passed with success |
|
Thanks for your quick response and collaboration! |
|
Thanks to you for this lovable package, was a plessure to contribute on this feat ^^ |
|
There are some parts that are not covered. That's why some parts are failed. Can you make sure everything is covered? |
|
@imaNNeo Lets try again |
|
Thanks for your contribution! |



fixes: #1175
Summary
Add the ability to apply rounded corners to individual pie chart sections using a simple
cornerRadiusparameter.Motivation
Currently, fl_chart pie charts only support sharp corners for sections. Many modern UI designs require rounded corners for a softer, more polished appearance. This feature would allow developers to create more visually appealing pie charts that match contemporary design trends.
Proposed Solution
Add a
cornerRadiusproperty toPieChartSectionDatathat allows developers to specify the radius for rounding the corners of individual pie chart sections.Expected API