drawXIntervalSegmentation static method

void drawXIntervalSegmentation(
  1. Canvas canvas,
  2. List<SectionBean> xSectionBeans,
  3. double startX,
  4. double endX,
  5. double startY,
  6. double endY,
)

Implementation

static void drawXIntervalSegmentation(
    Canvas canvas,
    List<SectionBean> xSectionBeans,
    double startX,
    double endX,
    double startY,
    double endY) {
  var _fixedWidth = endX - startX;
  for (var item in xSectionBeans) {
    var tempStartX = _fixedWidth * item.startRatio + startX;
    var tempWidth = _fixedWidth * item.widthRatio;
    var tempPath = Path()
      ..moveTo(tempStartX, endY)
      ..lineTo(tempStartX + tempWidth, endY)
      ..lineTo(tempStartX + tempWidth, startY)
      ..lineTo(tempStartX, startY)
      ..lineTo(tempStartX, endY)
      ..close();
    var tempPaint = Paint()
      ..isAntiAlias = true
      ..strokeWidth = item.borderWidth ?? 1
      ..color = item.fillColor ?? Colors.transparent
      ..style = PaintingStyle.fill;
    canvas.drawPath(tempPath, tempPaint);
    //边缘线
    var borderLinePaint = Paint()
      ..isAntiAlias = true
      ..strokeWidth = item.borderWidth ?? 1
      ..color = item.borderColor ?? Colors.transparent
      ..style = PaintingStyle.stroke;
    var borderLinePath1 = Path()
      ..moveTo(tempStartX, endY)
      ..lineTo(tempStartX, startY);
    var borderLinePath2 = Path()
      ..moveTo(tempStartX + tempWidth, endY)
      ..lineTo(tempStartX + tempWidth, startY);
    if (item.isBorderSolid) {
      canvas.drawPath(borderLinePath1, borderLinePaint);
      canvas.drawPath(borderLinePath2, borderLinePaint);
    } else {
      canvas.drawPath(
        dashPath(
          borderLinePath1,
          dashArray: CircularIntervalList<double>(<double>[5.0, 4.0]),
        ),
        borderLinePaint,
      );
      canvas.drawPath(
        dashPath(
          borderLinePath2,
          dashArray: CircularIntervalList<double>(<double>[5.0, 4.0]),
        ),
        borderLinePaint,
      );
    }
    if (item.textTitle != null) {
      //文字显示
      var tempText = TextPainter(
          textAlign: TextAlign.center,
          ellipsis: '.',
          maxLines: 1,
          text: TextSpan(
              text: item.textTitle!.title, style: item.textTitle!.titleStyle),
          textDirection: TextDirection.ltr)
        ..layout();
      //定义在图表上层显示
      tempText.paint(
          canvas,
          Offset(tempStartX + tempWidth / 2 - tempText.width / 2,
              endY - tempText.height - item.titleBottomSpace));
    }

    if (item.imgTitle != null) {
      //图片显示
      canvas.drawImageRect(
        item.imgTitle!.img,
        Rect.fromLTWH(0, 0, item.imgTitle!.img.width.toDouble(),
            item.imgTitle!.img.height.toDouble()),
        Rect.fromLTWH(
            tempStartX + tempWidth / 2 - item.imgTitle!.imgSize.width / 2,
            endY - item.imgTitle!.imgSize.height - item.titleBottomSpace,
            item.imgTitle!.imgSize.width,
            item.imgTitle!.imgSize.height),
        Paint(),
      );
    }
  }
}