1 | import { calBase } from '../util/math';
|
2 | import Continuous from './base';
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | class Pow extends Continuous {
|
8 | public readonly type: string = 'pow';
|
9 | |
10 |
|
11 |
|
12 | public exponent: number;
|
13 |
|
14 | |
15 |
|
16 |
|
17 | public invert(value: number) {
|
18 | const percent = this.getInvertPercent(value);
|
19 | const exponent = this.exponent;
|
20 | const max = calBase(exponent, this.max);
|
21 | const min = calBase(exponent, this.min);
|
22 | const tmp = percent * (max - min) + min;
|
23 | const factor = tmp >= 0 ? 1 : -1;
|
24 | return Math.pow(tmp, exponent) * factor;
|
25 | }
|
26 |
|
27 | protected initCfg() {
|
28 | this.tickMethod = 'pow';
|
29 | this.exponent = 2;
|
30 | this.tickCount = 5;
|
31 | this.nice = true;
|
32 | }
|
33 |
|
34 |
|
35 | protected getScalePercent(value: number) {
|
36 | const max = this.max;
|
37 | const min = this.min;
|
38 | if (max === min) {
|
39 | return 0;
|
40 | }
|
41 | const exponent = this.exponent;
|
42 | const percent =
|
43 | (calBase(exponent, value) - calBase(exponent, min)) / (calBase(exponent, max) - calBase(exponent, min));
|
44 | return percent;
|
45 | }
|
46 | }
|
47 |
|
48 | export default Pow;
|