UNPKG

1.96 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.Time = void 0;
4const util_1 = require("@antv/util");
5const fecha_1 = require("fecha");
6const continuous_1 = require("./continuous");
7const d3_time_1 = require("../tick-methods/d3-time");
8const utils_1 = require("../utils");
9function offset(date) {
10 const minuteOffset = date.getTimezoneOffset();
11 const d = new Date(date);
12 d.setMinutes(d.getMinutes() + minuteOffset, d.getSeconds(), d.getMilliseconds());
13 return d;
14}
15class Time extends continuous_1.Continuous {
16 getDefaultOptions() {
17 return {
18 domain: [new Date(2000, 0, 1), new Date(2000, 0, 2)],
19 range: [0, 1],
20 nice: false,
21 tickCount: 5,
22 tickInterval: undefined,
23 unknown: undefined,
24 clamp: false,
25 tickMethod: d3_time_1.d3Time,
26 interpolate: utils_1.createInterpolateNumber,
27 mask: undefined,
28 utc: false,
29 };
30 }
31 chooseTransforms() {
32 const transform = (x) => +x;
33 const untransform = (x) => new Date(x);
34 return [transform, untransform];
35 }
36 chooseNice() {
37 return utils_1.d3TimeNice;
38 }
39 getTickMethodOptions() {
40 const { domain, tickCount, tickInterval, utc } = this.options;
41 const min = domain[0];
42 const max = domain[domain.length - 1];
43 return [min, max, tickCount, tickInterval, utc];
44 }
45 getFormatter() {
46 const { mask, utc } = this.options;
47 const maskMap = utc ? utils_1.utcIntervalMap : utils_1.localIntervalMap;
48 const time = utc ? offset : util_1.identity; // fecha 不支持 utc 格式化,所以需要设置一个偏移
49 return (d) => (0, fecha_1.format)(time(d), mask || (0, utils_1.chooseNiceTimeMask)(d, maskMap));
50 }
51 clone() {
52 return new Time(this.options);
53 }
54}
55exports.Time = Time;
56//# sourceMappingURL=time.js.map
\No newline at end of file