UNPKG

1.19 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.tickStep = exports.tickIncrement = void 0;
4const e10 = Math.sqrt(50);
5const e5 = Math.sqrt(10);
6const e2 = Math.sqrt(2);
7function tickIncrement(start, stop, count) {
8 const step = (stop - start) / Math.max(0, count);
9 const power = Math.floor(Math.log(step) / Math.LN10);
10 const error = step / 10 ** power;
11 if (power >= 0) {
12 // eslint-disable-next-line no-nested-ternary
13 return (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * 10 ** power;
14 }
15 // eslint-disable-next-line no-nested-ternary
16 return -(10 ** -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
17}
18exports.tickIncrement = tickIncrement;
19function tickStep(start, stop, count) {
20 const step0 = Math.abs(stop - start) / Math.max(0, count);
21 let step1 = 10 ** Math.floor(Math.log(step0) / Math.LN10);
22 const error = step0 / step1;
23 if (error >= e10)
24 step1 *= 10;
25 else if (error >= e5)
26 step1 *= 5;
27 else if (error >= e2)
28 step1 *= 2;
29 return stop < start ? -step1 : step1;
30}
31exports.tickStep = tickStep;
32//# sourceMappingURL=ticks.js.map
\No newline at end of file