1 | import { each, isNil } from '@antv/util';
|
2 |
|
3 |
|
4 | export function calBase(a: number, b: number) {
|
5 | const e = Math.E;
|
6 | let value;
|
7 | if (b >= 0) {
|
8 | value = Math.pow(e, Math.log(b) / a);
|
9 | } else {
|
10 | value = Math.pow(e, Math.log(-b) / a) * -1;
|
11 | }
|
12 | return value;
|
13 | }
|
14 |
|
15 | export function log(a: number, b: number) {
|
16 | if (a === 1) {
|
17 | return 1;
|
18 | }
|
19 | return Math.log(b) / Math.log(a);
|
20 | }
|
21 |
|
22 | export function getLogPositiveMin(values, base, max?: number) {
|
23 | if (isNil(max)) {
|
24 | max = Math.max.apply(null, values);
|
25 | }
|
26 | let positiveMin = max;
|
27 | each(values, (value) => {
|
28 | if (value > 0 && value < positiveMin) {
|
29 | positiveMin = value;
|
30 | }
|
31 | });
|
32 | if (positiveMin === max) {
|
33 | positiveMin = max / base;
|
34 | }
|
35 | if (positiveMin > 1) {
|
36 | positiveMin = 1;
|
37 | }
|
38 | return positiveMin;
|
39 | }
|