drawNowPrice method

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

Implementation

@override
void drawNowPrice(Canvas canvas) {
  if (!showNowPrice || data == null) return;

  double value = data!.last.close;
  double y = getMainY(value);

  //视图展示区域边界值绘制
  if (y > getMainY(mMainLowMinValue)) y = getMainY(mMainLowMinValue);
  if (y < getMainY(mMainHighMaxValue)) y = getMainY(mMainHighMaxValue);

  nowPricePaint
    ..color = value >= data!.last.open ? style.colors.nowPriceUp : style.colors.nowPriceDown;
  //先画横线
  double startX = 0;
  final max = -mTranslateX + mWidth / scaleX;
  final space = style.nowPriceLineSpan + style.nowPriceLineLength;
  while (startX < max) {
    canvas.drawLine(Offset(startX, y), Offset(startX + style.nowPriceLineLength, y), nowPricePaint);
    startX += space;
  }

  //再画背景和文本
  TextPainter tp = getTextPainter(format(value), style.colors.nowPriceText);

  double offsetX;
  switch (style.main.yAxisAlignment) {
    case VerticalTextAlignment.left:
      offsetX = 0;
      break;

    case VerticalTextAlignment.right:
      offsetX = mWidth - tp.width;
      break;
  }

  double top = y - tp.height / 2;
  canvas.drawRect(Rect.fromLTRB(offsetX, top, offsetX + tp.width, top + tp.height), nowPricePaint);
  tp.paint(canvas, Offset(offsetX, top));
}