niceYTicks static method

List<double> niceYTicks(
  1. double min,
  2. double max, {
  3. int tickCount = 5,
})

Generate evenly-spaced Y-axis ticks for a min..max range.

Returns exactly tickCount values including min and max, rounded to a "nice" step using log10-based magnitude (no string tricks).

Implementation

static List<double> niceYTicks(double min, double max, {int tickCount = 5}) {
  final count = _normalizeGeneratedCount(tickCount);
  if (count <= 0) return const [];
  if (!min.isFinite || !max.isFinite) return List<double>.filled(count, 0.0);

  final lower = math.min(min, max);
  final upper = math.max(min, max);
  if (count == 1) return <double>[(lower + upper) / 2];
  if (lower == upper) return List<double>.filled(count, lower);

  final step = _niceStep((upper - lower) / (count - 1));
  if (!step.isFinite || step <= 0) return List<double>.filled(count, lower);
  final niceMin = (lower / step).floor() * step;
  return List.generate(count, (i) => niceMin + i * step);
}