1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.Time = void 0;
|
4 | const util_1 = require("@antv/util");
|
5 | const fecha_1 = require("fecha");
|
6 | const continuous_1 = require("./continuous");
|
7 | const d3_time_1 = require("../tick-methods/d3-time");
|
8 | const utils_1 = require("../utils");
|
9 | function 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 | }
|
15 | class 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;
|
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 | }
|
55 | exports.Time = Time;
|
56 |
|
\ | No newline at end of file |