ticks method
Like ScaleLinear.ticks
, but customized for a log scale.
final x = ScaleLog(
domain: [1, 100],
range: [0, 960],
interpolate: interpolateNumber
);
final T = x.ticks(); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
If the base
is an integer, the returned ticks are uniformly spaced
within each integer power of base; otherwise, one tick per power of base
is returned. The returned ticks are guaranteed to be within the extent of
the domain
. If the orders of magnitude in the domain is greater than
count, then at most one tick per power is returned. Otherwise, the tick
values are unfiltered, but note that you can use ScaleLog.tickFormat
to
filter the display of tick labels. If count is not specified, it defaults
to 10.
Implementation
List<num> ticks([num count = 10]) {
final d = domain;
var u = d[0];
var v = d[d.length - 1];
final r = v < u;
if (r) ([u, v] = [v, u]);
var i = _logs(u), j = _logs(v);
num k, t;
var z = <num>[];
if (!((base % 1) != 0) && j - i < count) {
i = i.floor();
j = j.ceil();
if (u > 0) {
for (; i <= j; ++i) {
for (k = 1; k < base; ++k) {
t = i < 0 ? k / _pows(-i) : k * _pows(i);
if (t < u) continue;
if (t > v) break;
z.add(t);
}
}
} else {
for (; i <= j; ++i) {
for (k = base - 1; k >= 1; --k) {
t = i > 0 ? k / _pows(-i) : k * _pows(i);
if (t < u) continue;
if (t > v) break;
z.add(t);
}
}
}
if (z.length * 2 < count) z = array.ticks(u, v, count);
} else {
z = array.ticks(i, j, min(j - i, count)).map(_pows).toList();
}
return r ? array.reverse(z) : z;
}