Skip to content

Commit f0180a8

Browse files
committed
simpler exact ticks
1 parent 9f745d0 commit f0180a8

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

src/log.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,21 @@ function transformExpn(x) {
2020
return -Math.exp(-x);
2121
}
2222

23-
function pow10(x, k) {
24-
return isFinite(x) ? +(k + "e" + x) : x < 0 ? 0 : x;
25-
}
26-
27-
function exp(x, k) {
28-
return Math.exp(x) * k;
23+
function pow10(x) {
24+
return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
2925
}
3026

3127
function powp(base) {
3228
return base === 10 ? pow10
33-
: base === Math.E ? exp
34-
: (x, k) => Math.pow(base, x) * k;
29+
: base === Math.E ? Math.exp
30+
: x => Math.pow(base, x);
3531
}
3632

3733
function logp(base) {
3834
return base === Math.E ? Math.log
3935
: base === 10 && Math.log10
4036
|| base === 2 && Math.log2
41-
|| (base = Math.log(base), (x) => Math.log(x) / base);
37+
|| (base = Math.log(base), x => Math.log(x) / base);
4238
}
4339

4440
function reflect(f) {
@@ -90,24 +86,23 @@ export function loggish(transform) {
9086
i = Math.floor(i), j = Math.ceil(j);
9187
if (u > 0) for (; i <= j; ++i) {
9288
for (k = 1; k < base; ++k) {
93-
t = pows(i, k);
89+
t = i < 0 ? k / pows(-i) : k * pows(i);
9490
if (t < u) continue;
9591
if (t > v) break;
9692
z.push(t);
9793
}
9894
} else for (; i <= j; ++i) {
9995
for (k = base - 1; k >= 1; --k) {
100-
t = pows(i, k);
96+
t = i > 0 ? k / pows(-i) : k * pows(i);
10197
if (t < u) continue;
10298
if (t > v) break;
10399
z.push(t);
104100
}
105101
}
106102
if (z.length * 2 < n) z = ticks(u, v, n);
107103
} else {
108-
z = ticks(i, j, Math.min(j - i, n)).map(i => pows(i, 1));
104+
z = ticks(i, j, Math.min(j - i, n)).map(pows);
109105
}
110-
111106
return r ? z.reverse() : z;
112107
};
113108

@@ -121,16 +116,16 @@ export function loggish(transform) {
121116
if (count === Infinity) return specifier;
122117
const k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
123118
return d => {
124-
let i = d / pows(Math.round(logs(d)), 1);
119+
let i = d / pows(Math.round(logs(d)));
125120
if (i * base < base - 0.5) i *= base;
126121
return i <= k ? specifier(d) : "";
127122
};
128123
};
129124

130125
scale.nice = () => {
131126
return domain(nice(domain(), {
132-
floor: x => pows(Math.floor(logs(x)), 1),
133-
ceil: x => pows(Math.ceil(logs(x)), 1)
127+
floor: x => pows(Math.floor(logs(x))),
128+
ceil: x => pows(Math.ceil(logs(x)))
134129
}));
135130
};
136131

0 commit comments

Comments
 (0)