drawNowPrice method
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);
}
Color priceColor = value >= datas!.last.open
? this.chartColors.nowPriceUpColor
: this.chartColors.nowPriceDnColor;
nowPriceSelectorBorderPaint.color = priceColor;
nowPriceLinePaint.color = priceColor;
//first draw the horizontal line
canvas.drawDashLine(
Offset(0, y),
Offset(-mTranslateX + mWidth / scaleX, y),
nowPriceLinePaint,
);
//repaint the background and text
TextPainter tp = getTextPainter(
NumberUtil.formatFixed(value, fixedLength) ?? '',
priceColor,
);
double paddingX = 3, paddingY = 1.5;
double space = 5.0;
double offsetX;
switch (verticalTextAlignment) {
case VerticalTextAlignment.left:
// offsetX = paddingX;
offsetX = space;
break;
case VerticalTextAlignment.right:
offsetX = mWidth - tp.width - paddingX * 2 - space;
break;
}
double top = y - tp.height / 2;
RRect rect = RRect.fromLTRBR(
offsetX,
top - paddingY,
offsetX + tp.width + paddingX * 2,
top + tp.height + paddingY * 2,
Radius.circular(2.0),
);
canvas.drawRRect(
rect,
nowPriceSelectorPaint,
);
canvas.drawRRect(
rect,
nowPriceSelectorBorderPaint,
);
tp.paint(
canvas,
Offset(offsetX + paddingX, top),
);
}