Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pieChart drawing single section on iPhone, #1515 #1523

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ScatterSpot(
),
```
* **BUGFIX** (by @imaNNeo) Fix barChart tooltip for values below or above the 0 point, #1462
* **BUGFIX** (by @imaNNeo) Fix pieChart drawing single section on iPhone, #1515

## 0.65.0
* **FEATURE** (by @Dartek12) Added gradient to [FlLine](https://github.com/imaNNeo/fl_chart/blob/master/repo_files/documentations/base_chart.md#FlLine), #1197
Expand Down
27 changes: 21 additions & 6 deletions lib/src/chart/pie_chart/pie_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ class PieChartPainter extends BaseChartPainter<PieChartData> {
PieChartPainter() : super() {
_sectionPaint = Paint()..style = PaintingStyle.stroke;

_sectionSaveLayerPaint = Paint();

_sectionStrokePaint = Paint()..style = PaintingStyle.stroke;

_centerSpacePaint = Paint()..style = PaintingStyle.fill;
}

late Paint _sectionPaint;
late Paint _sectionSaveLayerPaint;
late Paint _sectionStrokePaint;
late Paint _centerSpacePaint;

Expand Down Expand Up @@ -100,13 +104,24 @@ class PieChartPainter extends BaseChartPainter<PieChartData> {
if (sectionDegree == 360) {
_sectionPaint
..color = section.color
..strokeWidth = section.radius
..style = PaintingStyle.stroke;
canvasWrapper.drawCircle(
center,
centerRadius + section.radius / 2,
_sectionPaint,
..style = PaintingStyle.fill;
final bounds = Rect.fromCircle(
center: center,
radius: centerRadius + section.radius,
);
canvasWrapper
..saveLayer(bounds, _sectionSaveLayerPaint)
..drawCircle(
center,
centerRadius + section.radius,
_sectionPaint..blendMode = BlendMode.srcOver,
)
..drawCircle(
center,
centerRadius,
_sectionPaint..blendMode = BlendMode.srcOut,
)
..restore();
if (section.borderSide.width != 0.0 &&
section.borderSide.color.opacity != 0.0) {
_sectionStrokePaint
Expand Down
28 changes: 22 additions & 6 deletions test/chart/pie_chart/pie_chart_painter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,12 @@ void main() {
test('test 1', () {
const viewSize = Size(200, 200);

const radius = 30.0;
const centerSpace = 10.0;
final sections = [
PieChartSectionData(
color: MockData.color2,
radius: 30,
radius: radius,
value: 10,
borderSide: const BorderSide(
color: MockData.color3,
Expand All @@ -141,17 +143,31 @@ void main() {
when(mockCanvasWrapper.canvas).thenReturn(MockCanvas());
barChartPainter.drawSections(mockCanvasWrapper, [360], 10, holder);

final result = verify(
final rect = Rect.fromCircle(
center: viewSize.center(Offset.zero),
radius: radius + centerSpace,
);
final results = verifyInOrder([
mockCanvasWrapper.saveLayer(
rect,
any,
),
mockCanvasWrapper.drawCircle(
const Offset(100, 100),
10 + 15,
10 + 30,
captureAny,
),
);
mockCanvasWrapper.drawCircle(
const Offset(100, 100),
10,
captureAny,
),
mockCanvasWrapper.restore(),
]);
final result = results[1];
expect(result.callCount, 1);
expect((result.captured.single as Paint).color, MockData.color2);
expect((result.captured.single as Paint).strokeWidth, 30);
expect((result.captured.single as Paint).style, PaintingStyle.stroke);
expect((result.captured.single as Paint).style, PaintingStyle.fill);

final result2 = verify(
mockCanvasWrapper.drawCircle(
Expand Down