gridStep static method

double gridStep(
  1. double maxValue
)

A "nice" grid step for a max value, chosen on a log-magnitude basis so ticks land on 1/2/5 multiples. Mirrors the Compose calculateGridStep.

Implementation

static double gridStep(double maxValue) {
  if (!(maxValue > 0) || !maxValue.isFinite) return 1;
  final magnitude = (math.log(maxValue) / math.ln10).floorToDouble();
  final base = math.pow(10, magnitude).toDouble();
  if (maxValue / base > 5) return base * 2;
  if (maxValue / base > 2) return base;
  return base / 2;
}