Skip to content

Commit

Permalink
fix: RadarChart crashes if all values in RadarDataSet are equal
Browse files Browse the repository at this point in the history
If the max and min values in a RadarDataSet are equal, the `drawTicks` method in `radar_chart_painter.dart` will enter an infinite loop.

This is due to a for loop that fails to be incremented if the max and min values are equal, causing the loop to never meet its exit condition.

I have replaced the for loop with one that will always exit.

Resolves imaNNeo#882
  • Loading branch information
ateich committed Jun 30, 2022
1 parent 0212c73 commit 72322fb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## newVersion
* **BUGFIX** (by @ateich): Fix infinite loop in RadarChart when all values in RadarDataSet are equal, #882.
* **BUGFIX** (by @ateich): Fix uneven titles in RadarChart when using titlePositionPercentageOffset, #1074.

## 0.55.0
Expand Down
9 changes: 4 additions & 5 deletions lib/src/chart/radar_chart/radar_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,12 @@ class RadarChartPainter extends BaseChartPainter<RadarChartData> {
final dataSetMaxValue = data.maxEntry.value;
final dataSetMinValue = data.minEntry.value;
final tickSpace = (dataSetMaxValue - dataSetMinValue) / data.tickCount;

final ticks = <double>[];
double tickValue = dataSetMinValue;

for (var tick = dataSetMinValue;
tick <= dataSetMaxValue;
tick = tick + tickSpace) {
ticks.add(tick);
for (var i = 0; i <= data.tickCount; i++) {
ticks.add(tickValue);
tickValue += tickSpace;
}

final tickDistance = radius / (ticks.length);
Expand Down

0 comments on commit 72322fb

Please sign in to comment.