1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var util_1 = require("@antv/util");
|
5 | var time_1 = require("../util/time");
|
6 | var linear_1 = require("./linear");
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | var Time = (function (_super) {
|
12 | tslib_1.__extends(Time, _super);
|
13 | function Time() {
|
14 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
15 | _this.type = 'time';
|
16 | return _this;
|
17 | }
|
18 | |
19 |
|
20 |
|
21 | Time.prototype.getText = function (value, index) {
|
22 | var numberValue = this.translate(value);
|
23 | var formatter = this.formatter;
|
24 | return formatter ? formatter(numberValue, index) : time_1.timeFormat(numberValue, this.mask);
|
25 | };
|
26 | |
27 |
|
28 |
|
29 | Time.prototype.scale = function (value) {
|
30 | var v = value;
|
31 | if (util_1.isString(v) || util_1.isDate(v)) {
|
32 | v = this.translate(v);
|
33 | }
|
34 | return _super.prototype.scale.call(this, v);
|
35 | };
|
36 | |
37 |
|
38 |
|
39 |
|
40 | Time.prototype.translate = function (v) {
|
41 | return time_1.toTimeStamp(v);
|
42 | };
|
43 | Time.prototype.initCfg = function () {
|
44 | this.tickMethod = 'time-pretty';
|
45 | this.mask = 'YYYY-MM-DD';
|
46 | this.tickCount = 7;
|
47 | this.nice = false;
|
48 | };
|
49 | Time.prototype.setDomain = function () {
|
50 | var values = this.values;
|
51 |
|
52 | var minConfig = this.getConfig('min');
|
53 | var maxConfig = this.getConfig('max');
|
54 |
|
55 | if (!util_1.isNil(minConfig) || !util_1.isNumber(minConfig)) {
|
56 | this.min = this.translate(this.min);
|
57 | }
|
58 | if (!util_1.isNil(maxConfig) || !util_1.isNumber(maxConfig)) {
|
59 | this.max = this.translate(this.max);
|
60 | }
|
61 |
|
62 | if (values && values.length) {
|
63 |
|
64 | var timeStamps_1 = [];
|
65 | var min_1 = Infinity;
|
66 | var secondMin_1 = min_1;
|
67 | var max_1 = 0;
|
68 |
|
69 | util_1.each(values, function (v) {
|
70 | var timeStamp = time_1.toTimeStamp(v);
|
71 | if (isNaN(timeStamp)) {
|
72 | throw new TypeError("Invalid Time: " + v + " in time scale!");
|
73 | }
|
74 | if (min_1 > timeStamp) {
|
75 | secondMin_1 = min_1;
|
76 | min_1 = timeStamp;
|
77 | }
|
78 | else if (secondMin_1 > timeStamp) {
|
79 | secondMin_1 = timeStamp;
|
80 | }
|
81 | if (max_1 < timeStamp) {
|
82 | max_1 = timeStamp;
|
83 | }
|
84 | timeStamps_1.push(timeStamp);
|
85 | });
|
86 |
|
87 | if (values.length > 1) {
|
88 | this.minTickInterval = secondMin_1 - min_1;
|
89 | }
|
90 | if (util_1.isNil(minConfig)) {
|
91 | this.min = min_1;
|
92 | }
|
93 | if (util_1.isNil(maxConfig)) {
|
94 | this.max = max_1;
|
95 | }
|
96 | }
|
97 | };
|
98 | return Time;
|
99 | }(linear_1.default));
|
100 | exports.default = Time;
|
101 |
|
\ | No newline at end of file |