drawTrendLines method

void drawTrendLines(
  1. Canvas canvas,
  2. Size size
)

Implementation

void drawTrendLines(Canvas canvas, Size size) {
  var index = calculateSelectedX(selectX);
  Paint paintY = Paint()
    ..color = Colors.orange
    ..strokeWidth = 1
    ..isAntiAlias = true;
  double x = getX(index);
  trendLineX = x;

  double y = selectY;
  // getMainY(point.close);

  // k线图竖线
  canvas.drawLine(Offset(x, mTopPadding),
      Offset(x, size.height - mBottomPadding), paintY);
  Paint paintX = Paint()
    ..color = Colors.orangeAccent
    ..strokeWidth = 1
    ..isAntiAlias = true;
  Paint paint = Paint()
    ..color = Colors.orange
    ..strokeWidth = 1.0
    ..style = PaintingStyle.stroke
    ..strokeCap = StrokeCap.round;
  canvas.drawLine(Offset(-mTranslateX, y),
      Offset(-mTranslateX + mWidth / scaleX, y), paintX);
  if (scaleX >= 1) {
    canvas.drawOval(
        Rect.fromCenter(
            center: Offset(x, y), height: 15.0 * scaleX, width: 15.0),
        paint);
  } else {
    canvas.drawOval(
        Rect.fromCenter(
            center: Offset(x, y), height: 10.0, width: 10.0 / scaleX),
        paint);
  }
  if (lines.length >= 1) {
    lines.forEach((element) {
      var y1 = -((element.p1.dy - 35) / element.scale) + element.maxHeight;
      var y2 = -((element.p2.dy - 35) / element.scale) + element.maxHeight;
      var a = (trendLineMax! - y1) * trendLineScale! + trendLineContentRec!;
      var b = (trendLineMax! - y2) * trendLineScale! + trendLineContentRec!;
      var p1 = Offset(element.p1.dx, a);
      var p2 = Offset(element.p2.dx, b);
      canvas.drawLine(
          p1,
          element.p2 == Offset(-1, -1) ? Offset(x, y) : p2,
          Paint()
            ..color = Colors.yellow
            ..strokeWidth = 2);
    });
  }
}