tickIncrement function

int tickIncrement(
  1. int start,
  2. int stop,
  3. int count
)

Calculates tick increment for integer values.

Implementation

int tickIncrement(int start, int stop, int count) {
  final step = (stop - start) / count;
  final power = (math.log(step) / math.ln10).floor();
  final error = step / math.pow(10, power);

  int factor;
  if (error >= _e10) {
    factor = 10;
  } else if (error >= _e5) {
    factor = 5;
  } else if (error >= _e2) {
    factor = 2;
  } else {
    factor = 1;
  }

  if (power >= 0) {
    return (factor * math.pow(10, power)).toInt();
  } else {
    return -(math.pow(10, -power) / factor).toInt();
  }
}