ticks function

Iterable<num> ticks(
  1. num start,
  2. num stop,
  3. int count
)

Returns an Iterable of approximately count + 1 uniformly-spaced, nicely-rounded values between start and stop (inclusive). Each value is a power of ten multiplied by 1, 2 or 5.

Ticks are inclusive in the sense that they may include the specified start and stop values if (and only if) they are exact, nicely-rounded values consistent with the inferred step. More formally, each returned tick t satisfies start ≤ t and t ≤ stop.

Implementation

Iterable<num> ticks(num start, num stop, int count) {
  final bool isReverse = stop < start;

  if (isReverse) {
    final temp = start;
    start = stop;
    stop = temp;
  }

  final num step = tickIncrement(start, stop, count);

  // If step is 0 or infinite, can't compute ticks
  if (step == 0 || step.isInfinite) return <num>[];

  start = (start / step).floor();
  stop = (stop / step).ceil();
  final int len = (stop - start).ceil();
  final ticks = List<num>.filled(len, 0);
  for (int i = 0; i < len; i++) {
    ticks[i] = (start + i) * step;
  }

  return isReverse ? ticks.reversed : ticks;
}