UNPKG

1.26 kBJavaScriptView Raw
1"use strict";
2// 参考 d3-ticks nice 的实现
3// https://github.com/d3/d3-scale
4Object.defineProperty(exports, "__esModule", { value: true });
5exports.d3LinearNice = void 0;
6const ticks_1 = require("./ticks");
7const d3LinearNice = (min, max, count = 5) => {
8 const d = [min, max];
9 let i0 = 0;
10 let i1 = d.length - 1;
11 let start = d[i0];
12 let stop = d[i1];
13 let step;
14 if (stop < start) {
15 [start, stop] = [stop, start];
16 [i0, i1] = [i1, i0];
17 }
18 step = (0, ticks_1.tickIncrement)(start, stop, count);
19 if (step > 0) {
20 start = Math.floor(start / step) * step;
21 stop = Math.ceil(stop / step) * step;
22 step = (0, ticks_1.tickIncrement)(start, stop, count);
23 }
24 else if (step < 0) {
25 start = Math.ceil(start * step) / step;
26 stop = Math.floor(stop * step) / step;
27 step = (0, ticks_1.tickIncrement)(start, stop, count);
28 }
29 if (step > 0) {
30 d[i0] = Math.floor(start / step) * step;
31 d[i1] = Math.ceil(stop / step) * step;
32 }
33 else if (step < 0) {
34 d[i0] = Math.ceil(start * step) / step;
35 d[i1] = Math.floor(stop * step) / step;
36 }
37 return d;
38};
39exports.d3LinearNice = d3LinearNice;
40//# sourceMappingURL=d3-linear-nice.js.map
\No newline at end of file