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

Stop the chart from rotating when embedded in a scroll view. #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 6 additions & 5 deletions lib/src/chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,14 @@ class PieChartPainter extends CustomPainter {
} else {
final isGradientPresent = gradientList?.isNotEmpty ?? false;
final isNonGradientElementPresent = (_subParts.length - (gradientList?.length ?? 0)) > 0;
var subPartAngle = _prevAngle;

for (int i = 0; i < _subParts.length; i++) {
if (isGradientPresent) {
final endAngle = (((_totalAngle) / _total) * _subParts[i]);
final paint = Paint();

final normalizedPrevAngle = (_prevAngle - 0.15) % doublePi;
final normalizedPrevAngle = (subPartAngle - 0.15) % doublePi;
final normalizedEndAngle = (endAngle + 0.15) % doublePi;
final Gradient gradient = SweepGradient(
transform: GradientRotation(normalizedPrevAngle),
Expand All @@ -154,23 +155,23 @@ class PieChartPainter extends CustomPainter {
}
canvas.drawArc(
boundingSquare,
_prevAngle,
subPartAngle,
endAngle,
useCenter,
paint,
);
} else {
canvas.drawArc(
boundingSquare,
_prevAngle,
subPartAngle,
((_totalAngle / _total) * _subParts[i]),
useCenter,
_paintList[i],
);
}

final radius = showChartValuesOutside ? (side / 2) + 16 : side / 3;
final radians = _prevAngle + (((_totalAngle / _total) * _subParts[i]) / 2);
final radians = subPartAngle + (((_totalAngle / _total) * _subParts[i]) / 2);
final x = (radius) * math.cos(radians);
final y = (radius) * math.sin(radians);

Expand All @@ -188,7 +189,7 @@ class PieChartPainter extends CustomPainter {
_drawName(canvas, name, x, y, side);
}
}
_prevAngle = _prevAngle + (((_totalAngle) / _total) * _subParts[i]);
subPartAngle = subPartAngle + (((_totalAngle) / _total) * _subParts[i]);
}
}

Expand Down