1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.rPretty = void 0;
|
4 | const pretty_number_1 = require("../utils/pretty-number");
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | const rPretty = (min, max, m = 5) => {
|
15 | if (min === max) {
|
16 | return [min];
|
17 | }
|
18 | const n = m < 0 ? 0 : Math.round(m);
|
19 | if (n === 0)
|
20 | return [];
|
21 |
|
22 | const h = 1.5;
|
23 |
|
24 | const h5 = 0.5 + 1.5 * h;
|
25 |
|
26 | const d = max - min;
|
27 | const c = d / n;
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | const base = 10 ** Math.floor(Math.log10(c));
|
35 | let unit = base;
|
36 | if (2 * base - c < h * (c - unit)) {
|
37 | unit = 2 * base;
|
38 | if (5 * base - c < h5 * (c - unit)) {
|
39 | unit = 5 * base;
|
40 | if (10 * base - c < h * (c - unit)) {
|
41 | unit = 10 * base;
|
42 | }
|
43 | }
|
44 | }
|
45 | const nu = Math.ceil(max / unit);
|
46 | const ns = Math.floor(min / unit);
|
47 | const hi = Math.max(nu * unit, max);
|
48 | const lo = Math.min(ns * unit, min);
|
49 | const size = Math.floor((hi - lo) / unit) + 1;
|
50 | const ticks = new Array(size);
|
51 | for (let i = 0; i < size; i += 1) {
|
52 | ticks[i] = (0, pretty_number_1.prettyNumber)(lo + i * unit);
|
53 | }
|
54 | return ticks;
|
55 | };
|
56 | exports.rPretty = rPretty;
|
57 |
|
\ | No newline at end of file |