1 | import { __extends } from "tslib";
|
2 | import { getLogPositiveMin, log } from '../util/math';
|
3 | import Continuous from './base';
|
4 |
|
5 |
|
6 |
|
7 | var Log = (function (_super) {
|
8 | __extends(Log, _super);
|
9 | function Log() {
|
10 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
11 | _this.type = 'log';
|
12 | return _this;
|
13 | }
|
14 | |
15 |
|
16 |
|
17 | Log.prototype.invert = function (value) {
|
18 | var base = this.base;
|
19 | var max = log(base, this.max);
|
20 | var rangeMin = this.rangeMin();
|
21 | var range = this.rangeMax() - rangeMin;
|
22 | var min;
|
23 | var positiveMin = this.positiveMin;
|
24 | if (positiveMin) {
|
25 | if (value === 0) {
|
26 | return 0;
|
27 | }
|
28 | min = log(base, positiveMin / base);
|
29 | var appendPercent = (1 / (max - min)) * range;
|
30 | if (value < appendPercent) {
|
31 |
|
32 | return (value / appendPercent) * positiveMin;
|
33 | }
|
34 | }
|
35 | else {
|
36 | min = log(base, this.min);
|
37 | }
|
38 | var percent = (value - rangeMin) / range;
|
39 | var tmp = percent * (max - min) + min;
|
40 | return Math.pow(base, tmp);
|
41 | };
|
42 | Log.prototype.initCfg = function () {
|
43 | this.tickMethod = 'log';
|
44 | this.base = 10;
|
45 | this.tickCount = 6;
|
46 | this.nice = true;
|
47 | };
|
48 |
|
49 | Log.prototype.setDomain = function () {
|
50 | _super.prototype.setDomain.call(this);
|
51 | var min = this.min;
|
52 | if (min < 0) {
|
53 | throw new Error('When you use log scale, the minimum value must be greater than zero!');
|
54 | }
|
55 | if (min === 0) {
|
56 | this.positiveMin = getLogPositiveMin(this.values, this.base, this.max);
|
57 | }
|
58 | };
|
59 |
|
60 | Log.prototype.getScalePercent = function (value) {
|
61 | var max = this.max;
|
62 | var min = this.min;
|
63 | if (max === min) {
|
64 | return 0;
|
65 | }
|
66 |
|
67 | if (value <= 0) {
|
68 | return 0;
|
69 | }
|
70 | var base = this.base;
|
71 | var positiveMin = this.positiveMin;
|
72 |
|
73 | if (positiveMin) {
|
74 | min = (positiveMin * 1) / base;
|
75 | }
|
76 | var percent;
|
77 |
|
78 | if (value < positiveMin) {
|
79 | percent = value / positiveMin / (log(base, max) - log(base, min));
|
80 | }
|
81 | else {
|
82 | percent = (log(base, value) - log(base, min)) / (log(base, max) - log(base, min));
|
83 | }
|
84 | return percent;
|
85 | };
|
86 | return Log;
|
87 | }(Continuous));
|
88 | export default Log;
|
89 |
|
\ | No newline at end of file |