getBestInitialIntervalValue method

double getBestInitialIntervalValue(
  1. double min,
  2. double max,
  3. double interval, {
  4. double baseline = 0.0,
})

Finds the best initial interval value

If there is a zero point in the axis, we a value that passes through it. For example if we have -3 to +3, with interval 2. if we start from -3, we get something like this: -3, -1, +1, +3 But the most important point is zero in most cases. with this logic we get this: -2, 0, 2

Implementation

double getBestInitialIntervalValue(
  double min,
  double max,
  double interval, {
  double baseline = 0.0,
}) {
  final diff = baseline - min;
  final mod = diff % interval;
  if ((max - min).abs() <= mod) {
    return min;
  }
  if (mod == 0) {
    return min;
  }
  return min + mod;
}