getPrecipitationRange method

(double, double) getPrecipitationRange()

Get precipitation range (min, max) for hourly data.

Implementation

(double min, double max) getPrecipitationRange() {
  final validPoints = data.where((p) => p.precipitation != null).toList();
  if (validPoints.isEmpty) return (0, 2); // Smaller default range

  var min = validPoints.first.precipitation!;
  var max = validPoints.first.precipitation!;

  for (final point in validPoints) {
    if (point.precipitation! < min) min = point.precipitation!;
    if (point.precipitation! > max) max = point.precipitation!;
  }

  // If all values are 0 or very close, set a small visible range.

  if (max < 0.1) {
    return (0, 1.0); // Show 0-1mm range for very small/zero precipitation
  }

  if (max - min < 0.1) {
    return (0, max + 0.5);
  }

  return (min, max);
}