draw method
void
draw()
override
Implementation
@override
void draw(Canvas canvas, Size size, double scaleX, double scrollX,
double Function(double) getX, double Function(double) getY) {
debugPrint(
'HorizontalLineTool.draw: yPosition=$yPosition, priceLevel=$priceLevel');
if (yPosition == null) {
debugPrint('HorizontalLineTool.draw: yPosition为null,跳过绘制');
return;
}
final paint = Paint()
..color = color
..strokeWidth = strokeWidth
..style = PaintingStyle.stroke;
// 绘制横跨整个图表的水平线
debugPrint('绘制水平线: y=$yPosition, 宽度=${size.width}');
canvas.drawLine(
Offset(0, yPosition!),
Offset(size.width, yPosition!),
paint,
);
// 绘制价格标签
if (priceLevel != null) {
final textPainter = TextPainter(
text: TextSpan(
text: priceLevel!.toStringAsFixed(2),
style: TextStyle(color: color, fontSize: 12),
),
textDirection: TextDirection.ltr,
);
textPainter.layout();
textPainter.paint(
canvas,
Offset(size.width - textPainter.width - 5,
yPosition! - textPainter.height / 2));
}
}