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