paint method
void
paint(
- Canvas canvas,
- Size size,
- WorldToScreen worldToScreen,
- ScreenToWorld screenToWorld,
- double scale,
override
Implementation
@override
void paint(
Canvas canvas,
Size size,
WorldToScreen worldToScreen,
ScreenToWorld screenToWorld,
double scale,
) {
if (points.isEmpty) return;
final screenPoints = points.map((p) => worldToScreen(p.x, p.y)).toList();
if (connectPoints && screenPoints.length > 1) {
final path = Path()..moveTo(screenPoints[0].dx, screenPoints[0].dy);
for (int i = 1; i < screenPoints.length; i++) {
path.lineTo(screenPoints[i].dx, screenPoints[i].dy);
}
canvas.drawPath(
path.shift(const Offset(0, 2)),
Paint()
..color = color.withOpacity(0.2)
..strokeWidth = lineWidth
..style = PaintingStyle.stroke
..strokeCap = lineCap
..strokeJoin = StrokeJoin.round
..maskFilter = const MaskFilter.blur(BlurStyle.normal, 2.0),
);
canvas.drawPath(
path,
Paint()
..color = color
..strokeWidth = lineWidth
..style = PaintingStyle.stroke
..strokeCap = lineCap
..strokeJoin = StrokeJoin.round,
);
}
if (showPoints) {
for (int i = 0; i < points.length; i++) {
final currentPoint = points[i];
final currentScreenPoint = screenPoints[i];
final currentRadius = currentPoint.radius ?? pointRadius;
final currentColor = currentPoint.color ?? color;
canvas.drawCircle(
currentScreenPoint,
currentRadius,
Paint()..color = currentColor,
);
canvas.drawCircle(
currentScreenPoint,
currentRadius,
Paint()
..color = Colors.white
..style = PaintingStyle.stroke
..strokeWidth = 1.2,
);
if (currentPoint.label != null) {
final textPainter = TextPainter(
text: TextSpan(
text: currentPoint.label,
style: TextStyle(
fontSize: 11,
color: currentColor,
fontWeight: FontWeight.w600,
),
),
textDirection: TextDirection.ltr,
)..layout();
textPainter.paint(canvas, currentScreenPoint + const Offset(8, -14));
}
}
}
}