vega-time 2.1.3 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/vega-time.js +298 -701
- package/build/vega-time.js.map +1 -0
- package/index.js +5 -5
- package/package.json +20 -13
- package/rollup.config.js +1 -0
- package/src/bin.js +1 -1
- package/src/floor.js +2 -2
- package/src/interval.js +1 -1
- package/build/vega-time.min.js +0 -2
- package/build/vega-time.min.js.map +0 -1
- package/build/vega-time.module.js +0 -306
- package/rollup.config.mjs +0 -1
package/build/vega-time.js
CHANGED
|
@@ -1,710 +1,307 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
if (vegaUtil.hasOwnProperty(UNITS, unit)) {
|
|
28
|
-
m[unit] = 1;
|
|
29
|
-
} else {
|
|
30
|
-
vegaUtil.error(`Invalid time unit: ${unit}.`);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
const numTypes = (m[WEEK] || m[DAY] ? 1 : 0) + (m[QUARTER] || m[MONTH] || m[DATE] ? 1 : 0) + (m[DAYOFYEAR] ? 1 : 0);
|
|
34
|
-
if (numTypes > 1) {
|
|
35
|
-
vegaUtil.error(`Incompatible time units: ${units}`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// ensure proper sort order
|
|
39
|
-
u.sort((a, b) => UNITS[a] - UNITS[b]);
|
|
40
|
-
return u;
|
|
41
|
-
}
|
|
42
|
-
const defaultSpecifiers = {
|
|
43
|
-
[YEAR]: '%Y ',
|
|
44
|
-
[QUARTER]: 'Q%q ',
|
|
45
|
-
[MONTH]: '%b ',
|
|
46
|
-
[DATE]: '%d ',
|
|
47
|
-
[WEEK]: 'W%U ',
|
|
48
|
-
[DAY]: '%a ',
|
|
49
|
-
[DAYOFYEAR]: '%j ',
|
|
50
|
-
[HOURS]: '%H:00',
|
|
51
|
-
[MINUTES]: '00:%M',
|
|
52
|
-
[SECONDS]: ':%S',
|
|
53
|
-
[MILLISECONDS]: '.%L',
|
|
54
|
-
[`${YEAR}-${MONTH}`]: '%Y-%m ',
|
|
55
|
-
[`${YEAR}-${MONTH}-${DATE}`]: '%Y-%m-%d ',
|
|
56
|
-
[`${HOURS}-${MINUTES}`]: '%H:%M'
|
|
57
|
-
};
|
|
58
|
-
function timeUnitSpecifier(units, specifiers) {
|
|
59
|
-
const s = vegaUtil.extend({}, defaultSpecifiers, specifiers),
|
|
60
|
-
u = timeUnits(units),
|
|
61
|
-
n = u.length;
|
|
62
|
-
let fmt = '',
|
|
63
|
-
start = 0,
|
|
64
|
-
end,
|
|
65
|
-
key;
|
|
66
|
-
for (start = 0; start < n;) {
|
|
67
|
-
for (end = u.length; end > start; --end) {
|
|
68
|
-
key = u.slice(start, end).join('-');
|
|
69
|
-
if (s[key] != null) {
|
|
70
|
-
fmt += s[key];
|
|
71
|
-
start = end;
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return fmt.trim();
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const t0$1 = new Date(),
|
|
80
|
-
t1 = new Date();
|
|
81
|
-
function timeInterval$1(floori, offseti, count, field) {
|
|
82
|
-
function interval(date) {
|
|
83
|
-
return floori(date = arguments.length === 0 ? new Date() : new Date(+date)), date;
|
|
84
|
-
}
|
|
85
|
-
interval.floor = date => {
|
|
86
|
-
return floori(date = new Date(+date)), date;
|
|
87
|
-
};
|
|
88
|
-
interval.ceil = date => {
|
|
89
|
-
return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
|
|
90
|
-
};
|
|
91
|
-
interval.round = date => {
|
|
92
|
-
const d0 = interval(date),
|
|
93
|
-
d1 = interval.ceil(date);
|
|
94
|
-
return date - d0 < d1 - date ? d0 : d1;
|
|
95
|
-
};
|
|
96
|
-
interval.offset = (date, step) => {
|
|
97
|
-
return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
|
|
98
|
-
};
|
|
99
|
-
interval.range = (start, stop, step) => {
|
|
100
|
-
const range = [];
|
|
101
|
-
start = interval.ceil(start);
|
|
102
|
-
step = step == null ? 1 : Math.floor(step);
|
|
103
|
-
if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
|
|
104
|
-
let previous;
|
|
105
|
-
do range.push(previous = new Date(+start)), offseti(start, step), floori(start); while (previous < start && start < stop);
|
|
106
|
-
return range;
|
|
107
|
-
};
|
|
108
|
-
interval.filter = test => {
|
|
109
|
-
return timeInterval$1(date => {
|
|
110
|
-
if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
|
|
111
|
-
}, (date, step) => {
|
|
112
|
-
if (date >= date) {
|
|
113
|
-
if (step < 0) while (++step <= 0) {
|
|
114
|
-
while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
|
|
115
|
-
} else while (--step >= 0) {
|
|
116
|
-
while (offseti(date, 1), !test(date)) {} // eslint-disable-line no-empty
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
};
|
|
121
|
-
if (count) {
|
|
122
|
-
interval.count = (start, end) => {
|
|
123
|
-
t0$1.setTime(+start), t1.setTime(+end);
|
|
124
|
-
floori(t0$1), floori(t1);
|
|
125
|
-
return Math.floor(count(t0$1, t1));
|
|
126
|
-
};
|
|
127
|
-
interval.every = step => {
|
|
128
|
-
step = Math.floor(step);
|
|
129
|
-
return !isFinite(step) || !(step > 0) ? null : !(step > 1) ? interval : interval.filter(field ? d => field(d) % step === 0 : d => interval.count(0, d) % step === 0);
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
return interval;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const millisecond = timeInterval$1(() => {
|
|
136
|
-
// noop
|
|
137
|
-
}, (date, step) => {
|
|
138
|
-
date.setTime(+date + step);
|
|
139
|
-
}, (start, end) => {
|
|
140
|
-
return end - start;
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
// An optimized implementation for this simple case.
|
|
144
|
-
millisecond.every = k => {
|
|
145
|
-
k = Math.floor(k);
|
|
146
|
-
if (!isFinite(k) || !(k > 0)) return null;
|
|
147
|
-
if (!(k > 1)) return millisecond;
|
|
148
|
-
return timeInterval$1(date => {
|
|
149
|
-
date.setTime(Math.floor(date / k) * k);
|
|
150
|
-
}, (date, step) => {
|
|
151
|
-
date.setTime(+date + step * k);
|
|
152
|
-
}, (start, end) => {
|
|
153
|
-
return (end - start) / k;
|
|
154
|
-
});
|
|
155
|
-
};
|
|
156
|
-
millisecond.range;
|
|
157
|
-
|
|
158
|
-
const durationSecond$1 = 1000;
|
|
159
|
-
const durationMinute$1 = durationSecond$1 * 60;
|
|
160
|
-
const durationHour$1 = durationMinute$1 * 60;
|
|
161
|
-
const durationDay$1 = durationHour$1 * 24;
|
|
162
|
-
const durationWeek$1 = durationDay$1 * 7;
|
|
163
|
-
|
|
164
|
-
const second = timeInterval$1(date => {
|
|
165
|
-
date.setTime(date - date.getMilliseconds());
|
|
166
|
-
}, (date, step) => {
|
|
167
|
-
date.setTime(+date + step * durationSecond$1);
|
|
168
|
-
}, (start, end) => {
|
|
169
|
-
return (end - start) / durationSecond$1;
|
|
170
|
-
}, date => {
|
|
171
|
-
return date.getUTCSeconds();
|
|
172
|
-
});
|
|
173
|
-
second.range;
|
|
174
|
-
|
|
175
|
-
const timeMinute = timeInterval$1(date => {
|
|
176
|
-
date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond$1);
|
|
177
|
-
}, (date, step) => {
|
|
178
|
-
date.setTime(+date + step * durationMinute$1);
|
|
179
|
-
}, (start, end) => {
|
|
180
|
-
return (end - start) / durationMinute$1;
|
|
181
|
-
}, date => {
|
|
182
|
-
return date.getMinutes();
|
|
183
|
-
});
|
|
184
|
-
timeMinute.range;
|
|
185
|
-
const utcMinute = timeInterval$1(date => {
|
|
186
|
-
date.setUTCSeconds(0, 0);
|
|
187
|
-
}, (date, step) => {
|
|
188
|
-
date.setTime(+date + step * durationMinute$1);
|
|
189
|
-
}, (start, end) => {
|
|
190
|
-
return (end - start) / durationMinute$1;
|
|
191
|
-
}, date => {
|
|
192
|
-
return date.getUTCMinutes();
|
|
193
|
-
});
|
|
194
|
-
utcMinute.range;
|
|
195
|
-
|
|
196
|
-
const timeHour = timeInterval$1(date => {
|
|
197
|
-
date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond$1 - date.getMinutes() * durationMinute$1);
|
|
198
|
-
}, (date, step) => {
|
|
199
|
-
date.setTime(+date + step * durationHour$1);
|
|
200
|
-
}, (start, end) => {
|
|
201
|
-
return (end - start) / durationHour$1;
|
|
202
|
-
}, date => {
|
|
203
|
-
return date.getHours();
|
|
204
|
-
});
|
|
205
|
-
timeHour.range;
|
|
206
|
-
const utcHour = timeInterval$1(date => {
|
|
207
|
-
date.setUTCMinutes(0, 0, 0);
|
|
208
|
-
}, (date, step) => {
|
|
209
|
-
date.setTime(+date + step * durationHour$1);
|
|
210
|
-
}, (start, end) => {
|
|
211
|
-
return (end - start) / durationHour$1;
|
|
212
|
-
}, date => {
|
|
213
|
-
return date.getUTCHours();
|
|
214
|
-
});
|
|
215
|
-
utcHour.range;
|
|
216
|
-
|
|
217
|
-
const timeDay = timeInterval$1(date => date.setHours(0, 0, 0, 0), (date, step) => date.setDate(date.getDate() + step), (start, end) => (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute$1) / durationDay$1, date => date.getDate() - 1);
|
|
218
|
-
timeDay.range;
|
|
219
|
-
const utcDay = timeInterval$1(date => {
|
|
220
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
221
|
-
}, (date, step) => {
|
|
222
|
-
date.setUTCDate(date.getUTCDate() + step);
|
|
223
|
-
}, (start, end) => {
|
|
224
|
-
return (end - start) / durationDay$1;
|
|
225
|
-
}, date => {
|
|
226
|
-
return date.getUTCDate() - 1;
|
|
227
|
-
});
|
|
228
|
-
utcDay.range;
|
|
229
|
-
const unixDay = timeInterval$1(date => {
|
|
230
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
231
|
-
}, (date, step) => {
|
|
232
|
-
date.setUTCDate(date.getUTCDate() + step);
|
|
233
|
-
}, (start, end) => {
|
|
234
|
-
return (end - start) / durationDay$1;
|
|
235
|
-
}, date => {
|
|
236
|
-
return Math.floor(date / durationDay$1);
|
|
237
|
-
});
|
|
238
|
-
unixDay.range;
|
|
239
|
-
|
|
240
|
-
function timeWeekday(i) {
|
|
241
|
-
return timeInterval$1(date => {
|
|
242
|
-
date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
|
|
243
|
-
date.setHours(0, 0, 0, 0);
|
|
244
|
-
}, (date, step) => {
|
|
245
|
-
date.setDate(date.getDate() + step * 7);
|
|
246
|
-
}, (start, end) => {
|
|
247
|
-
return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute$1) / durationWeek$1;
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
const timeSunday = timeWeekday(0);
|
|
251
|
-
const timeMonday = timeWeekday(1);
|
|
252
|
-
const timeTuesday = timeWeekday(2);
|
|
253
|
-
const timeWednesday = timeWeekday(3);
|
|
254
|
-
const timeThursday = timeWeekday(4);
|
|
255
|
-
const timeFriday = timeWeekday(5);
|
|
256
|
-
const timeSaturday = timeWeekday(6);
|
|
257
|
-
timeSunday.range;
|
|
258
|
-
timeMonday.range;
|
|
259
|
-
timeTuesday.range;
|
|
260
|
-
timeWednesday.range;
|
|
261
|
-
timeThursday.range;
|
|
262
|
-
timeFriday.range;
|
|
263
|
-
timeSaturday.range;
|
|
264
|
-
function utcWeekday(i) {
|
|
265
|
-
return timeInterval$1(date => {
|
|
266
|
-
date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
|
|
267
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
268
|
-
}, (date, step) => {
|
|
269
|
-
date.setUTCDate(date.getUTCDate() + step * 7);
|
|
270
|
-
}, (start, end) => {
|
|
271
|
-
return (end - start) / durationWeek$1;
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
const utcSunday = utcWeekday(0);
|
|
275
|
-
const utcMonday = utcWeekday(1);
|
|
276
|
-
const utcTuesday = utcWeekday(2);
|
|
277
|
-
const utcWednesday = utcWeekday(3);
|
|
278
|
-
const utcThursday = utcWeekday(4);
|
|
279
|
-
const utcFriday = utcWeekday(5);
|
|
280
|
-
const utcSaturday = utcWeekday(6);
|
|
281
|
-
utcSunday.range;
|
|
282
|
-
utcMonday.range;
|
|
283
|
-
utcTuesday.range;
|
|
284
|
-
utcWednesday.range;
|
|
285
|
-
utcThursday.range;
|
|
286
|
-
utcFriday.range;
|
|
287
|
-
utcSaturday.range;
|
|
288
|
-
|
|
289
|
-
const timeMonth = timeInterval$1(date => {
|
|
290
|
-
date.setDate(1);
|
|
291
|
-
date.setHours(0, 0, 0, 0);
|
|
292
|
-
}, (date, step) => {
|
|
293
|
-
date.setMonth(date.getMonth() + step);
|
|
294
|
-
}, (start, end) => {
|
|
295
|
-
return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
|
|
296
|
-
}, date => {
|
|
297
|
-
return date.getMonth();
|
|
298
|
-
});
|
|
299
|
-
timeMonth.range;
|
|
300
|
-
const utcMonth = timeInterval$1(date => {
|
|
301
|
-
date.setUTCDate(1);
|
|
302
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
303
|
-
}, (date, step) => {
|
|
304
|
-
date.setUTCMonth(date.getUTCMonth() + step);
|
|
305
|
-
}, (start, end) => {
|
|
306
|
-
return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
|
|
307
|
-
}, date => {
|
|
308
|
-
return date.getUTCMonth();
|
|
309
|
-
});
|
|
310
|
-
utcMonth.range;
|
|
311
|
-
|
|
312
|
-
const timeYear = timeInterval$1(date => {
|
|
313
|
-
date.setMonth(0, 1);
|
|
314
|
-
date.setHours(0, 0, 0, 0);
|
|
315
|
-
}, (date, step) => {
|
|
316
|
-
date.setFullYear(date.getFullYear() + step);
|
|
317
|
-
}, (start, end) => {
|
|
318
|
-
return end.getFullYear() - start.getFullYear();
|
|
319
|
-
}, date => {
|
|
320
|
-
return date.getFullYear();
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
// An optimized implementation for this simple case.
|
|
324
|
-
timeYear.every = k => {
|
|
325
|
-
return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : timeInterval$1(date => {
|
|
326
|
-
date.setFullYear(Math.floor(date.getFullYear() / k) * k);
|
|
327
|
-
date.setMonth(0, 1);
|
|
328
|
-
date.setHours(0, 0, 0, 0);
|
|
329
|
-
}, (date, step) => {
|
|
330
|
-
date.setFullYear(date.getFullYear() + step * k);
|
|
331
|
-
});
|
|
332
|
-
};
|
|
333
|
-
timeYear.range;
|
|
334
|
-
const utcYear = timeInterval$1(date => {
|
|
335
|
-
date.setUTCMonth(0, 1);
|
|
336
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
337
|
-
}, (date, step) => {
|
|
338
|
-
date.setUTCFullYear(date.getUTCFullYear() + step);
|
|
339
|
-
}, (start, end) => {
|
|
340
|
-
return end.getUTCFullYear() - start.getUTCFullYear();
|
|
341
|
-
}, date => {
|
|
342
|
-
return date.getUTCFullYear();
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
// An optimized implementation for this simple case.
|
|
346
|
-
utcYear.every = k => {
|
|
347
|
-
return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : timeInterval$1(date => {
|
|
348
|
-
date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
|
|
349
|
-
date.setUTCMonth(0, 1);
|
|
350
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
351
|
-
}, (date, step) => {
|
|
352
|
-
date.setUTCFullYear(date.getUTCFullYear() + step * k);
|
|
353
|
-
});
|
|
354
|
-
};
|
|
355
|
-
utcYear.range;
|
|
356
|
-
|
|
357
|
-
function ascending(a, b) {
|
|
358
|
-
return a == null || b == null ? NaN : a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
function descending(a, b) {
|
|
362
|
-
return a == null || b == null ? NaN : b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
function bisector(f) {
|
|
366
|
-
let compare1, compare2, delta;
|
|
367
|
-
|
|
368
|
-
// If an accessor is specified, promote it to a comparator. In this case we
|
|
369
|
-
// can test whether the search value is (self-) comparable. We can’t do this
|
|
370
|
-
// for a comparator (except for specific, known comparators) because we can’t
|
|
371
|
-
// tell if the comparator is symmetric, and an asymmetric comparator can’t be
|
|
372
|
-
// used to test whether a single value is comparable.
|
|
373
|
-
if (f.length !== 2) {
|
|
374
|
-
compare1 = ascending;
|
|
375
|
-
compare2 = (d, x) => ascending(f(d), x);
|
|
376
|
-
delta = (d, x) => f(d) - x;
|
|
1
|
+
import { array, error, hasOwnProperty, extend, peek, toSet, constant, zero, one, span } from 'vega-util';
|
|
2
|
+
import { timeDay, timeWeek, utcDay, utcWeek, timeMonth, utcMonth, timeMillisecond, timeSecond, timeMinute, timeHour, timeYear, utcMillisecond, utcSecond, utcMinute, utcHour, utcYear } from 'd3-time';
|
|
3
|
+
import { bisector, tickStep } from 'd3-array';
|
|
4
|
+
|
|
5
|
+
const YEAR = 'year';
|
|
6
|
+
const QUARTER = 'quarter';
|
|
7
|
+
const MONTH = 'month';
|
|
8
|
+
const WEEK = 'week';
|
|
9
|
+
const DATE = 'date';
|
|
10
|
+
const DAY = 'day';
|
|
11
|
+
const DAYOFYEAR = 'dayofyear';
|
|
12
|
+
const HOURS = 'hours';
|
|
13
|
+
const MINUTES = 'minutes';
|
|
14
|
+
const SECONDS = 'seconds';
|
|
15
|
+
const MILLISECONDS = 'milliseconds';
|
|
16
|
+
const TIME_UNITS = [YEAR, QUARTER, MONTH, WEEK, DATE, DAY, DAYOFYEAR, HOURS, MINUTES, SECONDS, MILLISECONDS];
|
|
17
|
+
const UNITS = TIME_UNITS.reduce((o, u, i) => (o[u] = 1 + i, o), {});
|
|
18
|
+
function timeUnits(units) {
|
|
19
|
+
const u = array(units).slice(),
|
|
20
|
+
m = {};
|
|
21
|
+
|
|
22
|
+
// check validity
|
|
23
|
+
if (!u.length) error('Missing time unit.');
|
|
24
|
+
u.forEach(unit => {
|
|
25
|
+
if (hasOwnProperty(UNITS, unit)) {
|
|
26
|
+
m[unit] = 1;
|
|
377
27
|
} else {
|
|
378
|
-
|
|
379
|
-
compare2 = f;
|
|
380
|
-
delta = f;
|
|
381
|
-
}
|
|
382
|
-
function left(a, x, lo = 0, hi = a.length) {
|
|
383
|
-
if (lo < hi) {
|
|
384
|
-
if (compare1(x, x) !== 0) return hi;
|
|
385
|
-
do {
|
|
386
|
-
const mid = lo + hi >>> 1;
|
|
387
|
-
if (compare2(a[mid], x) < 0) lo = mid + 1;else hi = mid;
|
|
388
|
-
} while (lo < hi);
|
|
389
|
-
}
|
|
390
|
-
return lo;
|
|
28
|
+
error(`Invalid time unit: ${unit}.`);
|
|
391
29
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
30
|
+
});
|
|
31
|
+
const numTypes = (m[WEEK] || m[DAY] ? 1 : 0) + (m[QUARTER] || m[MONTH] || m[DATE] ? 1 : 0) + (m[DAYOFYEAR] ? 1 : 0);
|
|
32
|
+
if (numTypes > 1) {
|
|
33
|
+
error(`Incompatible time units: ${units}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// ensure proper sort order
|
|
37
|
+
u.sort((a, b) => UNITS[a] - UNITS[b]);
|
|
38
|
+
return u;
|
|
39
|
+
}
|
|
40
|
+
const defaultSpecifiers = {
|
|
41
|
+
[YEAR]: '%Y ',
|
|
42
|
+
[QUARTER]: 'Q%q ',
|
|
43
|
+
[MONTH]: '%b ',
|
|
44
|
+
[DATE]: '%d ',
|
|
45
|
+
[WEEK]: 'W%U ',
|
|
46
|
+
[DAY]: '%a ',
|
|
47
|
+
[DAYOFYEAR]: '%j ',
|
|
48
|
+
[HOURS]: '%H:00',
|
|
49
|
+
[MINUTES]: '00:%M',
|
|
50
|
+
[SECONDS]: ':%S',
|
|
51
|
+
[MILLISECONDS]: '.%L',
|
|
52
|
+
[`${YEAR}-${MONTH}`]: '%Y-%m ',
|
|
53
|
+
[`${YEAR}-${MONTH}-${DATE}`]: '%Y-%m-%d ',
|
|
54
|
+
[`${HOURS}-${MINUTES}`]: '%H:%M'
|
|
55
|
+
};
|
|
56
|
+
function timeUnitSpecifier(units, specifiers) {
|
|
57
|
+
const s = extend({}, defaultSpecifiers, specifiers),
|
|
58
|
+
u = timeUnits(units),
|
|
59
|
+
n = u.length;
|
|
60
|
+
let fmt = '',
|
|
61
|
+
start = 0,
|
|
62
|
+
end,
|
|
63
|
+
key;
|
|
64
|
+
for (start = 0; start < n;) {
|
|
65
|
+
for (end = u.length; end > start; --end) {
|
|
66
|
+
key = u.slice(start, end).join('-');
|
|
67
|
+
if (s[key] != null) {
|
|
68
|
+
fmt += s[key];
|
|
69
|
+
start = end;
|
|
70
|
+
break;
|
|
399
71
|
}
|
|
400
|
-
return lo;
|
|
401
|
-
}
|
|
402
|
-
function center(a, x, lo = 0, hi = a.length) {
|
|
403
|
-
const i = left(a, x, lo, hi - 1);
|
|
404
|
-
return i > lo && delta(a[i - 1], x) > -delta(a[i], x) ? i - 1 : i;
|
|
405
|
-
}
|
|
406
|
-
return {
|
|
407
|
-
left,
|
|
408
|
-
center,
|
|
409
|
-
right
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
function zero() {
|
|
413
|
-
return 0;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
const e10 = Math.sqrt(50),
|
|
417
|
-
e5 = Math.sqrt(10),
|
|
418
|
-
e2 = Math.sqrt(2);
|
|
419
|
-
function tickSpec(start, stop, count) {
|
|
420
|
-
const step = (stop - start) / Math.max(0, count),
|
|
421
|
-
power = Math.floor(Math.log10(step)),
|
|
422
|
-
error = step / Math.pow(10, power),
|
|
423
|
-
factor = error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1;
|
|
424
|
-
let i1, i2, inc;
|
|
425
|
-
if (power < 0) {
|
|
426
|
-
inc = Math.pow(10, -power) / factor;
|
|
427
|
-
i1 = Math.round(start * inc);
|
|
428
|
-
i2 = Math.round(stop * inc);
|
|
429
|
-
if (i1 / inc < start) ++i1;
|
|
430
|
-
if (i2 / inc > stop) --i2;
|
|
431
|
-
inc = -inc;
|
|
432
|
-
} else {
|
|
433
|
-
inc = Math.pow(10, power) * factor;
|
|
434
|
-
i1 = Math.round(start / inc);
|
|
435
|
-
i2 = Math.round(stop / inc);
|
|
436
|
-
if (i1 * inc < start) ++i1;
|
|
437
|
-
if (i2 * inc > stop) --i2;
|
|
438
|
-
}
|
|
439
|
-
if (i2 < i1 && 0.5 <= count && count < 2) return tickSpec(start, stop, count * 2);
|
|
440
|
-
return [i1, i2, inc];
|
|
441
|
-
}
|
|
442
|
-
function tickIncrement(start, stop, count) {
|
|
443
|
-
stop = +stop, start = +start, count = +count;
|
|
444
|
-
return tickSpec(start, stop, count)[2];
|
|
445
|
-
}
|
|
446
|
-
function tickStep(start, stop, count) {
|
|
447
|
-
stop = +stop, start = +start, count = +count;
|
|
448
|
-
const reverse = stop < start,
|
|
449
|
-
inc = reverse ? tickIncrement(stop, start, count) : tickIncrement(start, stop, count);
|
|
450
|
-
return (reverse ? -1 : 1) * (inc < 0 ? 1 / -inc : inc);
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
const t0 = new Date();
|
|
454
|
-
function localYear(y) {
|
|
455
|
-
t0.setFullYear(y);
|
|
456
|
-
t0.setMonth(0);
|
|
457
|
-
t0.setDate(1);
|
|
458
|
-
t0.setHours(0, 0, 0, 0);
|
|
459
|
-
return t0;
|
|
460
|
-
}
|
|
461
|
-
function dayofyear(d) {
|
|
462
|
-
return localDayOfYear(new Date(d));
|
|
463
|
-
}
|
|
464
|
-
function week(d) {
|
|
465
|
-
return localWeekNum(new Date(d));
|
|
466
|
-
}
|
|
467
|
-
function localDayOfYear(d) {
|
|
468
|
-
return timeDay.count(localYear(d.getFullYear()) - 1, d);
|
|
469
|
-
}
|
|
470
|
-
function localWeekNum(d) {
|
|
471
|
-
return timeSunday.count(localYear(d.getFullYear()) - 1, d);
|
|
472
|
-
}
|
|
473
|
-
function localFirst(y) {
|
|
474
|
-
return localYear(y).getDay();
|
|
475
|
-
}
|
|
476
|
-
function localDate(y, m, d, H, M, S, L) {
|
|
477
|
-
if (0 <= y && y < 100) {
|
|
478
|
-
const date = new Date(-1, m, d, H, M, S, L);
|
|
479
|
-
date.setFullYear(y);
|
|
480
|
-
return date;
|
|
481
|
-
}
|
|
482
|
-
return new Date(y, m, d, H, M, S, L);
|
|
483
|
-
}
|
|
484
|
-
function utcdayofyear(d) {
|
|
485
|
-
return utcDayOfYear(new Date(d));
|
|
486
|
-
}
|
|
487
|
-
function utcweek(d) {
|
|
488
|
-
return utcWeekNum(new Date(d));
|
|
489
|
-
}
|
|
490
|
-
function utcDayOfYear(d) {
|
|
491
|
-
const y = Date.UTC(d.getUTCFullYear(), 0, 1);
|
|
492
|
-
return utcDay.count(y - 1, d);
|
|
493
|
-
}
|
|
494
|
-
function utcWeekNum(d) {
|
|
495
|
-
const y = Date.UTC(d.getUTCFullYear(), 0, 1);
|
|
496
|
-
return utcSunday.count(y - 1, d);
|
|
497
|
-
}
|
|
498
|
-
function utcFirst(y) {
|
|
499
|
-
t0.setTime(Date.UTC(y, 0, 1));
|
|
500
|
-
return t0.getUTCDay();
|
|
501
|
-
}
|
|
502
|
-
function utcDate(y, m, d, H, M, S, L) {
|
|
503
|
-
if (0 <= y && y < 100) {
|
|
504
|
-
const date = new Date(Date.UTC(-1, m, d, H, M, S, L));
|
|
505
|
-
date.setUTCFullYear(d.y);
|
|
506
|
-
return date;
|
|
507
72
|
}
|
|
508
|
-
return new Date(Date.UTC(y, m, d, H, M, S, L));
|
|
509
73
|
}
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
74
|
+
return fmt.trim();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const t0 = new Date();
|
|
78
|
+
function localYear(y) {
|
|
79
|
+
t0.setFullYear(y);
|
|
80
|
+
t0.setMonth(0);
|
|
81
|
+
t0.setDate(1);
|
|
82
|
+
t0.setHours(0, 0, 0, 0);
|
|
83
|
+
return t0;
|
|
84
|
+
}
|
|
85
|
+
function dayofyear(d) {
|
|
86
|
+
return localDayOfYear(new Date(d));
|
|
87
|
+
}
|
|
88
|
+
function week(d) {
|
|
89
|
+
return localWeekNum(new Date(d));
|
|
90
|
+
}
|
|
91
|
+
function localDayOfYear(d) {
|
|
92
|
+
return timeDay.count(localYear(d.getFullYear()) - 1, d);
|
|
93
|
+
}
|
|
94
|
+
function localWeekNum(d) {
|
|
95
|
+
return timeWeek.count(localYear(d.getFullYear()) - 1, d);
|
|
96
|
+
}
|
|
97
|
+
function localFirst(y) {
|
|
98
|
+
return localYear(y).getDay();
|
|
99
|
+
}
|
|
100
|
+
function localDate(y, m, d, H, M, S, L) {
|
|
101
|
+
if (0 <= y && y < 100) {
|
|
102
|
+
const date = new Date(-1, m, d, H, M, S, L);
|
|
103
|
+
date.setFullYear(y);
|
|
104
|
+
return date;
|
|
105
|
+
}
|
|
106
|
+
return new Date(y, m, d, H, M, S, L);
|
|
107
|
+
}
|
|
108
|
+
function utcdayofyear(d) {
|
|
109
|
+
return utcDayOfYear(new Date(d));
|
|
110
|
+
}
|
|
111
|
+
function utcweek(d) {
|
|
112
|
+
return utcWeekNum(new Date(d));
|
|
113
|
+
}
|
|
114
|
+
function utcDayOfYear(d) {
|
|
115
|
+
const y = Date.UTC(d.getUTCFullYear(), 0, 1);
|
|
116
|
+
return utcDay.count(y - 1, d);
|
|
117
|
+
}
|
|
118
|
+
function utcWeekNum(d) {
|
|
119
|
+
const y = Date.UTC(d.getUTCFullYear(), 0, 1);
|
|
120
|
+
return utcWeek.count(y - 1, d);
|
|
121
|
+
}
|
|
122
|
+
function utcFirst(y) {
|
|
123
|
+
t0.setTime(Date.UTC(y, 0, 1));
|
|
124
|
+
return t0.getUTCDay();
|
|
125
|
+
}
|
|
126
|
+
function utcDate(y, m, d, H, M, S, L) {
|
|
127
|
+
if (0 <= y && y < 100) {
|
|
128
|
+
const date = new Date(Date.UTC(-1, m, d, H, M, S, L));
|
|
129
|
+
date.setUTCFullYear(d.y);
|
|
130
|
+
return date;
|
|
131
|
+
}
|
|
132
|
+
return new Date(Date.UTC(y, m, d, H, M, S, L));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function floor(units, step, get, inv, newDate) {
|
|
136
|
+
const s = step || 1,
|
|
137
|
+
b = peek(units),
|
|
138
|
+
_ = (unit, p, key) => {
|
|
139
|
+
key = key || unit;
|
|
140
|
+
return getUnit(get[key], inv[key], unit === b && s, p);
|
|
531
141
|
};
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
const localGet = {
|
|
547
|
-
[YEAR]: d => d.getFullYear(),
|
|
548
|
-
[QUARTER]: d => Math.floor(d.getMonth() / 3),
|
|
549
|
-
[MONTH]: d => d.getMonth(),
|
|
550
|
-
[DATE]: d => d.getDate(),
|
|
551
|
-
[HOURS]: d => d.getHours(),
|
|
552
|
-
[MINUTES]: d => d.getMinutes(),
|
|
553
|
-
[SECONDS]: d => d.getSeconds(),
|
|
554
|
-
[MILLISECONDS]: d => d.getMilliseconds(),
|
|
555
|
-
[DAYOFYEAR]: d => localDayOfYear(d),
|
|
556
|
-
[WEEK]: d => localWeekNum(d),
|
|
557
|
-
[WEEK + DAY]: (d, y) => weekday(localWeekNum(d), d.getDay(), localFirst(y)),
|
|
558
|
-
[DAY]: (d, y) => weekday(1, d.getDay(), localFirst(y))
|
|
559
|
-
};
|
|
560
|
-
const localInv = {
|
|
561
|
-
[QUARTER]: q => 3 * q,
|
|
562
|
-
[WEEK]: (w, y) => weekday(w, 0, localFirst(y))
|
|
563
|
-
};
|
|
564
|
-
function timeFloor(units, step) {
|
|
565
|
-
return floor(units, step || 1, localGet, localInv, localDate);
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
// -- UTC TIME --
|
|
569
|
-
|
|
570
|
-
const utcGet = {
|
|
571
|
-
[YEAR]: d => d.getUTCFullYear(),
|
|
572
|
-
[QUARTER]: d => Math.floor(d.getUTCMonth() / 3),
|
|
573
|
-
[MONTH]: d => d.getUTCMonth(),
|
|
574
|
-
[DATE]: d => d.getUTCDate(),
|
|
575
|
-
[HOURS]: d => d.getUTCHours(),
|
|
576
|
-
[MINUTES]: d => d.getUTCMinutes(),
|
|
577
|
-
[SECONDS]: d => d.getUTCSeconds(),
|
|
578
|
-
[MILLISECONDS]: d => d.getUTCMilliseconds(),
|
|
579
|
-
[DAYOFYEAR]: d => utcDayOfYear(d),
|
|
580
|
-
[WEEK]: d => utcWeekNum(d),
|
|
581
|
-
[DAY]: (d, y) => weekday(1, d.getUTCDay(), utcFirst(y)),
|
|
582
|
-
[WEEK + DAY]: (d, y) => weekday(utcWeekNum(d), d.getUTCDay(), utcFirst(y))
|
|
583
|
-
};
|
|
584
|
-
const utcInv = {
|
|
585
|
-
[QUARTER]: q => 3 * q,
|
|
586
|
-
[WEEK]: (w, y) => weekday(w, 0, utcFirst(y))
|
|
587
|
-
};
|
|
588
|
-
function utcFloor(units, step) {
|
|
589
|
-
return floor(units, step || 1, utcGet, utcInv, utcDate);
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
const timeIntervals = {
|
|
593
|
-
[YEAR]: timeYear,
|
|
594
|
-
[QUARTER]: timeMonth.every(3),
|
|
595
|
-
[MONTH]: timeMonth,
|
|
596
|
-
[WEEK]: timeSunday,
|
|
597
|
-
[DATE]: timeDay,
|
|
598
|
-
[DAY]: timeDay,
|
|
599
|
-
[DAYOFYEAR]: timeDay,
|
|
600
|
-
[HOURS]: timeHour,
|
|
601
|
-
[MINUTES]: timeMinute,
|
|
602
|
-
[SECONDS]: second,
|
|
603
|
-
[MILLISECONDS]: millisecond
|
|
142
|
+
const t = new Date(),
|
|
143
|
+
u = toSet(units),
|
|
144
|
+
y = u[YEAR] ? _(YEAR) : constant(2012),
|
|
145
|
+
m = u[MONTH] ? _(MONTH) : u[QUARTER] ? _(QUARTER) : zero,
|
|
146
|
+
d = u[WEEK] && u[DAY] ? _(DAY, 1, WEEK + DAY) : u[WEEK] ? _(WEEK, 1) : u[DAY] ? _(DAY, 1) : u[DATE] ? _(DATE, 1) : u[DAYOFYEAR] ? _(DAYOFYEAR, 1) : one,
|
|
147
|
+
H = u[HOURS] ? _(HOURS) : zero,
|
|
148
|
+
M = u[MINUTES] ? _(MINUTES) : zero,
|
|
149
|
+
S = u[SECONDS] ? _(SECONDS) : zero,
|
|
150
|
+
L = u[MILLISECONDS] ? _(MILLISECONDS) : zero;
|
|
151
|
+
return function (v) {
|
|
152
|
+
t.setTime(+v);
|
|
153
|
+
const year = y(t);
|
|
154
|
+
return newDate(year, m(t), d(t, year), H(t), M(t), S(t), L(t));
|
|
604
155
|
};
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
156
|
+
}
|
|
157
|
+
function getUnit(f, inv, step, phase) {
|
|
158
|
+
const u = step <= 1 ? f : phase ? (d, y) => phase + step * Math.floor((f(d, y) - phase) / step) : (d, y) => step * Math.floor(f(d, y) / step);
|
|
159
|
+
return inv ? (d, y) => inv(u(d, y), y) : u;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// returns the day of the year based on week number, day of week,
|
|
163
|
+
// and the day of the week for the first day of the year
|
|
164
|
+
function weekday(week, day, firstDay) {
|
|
165
|
+
return day + week * 7 - (firstDay + 6) % 7;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// -- LOCAL TIME --
|
|
169
|
+
|
|
170
|
+
const localGet = {
|
|
171
|
+
[YEAR]: d => d.getFullYear(),
|
|
172
|
+
[QUARTER]: d => Math.floor(d.getMonth() / 3),
|
|
173
|
+
[MONTH]: d => d.getMonth(),
|
|
174
|
+
[DATE]: d => d.getDate(),
|
|
175
|
+
[HOURS]: d => d.getHours(),
|
|
176
|
+
[MINUTES]: d => d.getMinutes(),
|
|
177
|
+
[SECONDS]: d => d.getSeconds(),
|
|
178
|
+
[MILLISECONDS]: d => d.getMilliseconds(),
|
|
179
|
+
[DAYOFYEAR]: d => localDayOfYear(d),
|
|
180
|
+
[WEEK]: d => localWeekNum(d),
|
|
181
|
+
[WEEK + DAY]: (d, y) => weekday(localWeekNum(d), d.getDay(), localFirst(y)),
|
|
182
|
+
[DAY]: (d, y) => weekday(1, d.getDay(), localFirst(y))
|
|
183
|
+
};
|
|
184
|
+
const localInv = {
|
|
185
|
+
[QUARTER]: q => 3 * q,
|
|
186
|
+
[WEEK]: (w, y) => weekday(w, 0, localFirst(y))
|
|
187
|
+
};
|
|
188
|
+
function timeFloor(units, step) {
|
|
189
|
+
return floor(units, step || 1, localGet, localInv, localDate);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// -- UTC TIME --
|
|
193
|
+
|
|
194
|
+
const utcGet = {
|
|
195
|
+
[YEAR]: d => d.getUTCFullYear(),
|
|
196
|
+
[QUARTER]: d => Math.floor(d.getUTCMonth() / 3),
|
|
197
|
+
[MONTH]: d => d.getUTCMonth(),
|
|
198
|
+
[DATE]: d => d.getUTCDate(),
|
|
199
|
+
[HOURS]: d => d.getUTCHours(),
|
|
200
|
+
[MINUTES]: d => d.getUTCMinutes(),
|
|
201
|
+
[SECONDS]: d => d.getUTCSeconds(),
|
|
202
|
+
[MILLISECONDS]: d => d.getUTCMilliseconds(),
|
|
203
|
+
[DAYOFYEAR]: d => utcDayOfYear(d),
|
|
204
|
+
[WEEK]: d => utcWeekNum(d),
|
|
205
|
+
[DAY]: (d, y) => weekday(1, d.getUTCDay(), utcFirst(y)),
|
|
206
|
+
[WEEK + DAY]: (d, y) => weekday(utcWeekNum(d), d.getUTCDay(), utcFirst(y))
|
|
207
|
+
};
|
|
208
|
+
const utcInv = {
|
|
209
|
+
[QUARTER]: q => 3 * q,
|
|
210
|
+
[WEEK]: (w, y) => weekday(w, 0, utcFirst(y))
|
|
211
|
+
};
|
|
212
|
+
function utcFloor(units, step) {
|
|
213
|
+
return floor(units, step || 1, utcGet, utcInv, utcDate);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const timeIntervals = {
|
|
217
|
+
[YEAR]: timeYear,
|
|
218
|
+
[QUARTER]: timeMonth.every(3),
|
|
219
|
+
[MONTH]: timeMonth,
|
|
220
|
+
[WEEK]: timeWeek,
|
|
221
|
+
[DATE]: timeDay,
|
|
222
|
+
[DAY]: timeDay,
|
|
223
|
+
[DAYOFYEAR]: timeDay,
|
|
224
|
+
[HOURS]: timeHour,
|
|
225
|
+
[MINUTES]: timeMinute,
|
|
226
|
+
[SECONDS]: timeSecond,
|
|
227
|
+
[MILLISECONDS]: timeMillisecond
|
|
228
|
+
};
|
|
229
|
+
const utcIntervals = {
|
|
230
|
+
[YEAR]: utcYear,
|
|
231
|
+
[QUARTER]: utcMonth.every(3),
|
|
232
|
+
[MONTH]: utcMonth,
|
|
233
|
+
[WEEK]: utcWeek,
|
|
234
|
+
[DATE]: utcDay,
|
|
235
|
+
[DAY]: utcDay,
|
|
236
|
+
[DAYOFYEAR]: utcDay,
|
|
237
|
+
[HOURS]: utcHour,
|
|
238
|
+
[MINUTES]: utcMinute,
|
|
239
|
+
[SECONDS]: utcSecond,
|
|
240
|
+
[MILLISECONDS]: utcMillisecond
|
|
241
|
+
};
|
|
242
|
+
function timeInterval(unit) {
|
|
243
|
+
return timeIntervals[unit];
|
|
244
|
+
}
|
|
245
|
+
function utcInterval(unit) {
|
|
246
|
+
return utcIntervals[unit];
|
|
247
|
+
}
|
|
248
|
+
function offset(ival, date, step) {
|
|
249
|
+
return ival ? ival.offset(date, step) : undefined;
|
|
250
|
+
}
|
|
251
|
+
function timeOffset(unit, date, step) {
|
|
252
|
+
return offset(timeInterval(unit), date, step);
|
|
253
|
+
}
|
|
254
|
+
function utcOffset(unit, date, step) {
|
|
255
|
+
return offset(utcInterval(unit), date, step);
|
|
256
|
+
}
|
|
257
|
+
function sequence(ival, start, stop, step) {
|
|
258
|
+
return ival ? ival.range(start, stop, step) : undefined;
|
|
259
|
+
}
|
|
260
|
+
function timeSequence(unit, start, stop, step) {
|
|
261
|
+
return sequence(timeInterval(unit), start, stop, step);
|
|
262
|
+
}
|
|
263
|
+
function utcSequence(unit, start, stop, step) {
|
|
264
|
+
return sequence(utcInterval(unit), start, stop, step);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const durationSecond = 1000,
|
|
268
|
+
durationMinute = durationSecond * 60,
|
|
269
|
+
durationHour = durationMinute * 60,
|
|
270
|
+
durationDay = durationHour * 24,
|
|
271
|
+
durationWeek = durationDay * 7,
|
|
272
|
+
durationMonth = durationDay * 30,
|
|
273
|
+
durationYear = durationDay * 365;
|
|
274
|
+
const Milli = [YEAR, MONTH, DATE, HOURS, MINUTES, SECONDS, MILLISECONDS],
|
|
275
|
+
Seconds = Milli.slice(0, -1),
|
|
276
|
+
Minutes = Seconds.slice(0, -1),
|
|
277
|
+
Hours = Minutes.slice(0, -1),
|
|
278
|
+
Day = Hours.slice(0, -1),
|
|
279
|
+
Week = [YEAR, WEEK],
|
|
280
|
+
Month = [YEAR, MONTH],
|
|
281
|
+
Year = [YEAR];
|
|
282
|
+
const intervals = [[Seconds, 1, durationSecond], [Seconds, 5, 5 * durationSecond], [Seconds, 15, 15 * durationSecond], [Seconds, 30, 30 * durationSecond], [Minutes, 1, durationMinute], [Minutes, 5, 5 * durationMinute], [Minutes, 15, 15 * durationMinute], [Minutes, 30, 30 * durationMinute], [Hours, 1, durationHour], [Hours, 3, 3 * durationHour], [Hours, 6, 6 * durationHour], [Hours, 12, 12 * durationHour], [Day, 1, durationDay], [Week, 1, durationWeek], [Month, 1, durationMonth], [Month, 3, 3 * durationMonth], [Year, 1, durationYear]];
|
|
283
|
+
function bin (opt) {
|
|
284
|
+
const ext = opt.extent,
|
|
285
|
+
max = opt.maxbins || 40,
|
|
286
|
+
target = Math.abs(span(ext)) / max;
|
|
287
|
+
let i = bisector(i => i[2]).right(intervals, target),
|
|
288
|
+
units,
|
|
289
|
+
step;
|
|
290
|
+
if (i === intervals.length) {
|
|
291
|
+
units = Year, step = tickStep(ext[0] / durationYear, ext[1] / durationYear, max);
|
|
292
|
+
} else if (i) {
|
|
293
|
+
i = intervals[target / intervals[i - 1][2] < intervals[i][2] / target ? i - 1 : i];
|
|
294
|
+
units = i[0];
|
|
295
|
+
step = i[1];
|
|
296
|
+
} else {
|
|
297
|
+
units = Milli;
|
|
298
|
+
step = Math.max(tickStep(ext[0], ext[1], max), 1);
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
units,
|
|
302
|
+
step
|
|
617
303
|
};
|
|
618
|
-
|
|
619
|
-
return timeIntervals[unit];
|
|
620
|
-
}
|
|
621
|
-
function utcInterval(unit) {
|
|
622
|
-
return utcIntervals[unit];
|
|
623
|
-
}
|
|
624
|
-
function offset(ival, date, step) {
|
|
625
|
-
return ival ? ival.offset(date, step) : undefined;
|
|
626
|
-
}
|
|
627
|
-
function timeOffset(unit, date, step) {
|
|
628
|
-
return offset(timeInterval(unit), date, step);
|
|
629
|
-
}
|
|
630
|
-
function utcOffset(unit, date, step) {
|
|
631
|
-
return offset(utcInterval(unit), date, step);
|
|
632
|
-
}
|
|
633
|
-
function sequence(ival, start, stop, step) {
|
|
634
|
-
return ival ? ival.range(start, stop, step) : undefined;
|
|
635
|
-
}
|
|
636
|
-
function timeSequence(unit, start, stop, step) {
|
|
637
|
-
return sequence(timeInterval(unit), start, stop, step);
|
|
638
|
-
}
|
|
639
|
-
function utcSequence(unit, start, stop, step) {
|
|
640
|
-
return sequence(utcInterval(unit), start, stop, step);
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
const durationSecond = 1000,
|
|
644
|
-
durationMinute = durationSecond * 60,
|
|
645
|
-
durationHour = durationMinute * 60,
|
|
646
|
-
durationDay = durationHour * 24,
|
|
647
|
-
durationWeek = durationDay * 7,
|
|
648
|
-
durationMonth = durationDay * 30,
|
|
649
|
-
durationYear = durationDay * 365;
|
|
650
|
-
const Milli = [YEAR, MONTH, DATE, HOURS, MINUTES, SECONDS, MILLISECONDS],
|
|
651
|
-
Seconds = Milli.slice(0, -1),
|
|
652
|
-
Minutes = Seconds.slice(0, -1),
|
|
653
|
-
Hours = Minutes.slice(0, -1),
|
|
654
|
-
Day = Hours.slice(0, -1),
|
|
655
|
-
Week = [YEAR, WEEK],
|
|
656
|
-
Month = [YEAR, MONTH],
|
|
657
|
-
Year = [YEAR];
|
|
658
|
-
const intervals = [[Seconds, 1, durationSecond], [Seconds, 5, 5 * durationSecond], [Seconds, 15, 15 * durationSecond], [Seconds, 30, 30 * durationSecond], [Minutes, 1, durationMinute], [Minutes, 5, 5 * durationMinute], [Minutes, 15, 15 * durationMinute], [Minutes, 30, 30 * durationMinute], [Hours, 1, durationHour], [Hours, 3, 3 * durationHour], [Hours, 6, 6 * durationHour], [Hours, 12, 12 * durationHour], [Day, 1, durationDay], [Week, 1, durationWeek], [Month, 1, durationMonth], [Month, 3, 3 * durationMonth], [Year, 1, durationYear]];
|
|
659
|
-
function bin (opt) {
|
|
660
|
-
const ext = opt.extent,
|
|
661
|
-
max = opt.maxbins || 40,
|
|
662
|
-
target = Math.abs(vegaUtil.span(ext)) / max;
|
|
663
|
-
let i = bisector(i => i[2]).right(intervals, target),
|
|
664
|
-
units,
|
|
665
|
-
step;
|
|
666
|
-
if (i === intervals.length) {
|
|
667
|
-
units = Year, step = tickStep(ext[0] / durationYear, ext[1] / durationYear, max);
|
|
668
|
-
} else if (i) {
|
|
669
|
-
i = intervals[target / intervals[i - 1][2] < intervals[i][2] / target ? i - 1 : i];
|
|
670
|
-
units = i[0];
|
|
671
|
-
step = i[1];
|
|
672
|
-
} else {
|
|
673
|
-
units = Milli;
|
|
674
|
-
step = Math.max(tickStep(ext[0], ext[1], max), 1);
|
|
675
|
-
}
|
|
676
|
-
return {
|
|
677
|
-
units,
|
|
678
|
-
step
|
|
679
|
-
};
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
exports.DATE = DATE;
|
|
683
|
-
exports.DAY = DAY;
|
|
684
|
-
exports.DAYOFYEAR = DAYOFYEAR;
|
|
685
|
-
exports.HOURS = HOURS;
|
|
686
|
-
exports.MILLISECONDS = MILLISECONDS;
|
|
687
|
-
exports.MINUTES = MINUTES;
|
|
688
|
-
exports.MONTH = MONTH;
|
|
689
|
-
exports.QUARTER = QUARTER;
|
|
690
|
-
exports.SECONDS = SECONDS;
|
|
691
|
-
exports.TIME_UNITS = TIME_UNITS;
|
|
692
|
-
exports.WEEK = WEEK;
|
|
693
|
-
exports.YEAR = YEAR;
|
|
694
|
-
exports.dayofyear = dayofyear;
|
|
695
|
-
exports.timeBin = bin;
|
|
696
|
-
exports.timeFloor = timeFloor;
|
|
697
|
-
exports.timeInterval = timeInterval;
|
|
698
|
-
exports.timeOffset = timeOffset;
|
|
699
|
-
exports.timeSequence = timeSequence;
|
|
700
|
-
exports.timeUnitSpecifier = timeUnitSpecifier;
|
|
701
|
-
exports.timeUnits = timeUnits;
|
|
702
|
-
exports.utcFloor = utcFloor;
|
|
703
|
-
exports.utcInterval = utcInterval;
|
|
704
|
-
exports.utcOffset = utcOffset;
|
|
705
|
-
exports.utcSequence = utcSequence;
|
|
706
|
-
exports.utcdayofyear = utcdayofyear;
|
|
707
|
-
exports.utcweek = utcweek;
|
|
708
|
-
exports.week = week;
|
|
304
|
+
}
|
|
709
305
|
|
|
710
|
-
}
|
|
306
|
+
export { DATE, DAY, DAYOFYEAR, HOURS, MILLISECONDS, MINUTES, MONTH, QUARTER, SECONDS, TIME_UNITS, WEEK, YEAR, dayofyear, bin as timeBin, timeFloor, timeInterval, timeOffset, timeSequence, timeUnitSpecifier, timeUnits, utcFloor, utcInterval, utcOffset, utcSequence, utcdayofyear, utcweek, week };
|
|
307
|
+
//# sourceMappingURL=vega-time.js.map
|