Skip to content

Commit

Permalink
Merge pull request #326 from imaNNeoFighT/hotfix/pie-chart-web
Browse files Browse the repository at this point in the history
Fixed problem of drawing pieChart on the web, (ignored `groupSpace`),…
  • Loading branch information
imaNNeo committed May 1, 2020
2 parents 4fdc28c + 1688754 commit 1dbdfef
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.9.4
* [Bugfix] Fixed showing PieChart on web (we've ignored `groupSpace` on web, because some BlendModes are [not working](https://github.com/flutter/flutter/issues/56071) yet)

## 0.9.3
* [BugFix] Fixed groupBarsPosition exception, #313.
* [Improvement] Shadows default off, #316.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Thank you all!

```yml
dependencies:
fl_chart: ^0.9.3
fl_chart: ^0.9.4
```


Expand Down
5 changes: 4 additions & 1 deletion lib/src/chart/pie_chart/pie_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:ui';
import 'package:equatable/equatable.dart';
import 'package:fl_chart/src/chart/base/base_chart/touch_input.dart';
import 'package:fl_chart/src/utils/lerp.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import '../base/base_chart/base_chart_data.dart';
Expand Down Expand Up @@ -57,7 +58,9 @@ class PieChartData extends BaseChartData with EquatableMixin {
}) : sections = sections ?? const [],
centerSpaceRadius = centerSpaceRadius ?? double.nan,
centerSpaceColor = centerSpaceColor ?? Colors.transparent,
sectionsSpace = sectionsSpace ?? 2,

/// we've disabled `groupSpace` on web, because some BlendModes are [not working](https://github.com/flutter/flutter/issues/56071) yet
sectionsSpace = kIsWeb ? 0 : sectionsSpace ?? 2,
startDegreeOffset = startDegreeOffset ?? 0,
pieTouchData = pieTouchData ?? PieTouchData(),
super(borderData: borderData, touchData: pieTouchData ?? PieTouchData());
Expand Down
9 changes: 7 additions & 2 deletions lib/src/chart/pie_chart/pie_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ class PieChartPainter extends BaseChartPainter<PieChartData> with TouchHandler<P
}

void _drawSections(Canvas canvas, Size viewSize, List<double> sectionsAngle) {
canvas.saveLayer(Rect.fromLTWH(0, 0, viewSize.width, viewSize.height), Paint());
if (data.sectionsSpace != 0) {
canvas.saveLayer(Rect.fromLTWH(0, 0, viewSize.width, viewSize.height), Paint());
}

final Offset center = Offset(viewSize.width / 2, viewSize.height / 2);

double tempAngle = data.startDegreeOffset;
Expand Down Expand Up @@ -99,7 +102,9 @@ class PieChartPainter extends BaseChartPainter<PieChartData> with TouchHandler<P
tempAngle += sweepAngle;
}

_removeSectionsSpace(canvas, viewSize);
if (data.sectionsSpace != 0) {
_removeSectionsSpace(canvas, viewSize);
}
}

/// firstly the sections draw close to eachOther without any space,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: fl_chart
description: A powerful Flutter chart library, currently supporting Line Chart, Bar Chart and Pie Chart.
version: 0.9.3
version: 0.9.4
homepage: https://github.com/imaNNeoFighT/fl_chart

environment:
Expand Down
2 changes: 1 addition & 1 deletion repo_files/documentations/pie_chart.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ PieChart(
|sections| list of [PieChartSectionData ](#PieChartSectionData) that is shown on the pie chart|[]|
|centerSpaceRadius| free space in the middle of the PieChart, set `double.nan` if you want it to be calculated according to the view size| double.nan|
|centerSpaceColor| colors the free space in the middle of the PieChart|Colors.transparent|
|sectionsSpace| space between the sections (margin of them)|2|
|sectionsSpace| space between the sections (margin of them), **Ignored on web**|2|
|startDegreeOffset| degree offset of the sections around the pie chart, should be between 0 and 360|0|
|pieTouchData| [PieTouchData](#PieTouchData) holds the touch interactivity details| PieTouchData()|
|borderData| shows a border around the chart, check the [FlBorderData](base_chart.md#FlBorderData)|FlBorderData()|
Expand Down

0 comments on commit 1dbdfef

Please sign in to comment.