drawTextByPosition method

void drawTextByPosition(
  1. List<Offset> points,
  2. Canvas canvas,
  3. Size size
)

根据位置来绘制文字

Implementation

void drawTextByPosition(List<Offset> points, Canvas canvas,Size size) {

  if(radarType == RadarType.none){
    for (int i = 0; i < points.length; i++) {
      final offset = points[i];
      TextStyle textStyle = data[i].textStyle;
      double textSize = textStyle.fontSize??12;
      final labelBackgroundPaint = Paint()
        ..color = Colors.white
        ..style = PaintingStyle.fill;
      switch (i) {
        case 0:
          // labelBackgroundPaint.color = data[i].bgColor;
          layoutTitle(Offset(offset.dx, offset.dy-padding- cycleRadius - titleMargin-textSize),data[i],canvas);
          break;
        case 1:
          // labelBackgroundPaint.color = data[i].bgColor;
          layoutTitle(Offset(offset.dx+cycleRadius/2+padding, offset.dy-cycleRadius),data[i],canvas);
          break;
        case 2:
          // labelBackgroundPaint.color = data[i].bgColor;
          layoutTitle(Offset(offset.dx, offset.dy+padding),data[i],canvas);
          break;
        case 3:
          // labelBackgroundPaint.color = data[i].bgColor;
          layoutTitle(Offset(offset.dx, offset.dy+padding),data[i],canvas);
          break;
        case 4:
          // labelBackgroundPaint.color = data[i].bgColor;
          layoutTitle(Offset(offset.dx-cycleRadius/2 -padding, offset.dy-cycleRadius),data[i],canvas);
          break;
        default:
      }
    }
    return;
  }

  if(radarType == RadarType.normal){
    for (int i = 0; i < points.length; i++) {
      final offset = points[i];
      TextStyle textStyle = data[i].textStyle;
      double textSize = textStyle.fontSize??12;
      final labelBackgroundPaint = Paint()
        ..color = Colors.white
        ..style = PaintingStyle.fill;

      switch (i) {
        case 0:
          labelBackgroundPaint.color = data[i].bgColor;
          layoutTitle(Offset(offset.dx, offset.dy-padding- cycleRadius - titleMargin-textSize),data[i],canvas);
          canvas.drawCircle(Offset(offset.dx, offset.dy -padding - cycleRadius/2), cycleRadius, labelBackgroundPaint);
          layoutScore(Offset(offset.dx, offset.dy-padding - cycleRadius/2),data[i],canvas);
          break;
        case 1:
          labelBackgroundPaint.color = data[i].bgColor;
          layoutTitle(Offset(offset.dx+cycleRadius/2+padding, offset.dy-cycleRadius),data[i],canvas);
          canvas.drawCircle(Offset(offset.dx+cycleRadius/2+padding, offset.dy - cycleRadius/2+textSize+titleMargin), cycleRadius, labelBackgroundPaint);
          layoutScore(Offset(offset.dx+cycleRadius/2+padding, offset.dy - cycleRadius/2+textSize+titleMargin),data[i],canvas);
          break;
        case 2:
          labelBackgroundPaint.color = data[i].bgColor;
          layoutTitle(Offset(offset.dx, offset.dy+padding),data[i],canvas);
          canvas.drawCircle(Offset(offset.dx, offset.dy+padding + cycleRadius/2+titleMargin+textSize), cycleRadius, labelBackgroundPaint);
          layoutScore(Offset(offset.dx, offset.dy+padding +  cycleRadius/2+titleMargin+textSize),data[i],canvas);
          break;
        case 3:
          labelBackgroundPaint.color = data[i].bgColor;
          layoutTitle(Offset(offset.dx, offset.dy+padding),data[i],canvas);
          canvas.drawCircle(Offset(offset.dx, offset.dy+padding + cycleRadius/2+titleMargin+textSize), cycleRadius, labelBackgroundPaint);
          layoutScore(Offset(offset.dx, offset.dy+padding +  cycleRadius/2+titleMargin+textSize),data[i],canvas);
          break;
        case 4:
          labelBackgroundPaint.color = data[i].bgColor;
          layoutTitle(Offset(offset.dx-cycleRadius/2 -padding, offset.dy-cycleRadius),data[i],canvas);
          canvas.drawCircle(Offset(offset.dx-cycleRadius/2 - padding, offset.dy - cycleRadius/2+textSize+titleMargin), cycleRadius, labelBackgroundPaint);
          layoutScore(Offset(offset.dx-cycleRadius/2-padding, offset.dy - cycleRadius/2+textSize+titleMargin),data[i],canvas);
          break;
        default:
      }
    }
    return;
  }

  // RadarType.inner
  for (int i = 0; i < points.length; i++) {
    final offset = points[i];
    final labelBackgroundPaint = Paint()
      ..color = Colors.white
      ..style = PaintingStyle.fill;

    switch (i) {
      case 0:
        labelBackgroundPaint.color = data[i].bgColor;
        canvas.drawCircle(
            Offset(offset.dx, offset.dy - padding - cycleRadius / 2),
            cycleRadius,
            labelBackgroundPaint);
        layoutText(Offset(offset.dx, offset.dy - padding - cycleRadius / 2),
            data[i], canvas);
        break;
      case 1:
        labelBackgroundPaint.color = data[i].bgColor;
        canvas.drawCircle(Offset(offset.dx + padding+cycleRadius/2, offset.dy-cycleRadius/2), cycleRadius,
            labelBackgroundPaint);
        layoutText(Offset(offset.dx + padding+cycleRadius/2, offset.dy-cycleRadius/2), data[i], canvas);
        break;
      case 2:
        labelBackgroundPaint.color = data[i].bgColor;
        canvas.drawCircle(Offset(offset.dx + padding, offset.dy+cycleRadius/2+padding), cycleRadius,
            labelBackgroundPaint);
        layoutText(Offset(offset.dx + padding, offset.dy+cycleRadius/2+padding), data[i], canvas);
        break;
      case 3:
        labelBackgroundPaint.color = data[i].bgColor;
        canvas.drawCircle(Offset(offset.dx-padding, offset.dy+cycleRadius/2+padding), cycleRadius,
            labelBackgroundPaint);
        layoutText(Offset(offset.dx-padding, offset.dy+cycleRadius/2+padding), data[i], canvas);
        break;
      case 4:
        labelBackgroundPaint.color = data[i].bgColor;
        canvas.drawCircle(Offset(offset.dx - padding-cycleRadius/2, offset.dy-cycleRadius/2), cycleRadius,
            labelBackgroundPaint);
        layoutText(Offset(offset.dx - padding-cycleRadius/2, offset.dy-cycleRadius/2), data[i], canvas);
        break;
      default:
    }
  }
}