drawSections method

  1. @visibleForTesting
void drawSections(
  1. CanvasWrapper canvasWrapper,
  2. List<double> sectionsAngle,
  3. double centerRadius,
  4. PaintHolder<PieChartData> holder,
)

Implementation

@visibleForTesting
void drawSections(
  CanvasWrapper canvasWrapper,
  List<double> sectionsAngle,
  double centerRadius,
  PaintHolder<PieChartData> holder,
) {
  final data = holder.data;
  final viewSize = canvasWrapper.size;

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

  var tempAngle = data.startDegreeOffset;

  for (var i = 0; i < data.sections.length; i++) {
    final section = data.sections[i];
    final sectionDegree = sectionsAngle[i];

    if (sectionDegree == 360) {
      _sectionPaint
        ..color = section.color
        ..strokeWidth = section.radius
        ..style = PaintingStyle.stroke;
      canvasWrapper.drawCircle(
        center,
        centerRadius + section.radius / 2,
        _sectionPaint,
      );
      if (section.borderSide.width != 0.0 &&
          section.borderSide.color.opacity != 0.0) {
        _sectionStrokePaint
          ..strokeWidth = section.borderSide.width
          ..color = section.borderSide.color;
        // Outer
        canvasWrapper
          ..drawCircle(
            center,
            centerRadius + section.radius - (section.borderSide.width / 2),
            _sectionStrokePaint,
          )

          // Inner
          ..drawCircle(
            center,
            centerRadius + (section.borderSide.width / 2),
            _sectionStrokePaint,
          );
      }
      return;
    }

    final sectionPath = generateSectionPath(
      section,
      data.sectionsSpace,
      tempAngle,
      sectionDegree,
      center,
      centerRadius,
    );

    drawSection(section, sectionPath, canvasWrapper);
    drawSectionStroke(section, sectionPath, canvasWrapper, viewSize);
    tempAngle += sectionDegree;
  }
}