123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422 |
- // https://d3js.org/d3-time/ v3.0.0 Copyright 2010-2021 Mike Bostock
- (function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-array')) :
- typeof define === 'function' && define.amd ? define(['exports', 'd3-array'], factory) :
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}, global.d3));
- }(this, (function (exports, d3Array) { 'use strict';
- var t0 = new Date,
- t1 = new Date;
- function newInterval(floori, offseti, count, field) {
- function interval(date) {
- return floori(date = arguments.length === 0 ? new Date : new Date(+date)), date;
- }
- interval.floor = function(date) {
- return floori(date = new Date(+date)), date;
- };
- interval.ceil = function(date) {
- return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
- };
- interval.round = function(date) {
- var d0 = interval(date),
- d1 = interval.ceil(date);
- return date - d0 < d1 - date ? d0 : d1;
- };
- interval.offset = function(date, step) {
- return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
- };
- interval.range = function(start, stop, step) {
- var range = [], previous;
- start = interval.ceil(start);
- step = step == null ? 1 : Math.floor(step);
- if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
- do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
- while (previous < start && start < stop);
- return range;
- };
- interval.filter = function(test) {
- return newInterval(function(date) {
- if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
- }, function(date, step) {
- if (date >= date) {
- if (step < 0) while (++step <= 0) {
- while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
- } else while (--step >= 0) {
- while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
- }
- }
- });
- };
- if (count) {
- interval.count = function(start, end) {
- t0.setTime(+start), t1.setTime(+end);
- floori(t0), floori(t1);
- return Math.floor(count(t0, t1));
- };
- interval.every = function(step) {
- step = Math.floor(step);
- return !isFinite(step) || !(step > 0) ? null
- : !(step > 1) ? interval
- : interval.filter(field
- ? function(d) { return field(d) % step === 0; }
- : function(d) { return interval.count(0, d) % step === 0; });
- };
- }
- return interval;
- }
- var millisecond = newInterval(function() {
- // noop
- }, function(date, step) {
- date.setTime(+date + step);
- }, function(start, end) {
- return end - start;
- });
- // An optimized implementation for this simple case.
- millisecond.every = function(k) {
- k = Math.floor(k);
- if (!isFinite(k) || !(k > 0)) return null;
- if (!(k > 1)) return millisecond;
- return newInterval(function(date) {
- date.setTime(Math.floor(date / k) * k);
- }, function(date, step) {
- date.setTime(+date + step * k);
- }, function(start, end) {
- return (end - start) / k;
- });
- };
- var milliseconds = millisecond.range;
- const durationSecond = 1000;
- const durationMinute = durationSecond * 60;
- const durationHour = durationMinute * 60;
- const durationDay = durationHour * 24;
- const durationWeek = durationDay * 7;
- const durationMonth = durationDay * 30;
- const durationYear = durationDay * 365;
- var second = newInterval(function(date) {
- date.setTime(date - date.getMilliseconds());
- }, function(date, step) {
- date.setTime(+date + step * durationSecond);
- }, function(start, end) {
- return (end - start) / durationSecond;
- }, function(date) {
- return date.getUTCSeconds();
- });
- var seconds = second.range;
- var minute = newInterval(function(date) {
- date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond);
- }, function(date, step) {
- date.setTime(+date + step * durationMinute);
- }, function(start, end) {
- return (end - start) / durationMinute;
- }, function(date) {
- return date.getMinutes();
- });
- var minutes = minute.range;
- var hour = newInterval(function(date) {
- date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond - date.getMinutes() * durationMinute);
- }, function(date, step) {
- date.setTime(+date + step * durationHour);
- }, function(start, end) {
- return (end - start) / durationHour;
- }, function(date) {
- return date.getHours();
- });
- var hours = hour.range;
- var day = newInterval(
- date => date.setHours(0, 0, 0, 0),
- (date, step) => date.setDate(date.getDate() + step),
- (start, end) => (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay,
- date => date.getDate() - 1
- );
- var days = day.range;
- function weekday(i) {
- return newInterval(function(date) {
- date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
- date.setHours(0, 0, 0, 0);
- }, function(date, step) {
- date.setDate(date.getDate() + step * 7);
- }, function(start, end) {
- return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
- });
- }
- var sunday = weekday(0);
- var monday = weekday(1);
- var tuesday = weekday(2);
- var wednesday = weekday(3);
- var thursday = weekday(4);
- var friday = weekday(5);
- var saturday = weekday(6);
- var sundays = sunday.range;
- var mondays = monday.range;
- var tuesdays = tuesday.range;
- var wednesdays = wednesday.range;
- var thursdays = thursday.range;
- var fridays = friday.range;
- var saturdays = saturday.range;
- var month = newInterval(function(date) {
- date.setDate(1);
- date.setHours(0, 0, 0, 0);
- }, function(date, step) {
- date.setMonth(date.getMonth() + step);
- }, function(start, end) {
- return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
- }, function(date) {
- return date.getMonth();
- });
- var months = month.range;
- var year = newInterval(function(date) {
- date.setMonth(0, 1);
- date.setHours(0, 0, 0, 0);
- }, function(date, step) {
- date.setFullYear(date.getFullYear() + step);
- }, function(start, end) {
- return end.getFullYear() - start.getFullYear();
- }, function(date) {
- return date.getFullYear();
- });
- // An optimized implementation for this simple case.
- year.every = function(k) {
- return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
- date.setFullYear(Math.floor(date.getFullYear() / k) * k);
- date.setMonth(0, 1);
- date.setHours(0, 0, 0, 0);
- }, function(date, step) {
- date.setFullYear(date.getFullYear() + step * k);
- });
- };
- var years = year.range;
- var utcMinute = newInterval(function(date) {
- date.setUTCSeconds(0, 0);
- }, function(date, step) {
- date.setTime(+date + step * durationMinute);
- }, function(start, end) {
- return (end - start) / durationMinute;
- }, function(date) {
- return date.getUTCMinutes();
- });
- var utcMinutes = utcMinute.range;
- var utcHour = newInterval(function(date) {
- date.setUTCMinutes(0, 0, 0);
- }, function(date, step) {
- date.setTime(+date + step * durationHour);
- }, function(start, end) {
- return (end - start) / durationHour;
- }, function(date) {
- return date.getUTCHours();
- });
- var utcHours = utcHour.range;
- var utcDay = newInterval(function(date) {
- date.setUTCHours(0, 0, 0, 0);
- }, function(date, step) {
- date.setUTCDate(date.getUTCDate() + step);
- }, function(start, end) {
- return (end - start) / durationDay;
- }, function(date) {
- return date.getUTCDate() - 1;
- });
- var utcDays = utcDay.range;
- function utcWeekday(i) {
- return newInterval(function(date) {
- date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
- date.setUTCHours(0, 0, 0, 0);
- }, function(date, step) {
- date.setUTCDate(date.getUTCDate() + step * 7);
- }, function(start, end) {
- return (end - start) / durationWeek;
- });
- }
- var utcSunday = utcWeekday(0);
- var utcMonday = utcWeekday(1);
- var utcTuesday = utcWeekday(2);
- var utcWednesday = utcWeekday(3);
- var utcThursday = utcWeekday(4);
- var utcFriday = utcWeekday(5);
- var utcSaturday = utcWeekday(6);
- var utcSundays = utcSunday.range;
- var utcMondays = utcMonday.range;
- var utcTuesdays = utcTuesday.range;
- var utcWednesdays = utcWednesday.range;
- var utcThursdays = utcThursday.range;
- var utcFridays = utcFriday.range;
- var utcSaturdays = utcSaturday.range;
- var utcMonth = newInterval(function(date) {
- date.setUTCDate(1);
- date.setUTCHours(0, 0, 0, 0);
- }, function(date, step) {
- date.setUTCMonth(date.getUTCMonth() + step);
- }, function(start, end) {
- return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
- }, function(date) {
- return date.getUTCMonth();
- });
- var utcMonths = utcMonth.range;
- var utcYear = newInterval(function(date) {
- date.setUTCMonth(0, 1);
- date.setUTCHours(0, 0, 0, 0);
- }, function(date, step) {
- date.setUTCFullYear(date.getUTCFullYear() + step);
- }, function(start, end) {
- return end.getUTCFullYear() - start.getUTCFullYear();
- }, function(date) {
- return date.getUTCFullYear();
- });
- // An optimized implementation for this simple case.
- utcYear.every = function(k) {
- return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
- date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
- date.setUTCMonth(0, 1);
- date.setUTCHours(0, 0, 0, 0);
- }, function(date, step) {
- date.setUTCFullYear(date.getUTCFullYear() + step * k);
- });
- };
- var utcYears = utcYear.range;
- function ticker(year, month, week, day, hour, minute) {
- const tickIntervals = [
- [second, 1, durationSecond],
- [second, 5, 5 * durationSecond],
- [second, 15, 15 * durationSecond],
- [second, 30, 30 * durationSecond],
- [minute, 1, durationMinute],
- [minute, 5, 5 * durationMinute],
- [minute, 15, 15 * durationMinute],
- [minute, 30, 30 * durationMinute],
- [ hour, 1, durationHour ],
- [ hour, 3, 3 * durationHour ],
- [ hour, 6, 6 * durationHour ],
- [ hour, 12, 12 * durationHour ],
- [ day, 1, durationDay ],
- [ day, 2, 2 * durationDay ],
- [ week, 1, durationWeek ],
- [ month, 1, durationMonth ],
- [ month, 3, 3 * durationMonth ],
- [ year, 1, durationYear ]
- ];
- function ticks(start, stop, count) {
- const reverse = stop < start;
- if (reverse) [start, stop] = [stop, start];
- const interval = count && typeof count.range === "function" ? count : tickInterval(start, stop, count);
- const ticks = interval ? interval.range(start, +stop + 1) : []; // inclusive stop
- return reverse ? ticks.reverse() : ticks;
- }
- function tickInterval(start, stop, count) {
- const target = Math.abs(stop - start) / count;
- const i = d3Array.bisector(([,, step]) => step).right(tickIntervals, target);
- if (i === tickIntervals.length) return year.every(d3Array.tickStep(start / durationYear, stop / durationYear, count));
- if (i === 0) return millisecond.every(Math.max(d3Array.tickStep(start, stop, count), 1));
- const [t, step] = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
- return t.every(step);
- }
- return [ticks, tickInterval];
- }
- const [utcTicks, utcTickInterval] = ticker(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute);
- const [timeTicks, timeTickInterval] = ticker(year, month, sunday, day, hour, minute);
- exports.timeDay = day;
- exports.timeDays = days;
- exports.timeFriday = friday;
- exports.timeFridays = fridays;
- exports.timeHour = hour;
- exports.timeHours = hours;
- exports.timeInterval = newInterval;
- exports.timeMillisecond = millisecond;
- exports.timeMilliseconds = milliseconds;
- exports.timeMinute = minute;
- exports.timeMinutes = minutes;
- exports.timeMonday = monday;
- exports.timeMondays = mondays;
- exports.timeMonth = month;
- exports.timeMonths = months;
- exports.timeSaturday = saturday;
- exports.timeSaturdays = saturdays;
- exports.timeSecond = second;
- exports.timeSeconds = seconds;
- exports.timeSunday = sunday;
- exports.timeSundays = sundays;
- exports.timeThursday = thursday;
- exports.timeThursdays = thursdays;
- exports.timeTickInterval = timeTickInterval;
- exports.timeTicks = timeTicks;
- exports.timeTuesday = tuesday;
- exports.timeTuesdays = tuesdays;
- exports.timeWednesday = wednesday;
- exports.timeWednesdays = wednesdays;
- exports.timeWeek = sunday;
- exports.timeWeeks = sundays;
- exports.timeYear = year;
- exports.timeYears = years;
- exports.utcDay = utcDay;
- exports.utcDays = utcDays;
- exports.utcFriday = utcFriday;
- exports.utcFridays = utcFridays;
- exports.utcHour = utcHour;
- exports.utcHours = utcHours;
- exports.utcMillisecond = millisecond;
- exports.utcMilliseconds = milliseconds;
- exports.utcMinute = utcMinute;
- exports.utcMinutes = utcMinutes;
- exports.utcMonday = utcMonday;
- exports.utcMondays = utcMondays;
- exports.utcMonth = utcMonth;
- exports.utcMonths = utcMonths;
- exports.utcSaturday = utcSaturday;
- exports.utcSaturdays = utcSaturdays;
- exports.utcSecond = second;
- exports.utcSeconds = seconds;
- exports.utcSunday = utcSunday;
- exports.utcSundays = utcSundays;
- exports.utcThursday = utcThursday;
- exports.utcThursdays = utcThursdays;
- exports.utcTickInterval = utcTickInterval;
- exports.utcTicks = utcTicks;
- exports.utcTuesday = utcTuesday;
- exports.utcTuesdays = utcTuesdays;
- exports.utcWednesday = utcWednesday;
- exports.utcWednesdays = utcWednesdays;
- exports.utcWeek = utcSunday;
- exports.utcWeeks = utcSundays;
- exports.utcYear = utcYear;
- exports.utcYears = utcYears;
- Object.defineProperty(exports, '__esModule', { value: true });
- })));
|