vega-time 2.1.0 → 2.1.2
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 -264
- 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,87 @@
|
|
|
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
|
-
|
|
135
121
|
if (count) {
|
|
136
|
-
interval.count =
|
|
122
|
+
interval.count = (start, end) => {
|
|
137
123
|
t0$1.setTime(+start), t1.setTime(+end);
|
|
138
124
|
floori(t0$1), floori(t1);
|
|
139
125
|
return Math.floor(count(t0$1, t1));
|
|
140
126
|
};
|
|
141
|
-
|
|
142
|
-
interval.every = function (step) {
|
|
127
|
+
interval.every = step => {
|
|
143
128
|
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
|
-
});
|
|
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);
|
|
149
130
|
};
|
|
150
131
|
}
|
|
151
|
-
|
|
152
132
|
return interval;
|
|
153
133
|
}
|
|
154
134
|
|
|
155
|
-
|
|
156
|
-
|
|
135
|
+
const millisecond = timeInterval$1(() => {
|
|
136
|
+
// noop
|
|
137
|
+
}, (date, step) => {
|
|
157
138
|
date.setTime(+date + step);
|
|
158
|
-
},
|
|
139
|
+
}, (start, end) => {
|
|
159
140
|
return end - start;
|
|
160
|
-
});
|
|
141
|
+
});
|
|
161
142
|
|
|
162
|
-
|
|
143
|
+
// An optimized implementation for this simple case.
|
|
144
|
+
millisecond.every = k => {
|
|
163
145
|
k = Math.floor(k);
|
|
164
146
|
if (!isFinite(k) || !(k > 0)) return null;
|
|
165
147
|
if (!(k > 1)) return millisecond;
|
|
166
|
-
return
|
|
148
|
+
return timeInterval$1(date => {
|
|
167
149
|
date.setTime(Math.floor(date / k) * k);
|
|
168
|
-
},
|
|
150
|
+
}, (date, step) => {
|
|
169
151
|
date.setTime(+date + step * k);
|
|
170
|
-
},
|
|
152
|
+
}, (start, end) => {
|
|
171
153
|
return (end - start) / k;
|
|
172
154
|
});
|
|
173
155
|
};
|
|
174
|
-
|
|
175
|
-
var utcMillisecond = millisecond;
|
|
156
|
+
millisecond.range;
|
|
176
157
|
|
|
177
158
|
const durationSecond$1 = 1000;
|
|
178
159
|
const durationMinute$1 = durationSecond$1 * 60;
|
|
@@ -180,251 +161,296 @@
|
|
|
180
161
|
const durationDay$1 = durationHour$1 * 24;
|
|
181
162
|
const durationWeek$1 = durationDay$1 * 7;
|
|
182
163
|
|
|
183
|
-
|
|
164
|
+
const second = timeInterval$1(date => {
|
|
184
165
|
date.setTime(date - date.getMilliseconds());
|
|
185
|
-
},
|
|
166
|
+
}, (date, step) => {
|
|
186
167
|
date.setTime(+date + step * durationSecond$1);
|
|
187
|
-
},
|
|
168
|
+
}, (start, end) => {
|
|
188
169
|
return (end - start) / durationSecond$1;
|
|
189
|
-
},
|
|
170
|
+
}, date => {
|
|
190
171
|
return date.getUTCSeconds();
|
|
191
172
|
});
|
|
192
|
-
|
|
173
|
+
second.range;
|
|
193
174
|
|
|
194
|
-
|
|
175
|
+
const timeMinute = timeInterval$1(date => {
|
|
195
176
|
date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond$1);
|
|
196
|
-
},
|
|
177
|
+
}, (date, step) => {
|
|
197
178
|
date.setTime(+date + step * durationMinute$1);
|
|
198
|
-
},
|
|
179
|
+
}, (start, end) => {
|
|
199
180
|
return (end - start) / durationMinute$1;
|
|
200
|
-
},
|
|
181
|
+
}, date => {
|
|
201
182
|
return date.getMinutes();
|
|
202
183
|
});
|
|
203
|
-
|
|
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;
|
|
204
195
|
|
|
205
|
-
|
|
196
|
+
const timeHour = timeInterval$1(date => {
|
|
206
197
|
date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond$1 - date.getMinutes() * durationMinute$1);
|
|
207
|
-
},
|
|
198
|
+
}, (date, step) => {
|
|
208
199
|
date.setTime(+date + step * durationHour$1);
|
|
209
|
-
},
|
|
200
|
+
}, (start, end) => {
|
|
210
201
|
return (end - start) / durationHour$1;
|
|
211
|
-
},
|
|
202
|
+
}, date => {
|
|
212
203
|
return date.getHours();
|
|
213
204
|
});
|
|
214
|
-
|
|
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;
|
|
215
216
|
|
|
216
|
-
|
|
217
|
-
|
|
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;
|
|
218
239
|
|
|
219
|
-
function
|
|
220
|
-
return
|
|
240
|
+
function timeWeekday(i) {
|
|
241
|
+
return timeInterval$1(date => {
|
|
221
242
|
date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
|
|
222
243
|
date.setHours(0, 0, 0, 0);
|
|
223
|
-
},
|
|
244
|
+
}, (date, step) => {
|
|
224
245
|
date.setDate(date.getDate() + step * 7);
|
|
225
|
-
},
|
|
246
|
+
}, (start, end) => {
|
|
226
247
|
return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute$1) / durationWeek$1;
|
|
227
248
|
});
|
|
228
249
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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 => {
|
|
239
290
|
date.setDate(1);
|
|
240
291
|
date.setHours(0, 0, 0, 0);
|
|
241
|
-
},
|
|
292
|
+
}, (date, step) => {
|
|
242
293
|
date.setMonth(date.getMonth() + step);
|
|
243
|
-
},
|
|
294
|
+
}, (start, end) => {
|
|
244
295
|
return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
|
|
245
|
-
},
|
|
296
|
+
}, date => {
|
|
246
297
|
return date.getMonth();
|
|
247
298
|
});
|
|
248
|
-
|
|
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;
|
|
249
311
|
|
|
250
|
-
|
|
312
|
+
const timeYear = timeInterval$1(date => {
|
|
251
313
|
date.setMonth(0, 1);
|
|
252
314
|
date.setHours(0, 0, 0, 0);
|
|
253
|
-
},
|
|
315
|
+
}, (date, step) => {
|
|
254
316
|
date.setFullYear(date.getFullYear() + step);
|
|
255
|
-
},
|
|
317
|
+
}, (start, end) => {
|
|
256
318
|
return end.getFullYear() - start.getFullYear();
|
|
257
|
-
},
|
|
319
|
+
}, date => {
|
|
258
320
|
return date.getFullYear();
|
|
259
|
-
});
|
|
321
|
+
});
|
|
260
322
|
|
|
261
|
-
|
|
262
|
-
|
|
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 => {
|
|
263
326
|
date.setFullYear(Math.floor(date.getFullYear() / k) * k);
|
|
264
327
|
date.setMonth(0, 1);
|
|
265
328
|
date.setHours(0, 0, 0, 0);
|
|
266
|
-
},
|
|
329
|
+
}, (date, step) => {
|
|
267
330
|
date.setFullYear(date.getFullYear() + step * k);
|
|
268
331
|
});
|
|
269
332
|
};
|
|
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) {
|
|
333
|
+
timeYear.range;
|
|
334
|
+
const utcYear = timeInterval$1(date => {
|
|
338
335
|
date.setUTCMonth(0, 1);
|
|
339
336
|
date.setUTCHours(0, 0, 0, 0);
|
|
340
|
-
},
|
|
337
|
+
}, (date, step) => {
|
|
341
338
|
date.setUTCFullYear(date.getUTCFullYear() + step);
|
|
342
|
-
},
|
|
339
|
+
}, (start, end) => {
|
|
343
340
|
return end.getUTCFullYear() - start.getUTCFullYear();
|
|
344
|
-
},
|
|
341
|
+
}, date => {
|
|
345
342
|
return date.getUTCFullYear();
|
|
346
|
-
});
|
|
343
|
+
});
|
|
347
344
|
|
|
348
|
-
|
|
349
|
-
|
|
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 => {
|
|
350
348
|
date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
|
|
351
349
|
date.setUTCMonth(0, 1);
|
|
352
350
|
date.setUTCHours(0, 0, 0, 0);
|
|
353
|
-
},
|
|
351
|
+
}, (date, step) => {
|
|
354
352
|
date.setUTCFullYear(date.getUTCFullYear() + step * k);
|
|
355
353
|
});
|
|
356
354
|
};
|
|
357
|
-
|
|
358
|
-
var utcYear$1 = utcYear;
|
|
355
|
+
utcYear.range;
|
|
359
356
|
|
|
360
357
|
function ascending(a, b) {
|
|
361
358
|
return a == null || b == null ? NaN : a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
|
|
362
359
|
}
|
|
363
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
|
+
|
|
364
365
|
function bisector(f) {
|
|
365
|
-
let
|
|
366
|
-
let compare1 = f;
|
|
367
|
-
let compare2 = f;
|
|
366
|
+
let compare1, compare2, delta;
|
|
368
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.
|
|
369
373
|
if (f.length !== 2) {
|
|
370
|
-
delta = (d, x) => f(d) - x;
|
|
371
|
-
|
|
372
374
|
compare1 = ascending;
|
|
373
|
-
|
|
374
375
|
compare2 = (d, x) => ascending(f(d), x);
|
|
376
|
+
delta = (d, x) => f(d) - x;
|
|
377
|
+
} else {
|
|
378
|
+
compare1 = f === ascending || f === descending ? f : zero;
|
|
379
|
+
compare2 = f;
|
|
380
|
+
delta = f;
|
|
375
381
|
}
|
|
376
|
-
|
|
377
382
|
function left(a, x, lo = 0, hi = a.length) {
|
|
378
383
|
if (lo < hi) {
|
|
379
384
|
if (compare1(x, x) !== 0) return hi;
|
|
380
|
-
|
|
381
385
|
do {
|
|
382
386
|
const mid = lo + hi >>> 1;
|
|
383
387
|
if (compare2(a[mid], x) < 0) lo = mid + 1;else hi = mid;
|
|
384
388
|
} while (lo < hi);
|
|
385
389
|
}
|
|
386
|
-
|
|
387
390
|
return lo;
|
|
388
391
|
}
|
|
389
|
-
|
|
390
392
|
function right(a, x, lo = 0, hi = a.length) {
|
|
391
393
|
if (lo < hi) {
|
|
392
394
|
if (compare1(x, x) !== 0) return hi;
|
|
393
|
-
|
|
394
395
|
do {
|
|
395
396
|
const mid = lo + hi >>> 1;
|
|
396
397
|
if (compare2(a[mid], x) <= 0) lo = mid + 1;else hi = mid;
|
|
397
398
|
} while (lo < hi);
|
|
398
399
|
}
|
|
399
|
-
|
|
400
400
|
return lo;
|
|
401
401
|
}
|
|
402
|
-
|
|
403
402
|
function center(a, x, lo = 0, hi = a.length) {
|
|
404
403
|
const i = left(a, x, lo, hi - 1);
|
|
405
404
|
return i > lo && delta(a[i - 1], x) > -delta(a[i], x) ? i - 1 : i;
|
|
406
405
|
}
|
|
407
|
-
|
|
408
406
|
return {
|
|
409
407
|
left,
|
|
410
408
|
center,
|
|
411
409
|
right
|
|
412
410
|
};
|
|
413
411
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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
|
+
}
|
|
418
446
|
function tickStep(start, stop, count) {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
return stop < start ? -step1 : step1;
|
|
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);
|
|
424
451
|
}
|
|
425
452
|
|
|
426
453
|
const t0 = new Date();
|
|
427
|
-
|
|
428
454
|
function localYear(y) {
|
|
429
455
|
t0.setFullYear(y);
|
|
430
456
|
t0.setMonth(0);
|
|
@@ -432,7 +458,6 @@
|
|
|
432
458
|
t0.setHours(0, 0, 0, 0);
|
|
433
459
|
return t0;
|
|
434
460
|
}
|
|
435
|
-
|
|
436
461
|
function dayofyear(d) {
|
|
437
462
|
return localDayOfYear(new Date(d));
|
|
438
463
|
}
|
|
@@ -443,7 +468,7 @@
|
|
|
443
468
|
return timeDay.count(localYear(d.getFullYear()) - 1, d);
|
|
444
469
|
}
|
|
445
470
|
function localWeekNum(d) {
|
|
446
|
-
return
|
|
471
|
+
return timeSunday.count(localYear(d.getFullYear()) - 1, d);
|
|
447
472
|
}
|
|
448
473
|
function localFirst(y) {
|
|
449
474
|
return localYear(y).getDay();
|
|
@@ -454,7 +479,6 @@
|
|
|
454
479
|
date.setFullYear(y);
|
|
455
480
|
return date;
|
|
456
481
|
}
|
|
457
|
-
|
|
458
482
|
return new Date(y, m, d, H, M, S, L);
|
|
459
483
|
}
|
|
460
484
|
function utcdayofyear(d) {
|
|
@@ -465,7 +489,7 @@
|
|
|
465
489
|
}
|
|
466
490
|
function utcDayOfYear(d) {
|
|
467
491
|
const y = Date.UTC(d.getUTCFullYear(), 0, 1);
|
|
468
|
-
return utcDay
|
|
492
|
+
return utcDay.count(y - 1, d);
|
|
469
493
|
}
|
|
470
494
|
function utcWeekNum(d) {
|
|
471
495
|
const y = Date.UTC(d.getUTCFullYear(), 0, 1);
|
|
@@ -481,45 +505,43 @@
|
|
|
481
505
|
date.setUTCFullYear(d.y);
|
|
482
506
|
return date;
|
|
483
507
|
}
|
|
484
|
-
|
|
485
508
|
return new Date(Date.UTC(y, m, d, H, M, S, L));
|
|
486
509
|
}
|
|
487
510
|
|
|
488
511
|
function floor(units, step, get, inv, newDate) {
|
|
489
512
|
const s = step || 1,
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
513
|
+
b = vegaUtil.peek(units),
|
|
514
|
+
_ = (unit, p, key) => {
|
|
515
|
+
key = key || unit;
|
|
516
|
+
return getUnit(get[key], inv[key], unit === b && s, p);
|
|
517
|
+
};
|
|
496
518
|
const t = new Date(),
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
519
|
+
u = vegaUtil.toSet(units),
|
|
520
|
+
y = u[YEAR] ? _(YEAR) : vegaUtil.constant(2012),
|
|
521
|
+
m = u[MONTH] ? _(MONTH) : u[QUARTER] ? _(QUARTER) : vegaUtil.zero,
|
|
522
|
+
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,
|
|
523
|
+
H = u[HOURS] ? _(HOURS) : vegaUtil.zero,
|
|
524
|
+
M = u[MINUTES] ? _(MINUTES) : vegaUtil.zero,
|
|
525
|
+
S = u[SECONDS] ? _(SECONDS) : vegaUtil.zero,
|
|
526
|
+
L = u[MILLISECONDS] ? _(MILLISECONDS) : vegaUtil.zero;
|
|
505
527
|
return function (v) {
|
|
506
528
|
t.setTime(+v);
|
|
507
529
|
const year = y(t);
|
|
508
530
|
return newDate(year, m(t), d(t, year), H(t), M(t), S(t), L(t));
|
|
509
531
|
};
|
|
510
532
|
}
|
|
511
|
-
|
|
512
533
|
function getUnit(f, inv, step, phase) {
|
|
513
534
|
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
535
|
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
|
-
|
|
536
|
+
}
|
|
518
537
|
|
|
538
|
+
// returns the day of the year based on week number, day of week,
|
|
539
|
+
// and the day of the week for the first day of the year
|
|
519
540
|
function weekday(week, day, firstDay) {
|
|
520
541
|
return day + week * 7 - (firstDay + 6) % 7;
|
|
521
|
-
}
|
|
542
|
+
}
|
|
522
543
|
|
|
544
|
+
// -- LOCAL TIME --
|
|
523
545
|
|
|
524
546
|
const localGet = {
|
|
525
547
|
[YEAR]: d => d.getFullYear(),
|
|
@@ -541,7 +563,9 @@
|
|
|
541
563
|
};
|
|
542
564
|
function timeFloor(units, step) {
|
|
543
565
|
return floor(units, step || 1, localGet, localInv, localDate);
|
|
544
|
-
}
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// -- UTC TIME --
|
|
545
569
|
|
|
546
570
|
const utcGet = {
|
|
547
571
|
[YEAR]: d => d.getUTCFullYear(),
|
|
@@ -569,27 +593,27 @@
|
|
|
569
593
|
[YEAR]: timeYear,
|
|
570
594
|
[QUARTER]: timeMonth.every(3),
|
|
571
595
|
[MONTH]: timeMonth,
|
|
572
|
-
[WEEK]:
|
|
596
|
+
[WEEK]: timeSunday,
|
|
573
597
|
[DATE]: timeDay,
|
|
574
598
|
[DAY]: timeDay,
|
|
575
599
|
[DAYOFYEAR]: timeDay,
|
|
576
600
|
[HOURS]: timeHour,
|
|
577
601
|
[MINUTES]: timeMinute,
|
|
578
|
-
[SECONDS]:
|
|
579
|
-
[MILLISECONDS]:
|
|
602
|
+
[SECONDS]: second,
|
|
603
|
+
[MILLISECONDS]: millisecond
|
|
580
604
|
};
|
|
581
605
|
const utcIntervals = {
|
|
582
|
-
[YEAR]: utcYear
|
|
583
|
-
[QUARTER]: utcMonth
|
|
584
|
-
[MONTH]: utcMonth
|
|
606
|
+
[YEAR]: utcYear,
|
|
607
|
+
[QUARTER]: utcMonth.every(3),
|
|
608
|
+
[MONTH]: utcMonth,
|
|
585
609
|
[WEEK]: utcSunday,
|
|
586
|
-
[DATE]: utcDay
|
|
587
|
-
[DAY]: utcDay
|
|
588
|
-
[DAYOFYEAR]: utcDay
|
|
589
|
-
[HOURS]: utcHour
|
|
590
|
-
[MINUTES]: utcMinute
|
|
591
|
-
[SECONDS]:
|
|
592
|
-
[MILLISECONDS]:
|
|
610
|
+
[DATE]: utcDay,
|
|
611
|
+
[DAY]: utcDay,
|
|
612
|
+
[DAYOFYEAR]: utcDay,
|
|
613
|
+
[HOURS]: utcHour,
|
|
614
|
+
[MINUTES]: utcMinute,
|
|
615
|
+
[SECONDS]: second,
|
|
616
|
+
[MILLISECONDS]: millisecond
|
|
593
617
|
};
|
|
594
618
|
function timeInterval(unit) {
|
|
595
619
|
return timeIntervals[unit];
|
|
@@ -597,22 +621,18 @@
|
|
|
597
621
|
function utcInterval(unit) {
|
|
598
622
|
return utcIntervals[unit];
|
|
599
623
|
}
|
|
600
|
-
|
|
601
624
|
function offset(ival, date, step) {
|
|
602
625
|
return ival ? ival.offset(date, step) : undefined;
|
|
603
626
|
}
|
|
604
|
-
|
|
605
627
|
function timeOffset(unit, date, step) {
|
|
606
628
|
return offset(timeInterval(unit), date, step);
|
|
607
629
|
}
|
|
608
630
|
function utcOffset(unit, date, step) {
|
|
609
631
|
return offset(utcInterval(unit), date, step);
|
|
610
632
|
}
|
|
611
|
-
|
|
612
633
|
function sequence(ival, start, stop, step) {
|
|
613
634
|
return ival ? ival.range(start, stop, step) : undefined;
|
|
614
635
|
}
|
|
615
|
-
|
|
616
636
|
function timeSequence(unit, start, stop, step) {
|
|
617
637
|
return sequence(timeInterval(unit), start, stop, step);
|
|
618
638
|
}
|
|
@@ -621,29 +641,28 @@
|
|
|
621
641
|
}
|
|
622
642
|
|
|
623
643
|
const durationSecond = 1000,
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
644
|
+
durationMinute = durationSecond * 60,
|
|
645
|
+
durationHour = durationMinute * 60,
|
|
646
|
+
durationDay = durationHour * 24,
|
|
647
|
+
durationWeek = durationDay * 7,
|
|
648
|
+
durationMonth = durationDay * 30,
|
|
649
|
+
durationYear = durationDay * 365;
|
|
630
650
|
const Milli = [YEAR, MONTH, DATE, HOURS, MINUTES, SECONDS, MILLISECONDS],
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
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];
|
|
638
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]];
|
|
639
659
|
function bin (opt) {
|
|
640
660
|
const ext = opt.extent,
|
|
641
|
-
|
|
642
|
-
|
|
661
|
+
max = opt.maxbins || 40,
|
|
662
|
+
target = Math.abs(vegaUtil.span(ext)) / max;
|
|
643
663
|
let i = bisector(i => i[2]).right(intervals, target),
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
664
|
+
units,
|
|
665
|
+
step;
|
|
647
666
|
if (i === intervals.length) {
|
|
648
667
|
units = Year, step = tickStep(ext[0] / durationYear, ext[1] / durationYear, max);
|
|
649
668
|
} else if (i) {
|
|
@@ -654,7 +673,6 @@
|
|
|
654
673
|
units = Milli;
|
|
655
674
|
step = Math.max(tickStep(ext[0], ext[1], max), 1);
|
|
656
675
|
}
|
|
657
|
-
|
|
658
676
|
return {
|
|
659
677
|
units,
|
|
660
678
|
step
|
|
@@ -689,6 +707,4 @@
|
|
|
689
707
|
exports.utcweek = utcweek;
|
|
690
708
|
exports.week = week;
|
|
691
709
|
|
|
692
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
693
|
-
|
|
694
710
|
}));
|