Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
IldySilva authored Oct 20, 2024
2 parents 21baf04 + d1e7e66 commit cbf3aa4
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions lib/src/chart/pie_chart/pie_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ class PieChartPainter extends BaseChartPainter<PieChartData> {
) {
final data = holder.data;
final sectionsAngle = calculateSectionsAngle(data.sections, data.sumValue);
final centerRadius = calculateCenterRadius(viewSize, holder);

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

Expand All @@ -448,33 +449,34 @@ class PieChartPainter extends BaseChartPainter<PieChartData> {
PieChartSectionData? foundSectionData;
var foundSectionDataPosition = -1;

/// Find the nearest section base on the touch spot
final relativeTouchAngle = (touchAngle - data.startDegreeOffset) % 360;
var tempAngle = 0.0;
var tempAngle = data.startDegreeOffset;
for (var i = 0; i < data.sections.length; i++) {
final section = data.sections[i];
var sectionAngle = sectionsAngle[i];
final sectionAngle = sectionsAngle[i];

tempAngle %= 360;
if (data.sections.length == 1) {
sectionAngle = 360;
} else {
sectionAngle %= 360;
if (sectionAngle == 360) {
final distance = math.sqrt(
math.pow(localPosition.dx - center.dx, 2) +
math.pow(localPosition.dy - center.dy, 2),
);
if (distance >= centerRadius &&
distance <= section.radius + centerRadius) {
foundSectionData = section;
foundSectionDataPosition = i;
}
break;
}

/// degree criteria
final space = data.sectionsSpace / 2;
final fromDegree = tempAngle + space;
final toDegree = sectionAngle + tempAngle - space;
final isInDegree =
relativeTouchAngle >= fromDegree && relativeTouchAngle <= toDegree;

/// radius criteria
final centerRadius = calculateCenterRadius(viewSize, holder);
final sectionRadius = centerRadius + section.radius;
final isInRadius = touchR > centerRadius && touchR <= sectionRadius;
final sectionPath = generateSectionPath(
section,
data.sectionsSpace,
tempAngle,
sectionAngle,
center,
centerRadius,
);

if (isInDegree && isInRadius) {
if (sectionPath.contains(localPosition)) {
foundSectionData = section;
foundSectionDataPosition = i;
break;
Expand Down

0 comments on commit cbf3aa4

Please sign in to comment.