drawCrossLine method

void drawCrossLine(
  1. Canvas canvas,
  2. Size size
)
override

画交叉线

Implementation

void drawCrossLine(Canvas canvas, Size size) {
  var index = calculateSelectedX(selectX);
  KLineEntity point = getItem(index);

  // 创建虚线画笔 - 竖线使用与横线相同的颜色
  Paint paintY = Paint()
    ..color = this.chartColors.hCrossColor // 使用与横线相同的颜色
    ..strokeWidth = this.chartStyle.hCrossWidth // 使用与横线相同的宽度
    ..isAntiAlias = true
    ..style = PaintingStyle.stroke
    ..strokeCap = StrokeCap.round;

  double x = getX(index);
  double y = getMainY(point.close);

  // k线图竖线 - 使用虚线
  _drawDashedLine(
    canvas,
    Offset(x, mTopPadding),
    Offset(x, size.height - mBottomPadding),
    paintY,
  );

  Paint paintX = Paint()
    ..color = this.chartColors.hCrossColor
    ..strokeWidth = this.chartStyle.hCrossWidth
    ..isAntiAlias = true
    ..style = PaintingStyle.stroke
    ..strokeCap = StrokeCap.round;

  // k线图横线 - 使用虚线
  _drawDashedLine(
    canvas,
    Offset(-mTranslateX, y),
    Offset(-mTranslateX + mWidth / scaleX, y),
    paintX,
  );

  if (scaleX >= 1) {
    canvas.drawOval(
        Rect.fromCenter(
            center: Offset(x, y), height: 2.0 * scaleX, width: 2.0),
        paintX);
  } else {
    canvas.drawOval(
        Rect.fromCenter(
            center: Offset(x, y), height: 2.0, width: 2.0 / scaleX),
        paintX);
  }
}