drawMaxAndMin method

  1. @override
void drawMaxAndMin(
  1. Canvas canvas
)
override

Implementation

@override
void drawMaxAndMin(Canvas canvas) {
  if (isLine) return;
  double lineSize = 20;
  double lineToTextOffset = 5;

  Paint linePaint = Paint()
    ..strokeWidth = 1
    ..color = style.colors.minColor;

  //绘制最大值和最小值
  double x = translateXtoX(getX(mMainMinIndex));
  double y = getMainY(mMainLowMinValue);
  if (x < mWidth / 2) {
    //画右边
    final tp = getTextPainter(format(mMainLowMinValue), style.colors.minColor);
    canvas.drawLine(Offset(x, y), Offset(x + lineSize, y), linePaint);
    tp.paint(canvas, Offset(x + lineSize + lineToTextOffset, y - tp.height / 2));
  } else {
    final tp = getTextPainter(format(mMainLowMinValue), style.colors.minColor);
    canvas.drawLine(Offset(x, y), Offset(x - lineSize, y), linePaint);
    tp.paint(canvas, Offset(x - tp.width - lineSize - lineToTextOffset, y - tp.height / 2));
  }
  x = translateXtoX(getX(mMainMaxIndex));
  y = getMainY(mMainHighMaxValue);
  if (x < mWidth / 2) {
    //画右边
    TextPainter tp = getTextPainter(format(mMainHighMaxValue), style.colors.maxColor);

    canvas.drawLine(Offset(x, y), Offset(x + lineSize, y), linePaint);

    tp.paint(canvas, Offset(x + lineSize + lineToTextOffset, y - tp.height / 2));
  } else {
    TextPainter tp = getTextPainter(format(mMainHighMaxValue), style.colors.maxColor);
    canvas.drawLine(Offset(x, y), Offset(x - lineSize, y), linePaint);
    tp.paint(canvas, Offset(x - tp.width - lineSize - lineToTextOffset, y - tp.height / 2));
  }
}