UNPKG

1.69 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.d3Log = void 0;
4const d3_ticks_1 = require("./d3-ticks");
5const utils_1 = require("../utils");
6const d3Log = (a, b, n, base = 10) => {
7 const shouldReflect = a < 0;
8 const pow = (0, utils_1.pows)(base, shouldReflect);
9 const log = (0, utils_1.logs)(base, shouldReflect);
10 const r = b < a;
11 const min = r ? b : a;
12 const max = r ? a : b;
13 let i = log(min);
14 let j = log(max);
15 let ticks = [];
16 // 如果 base 是整数
17 if (!(base % 1) && j - i < n) {
18 i = Math.floor(i);
19 j = Math.ceil(j);
20 if (shouldReflect) {
21 for (; i <= j; i += 1) {
22 const p = pow(i);
23 for (let k = base - 1; k >= 1; k -= 1) {
24 const t = p * k;
25 if (t > max)
26 break;
27 if (t >= min)
28 ticks.push(t);
29 }
30 }
31 }
32 else {
33 for (; i <= j; i += 1) {
34 const p = pow(i);
35 for (let k = 1; k < base; k += 1) {
36 const t = p * k;
37 if (t > max)
38 break;
39 if (t >= min)
40 ticks.push(t);
41 }
42 }
43 }
44 if (ticks.length * 2 < n)
45 ticks = (0, d3_ticks_1.d3Ticks)(min, max, n);
46 }
47 else {
48 const count = n === -1 ? j - i : Math.min(j - i, n);
49 ticks = (0, d3_ticks_1.d3Ticks)(i, j, count).map(pow);
50 }
51 return r ? ticks.reverse() : ticks;
52};
53exports.d3Log = d3Log;
54//# sourceMappingURL=d3-log.js.map
\No newline at end of file