drawSegment method
void
drawSegment()
Implementation
void drawSegment(
Canvas canvas,
FastChartData datum,
double startAngle,
double sweepAngle,
Paint paint,
Rect rect,
double radius,
double labelRadius,
) {
canvas.drawArc(
rect,
degreesToRadian(startAngle),
degreesToRadian(sweepAngle),
paint.style == PaintingStyle.fill,
paint,
);
if (showLabel && datum.value >= labelValueThreshold) {
// Draw the percentage text in the middle of the segment
final textPainter = TextPainter(
text: TextSpan(
text: formatPercentage(
value: datum.value,
maximumFractionDigits: 1,
minimumFractionDigits: 0,
),
style: const TextStyle(
fontWeight: kFastFontWeightLight,
fontSize: kFastFontSize10,
color: Colors.white,
),
),
textDirection: TextDirection.ltr,
)..layout();
final labelAngle = startAngle + sweepAngle / 2;
final labelX = radius + labelRadius * cos(degreesToRadian(labelAngle));
final labelY = radius + labelRadius * sin(degreesToRadian(labelAngle));
textPainter.paint(
canvas,
Offset(labelX - textPainter.width / 2, labelY - textPainter.height / 2),
);
}
}