drawGrid method

void drawGrid(
  1. Canvas canvas,
  2. Size size,
  3. double minX,
  4. double maxX,
  5. double minY,
  6. double maxY,
)

Draw grid lines (optimized with batched operations)

Implementation

void drawGrid(
  Canvas canvas,
  Size size,
  double minX,
  double maxX,
  double minY,
  double maxY,
) {
  if (!showGrid || !theme.showGrid) return;

  // Create paint once
  final paint = Paint()
    ..color = theme.gridColor.withValues(alpha: 0.5)
    ..strokeWidth = 0.5
    ..style = PaintingStyle.stroke;

  // Horizontal grid lines only (more professional)
  // Pre-calculate y positions and batch draw
  const horizontalLines = 5;
  final lineSpacing = size.height / horizontalLines;
  final path = Path();

  for (int i = 1; i < horizontalLines; i++) {
    final y = lineSpacing * i;
    path.moveTo(0, y);
    path.lineTo(size.width, y);
  }

  canvas.drawPath(path, paint);
}