generateSectionPath method
Generates a path around a section
Implementation
@visibleForTesting
Path generateSectionPath(
PieChartSectionData section,
double sectionSpace,
double tempAngle,
double sectionDegree,
Offset center,
double centerRadius,
) {
final sectionRadiusRect = Rect.fromCircle(
center: center,
radius: centerRadius + section.radius,
);
final centerRadiusRect = Rect.fromCircle(
center: center,
radius: centerRadius,
);
final startRadians = Utils().radians(tempAngle);
final sweepRadians = Utils().radians(sectionDegree);
final endRadians = startRadians + sweepRadians;
final startLineDirection =
Offset(math.cos(startRadians), math.sin(startRadians));
final startLineFrom = center + startLineDirection * centerRadius;
final startLineTo = startLineFrom + startLineDirection * section.radius;
final startLine = Line(startLineFrom, startLineTo);
final endLineDirection = Offset(math.cos(endRadians), math.sin(endRadians));
final endLineFrom = center + endLineDirection * centerRadius;
final endLineTo = endLineFrom + endLineDirection * section.radius;
final endLine = Line(endLineFrom, endLineTo);
var sectionPath = Path()
..moveTo(startLine.from.dx, startLine.from.dy)
..lineTo(startLine.to.dx, startLine.to.dy)
..arcTo(sectionRadiusRect, startRadians, sweepRadians, false)
..lineTo(endLine.from.dx, endLine.from.dy)
..arcTo(centerRadiusRect, endRadians, -sweepRadians, false)
..moveTo(startLine.from.dx, startLine.from.dy)
..close();
/// Subtract section space from the sectionPath
if (sectionSpace != 0) {
final startLineSeparatorPath = createRectPathAroundLine(
Line(startLineFrom, startLineTo),
sectionSpace,
);
sectionPath = Path.combine(
PathOperation.difference,
sectionPath,
startLineSeparatorPath,
);
final endLineSeparatorPath =
createRectPathAroundLine(Line(endLineFrom, endLineTo), sectionSpace);
sectionPath = Path.combine(
PathOperation.difference,
sectionPath,
endLineSeparatorPath,
);
}
return sectionPath;
}