drawNowPrice method

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

draw the current price

Implementation

@override
void drawNowPrice(Canvas canvas) {
  if (!this.showNowPrice) {
    return;
  }

  if (datas == null) {
    return;
  }

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

  //view display area boundary value drawing
  if (y > getMainY(mMainLowMinValue)) {
    y = getMainY(mMainLowMinValue);
  }

  if (y < getMainY(mMainHighMaxValue)) {
    y = getMainY(mMainHighMaxValue);
  }

  nowPricePaint
    ..color = value >= datas!.last.open
        ? this.chartColors.nowPriceUpColor
        : this.chartColors.nowPriceDnColor;
  //first draw the horizontal line
  double startX = 0;
  final max = -mTranslateX + mWidth / scaleX;
  final space =
      this.chartStyle.nowPriceLineSpan + this.chartStyle.nowPriceLineLength;
  while (startX < max) {
    canvas.drawLine(
        Offset(startX, y),
        Offset(startX + this.chartStyle.nowPriceLineLength, y),
        nowPricePaint);
    startX += space;
  }
  //repaint the background and text
  TextPainter tp = getTextPainter(
    value.toStringAsFixed(fixedLength),
    this.chartColors.nowPriceTextColor,
  );

  double offsetX;
  switch (verticalTextAlignment) {
    case VerticalTextAlignment.left:
      offsetX = mWidth - tp.width;
      break;
    case VerticalTextAlignment.right:
      offsetX = 0;
      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));
}