drawNowPrice method
void
drawNowPrice(
- Canvas canvas
)
override
Implementation
@override
void drawNowPrice(Canvas canvas) {
if (!this.showNowPrice) {
return;
}
if (datas == null) {
return;
}
double value = datas!.last.close;
double y = getMainY(value);
//视图展示区域边界值绘制
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;
//先画横线
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;
}
//再画背景和文本
TextPainter tp = getTextPainter(
value.toStringAsFixed(fixedLength), this.chartColors.nowPriceTextColor);
double offsetX;
switch (verticalTextAlignment) {
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));
}