drawCrossLine method

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

draw cross lines

Implementation

// void drawCrossLine(Canvas canvas, Size size) {
//   var index = calculateSelectedX(selectX);
//   KLineEntity point = getItem(index);
//   Paint paintY = Paint()
//     ..color = chartColors.vCrossColor
//     ..strokeWidth = chartStyle.vCrossWidth
//     ..isAntiAlias = true;
//   double x = getX(index);
//   double y = getMainY(point.close);
//   // K-line chart vertical line
//   canvas.drawLine(Offset(x, mTopPadding),
//       Offset(x, size.height - mBottomPadding), paintY);
//
//   Paint paintX = Paint()
//     ..color = chartColors.hCrossColor
//     ..strokeWidth = chartStyle.hCrossWidth
//     ..isAntiAlias = true;
//   // K-line chart horizontal line
//   canvas.drawLine(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,
//     );
//   }
// }

@override
void drawCrossLine(Canvas canvas, Size size) {
  var index = calculateSelectedX(selectX);
  KLineEntity point = getItem(index);
  Paint paintY = Paint()
    ..color = chartColors.vCrossColor
    ..strokeWidth = chartStyle.vCrossWidth
    ..isAntiAlias = true;
  double x = getX(index);
  double y = getMainY(point.close);

  // Draw vertical dashed line
  drawDashedLine(canvas, Offset(x, mTopPadding),
      Offset(x, size.height - mBottomPadding), paintY);

  Paint paintX = Paint()
    ..color = chartColors.hCrossColor
    ..strokeWidth = chartStyle.hCrossWidth
    ..isAntiAlias = true;

  // Draw horizontal dashed line
  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,
    );
  }
}