Comparing version 1.1.0 to 2.0.0
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vega-util'), require('d3-time'), require('d3-time-format'), require('d3-array')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'vega-util', 'd3-time', 'd3-time-format', 'd3-array'], factory) : | ||
(global = global || self, factory(global.vega = {}, global.vega, global.d3, global.d3, global.d3)); | ||
}(this, (function (exports, vegaUtil, d3Time, d3TimeFormat, d3Array) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vega-util'), require('d3-time'), require('d3-array')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'vega-util', 'd3-time', 'd3-array'], factory) : | ||
(global = global || self, factory(global.vega = {}, global.vega, global.d3, global.d3)); | ||
}(this, (function (exports, vegaUtil, d3Time, d3Array) { 'use strict'; | ||
@@ -66,2 +66,40 @@ const YEAR = 'year'; | ||
const defaultSpecifiers = { | ||
[YEAR]: '%Y ', | ||
[QUARTER]: 'Q%q ', | ||
[MONTH]: '%b ', | ||
[DATE]: '%d ', | ||
[WEEK]: 'W%U ', | ||
[DAY]: '%a ', | ||
[DAYOFYEAR]: '%j ', | ||
[HOURS]: '%H:00', | ||
[MINUTES]: '00:%M', | ||
[SECONDS]: ':%S', | ||
[MILLISECONDS]: '.%L', | ||
[`${YEAR}-${MONTH}`]: '%Y-%m ', | ||
[`${YEAR}-${MONTH}-${DATE}`]: '%Y-%m-%d ', | ||
[`${HOURS}-${MINUTES}`]: '%H:%M' | ||
}; | ||
function timeUnitSpecifier(units, specifiers) { | ||
const s = vegaUtil.extend({}, defaultSpecifiers, specifiers), | ||
u = timeUnits(units), | ||
n = u.length; | ||
let fmt = '', start = 0, end, key; | ||
for (start=0; start<n; ) { | ||
for (end=u.length; end > start; --end) { | ||
key = u.slice(start, end).join('-'); | ||
if (s[key] != null) { | ||
fmt += s[key]; | ||
start = end; | ||
break; | ||
} | ||
} | ||
} | ||
return fmt.trim(); | ||
} | ||
const t0 = new Date; | ||
@@ -295,89 +333,2 @@ | ||
const defaultSpecifiers = { | ||
[YEAR]: '%Y ', | ||
[QUARTER]: 'Q%q ', | ||
[MONTH]: '%b ', | ||
[DATE]: '%d ', | ||
[WEEK]: 'W%U ', | ||
[DAY]: '%a ', | ||
[DAYOFYEAR]: '%j ', | ||
[HOURS]: '%H:00', | ||
[MINUTES]: '00:%M', | ||
[SECONDS]: ':%S', | ||
[MILLISECONDS]: '.%L', | ||
[`${YEAR}-${MONTH}`]: '%Y-%m ', | ||
[`${YEAR}-${MONTH}-${DATE}`]: '%Y-%m-%d ', | ||
[`${HOURS}-${MINUTES}`]: '%H:%M' | ||
}; | ||
function timeUnitSpecifier(units, specifiers) { | ||
const s = vegaUtil.extend({}, defaultSpecifiers, specifiers), | ||
u = timeUnits(units), | ||
n = u.length; | ||
let fmt = '', start = 0, end, key; | ||
for (start=0; start<n; ) { | ||
for (end=u.length; end > start; --end) { | ||
key = u.slice(start, end).join('-'); | ||
if (s[key] != null) { | ||
fmt += s[key]; | ||
start = end; | ||
break; | ||
} | ||
} | ||
} | ||
return fmt.trim(); | ||
} | ||
function timeFormat(specifier) { | ||
return formatter(d3TimeFormat.timeFormat, timeInterval, specifier); | ||
} | ||
function utcFormat(specifier) { | ||
return formatter(d3TimeFormat.utcFormat, utcInterval, specifier); | ||
} | ||
function formatter(format, interval, specifier) { | ||
return vegaUtil.isString(specifier) | ||
? format(specifier) | ||
: multiFormat(format, interval, specifier); | ||
} | ||
function multiFormat(format, interval, spec) { | ||
spec = spec || {}; | ||
if (!vegaUtil.isObject(spec)) { | ||
vegaUtil.error(`Invalid time multi-format specifier: ${spec}`); | ||
} | ||
const second = interval(SECONDS), | ||
minute = interval(MINUTES), | ||
hour = interval(HOURS), | ||
day = interval(DATE), | ||
week = interval(WEEK), | ||
month = interval(MONTH), | ||
quarter = interval(QUARTER), | ||
year = interval(YEAR), | ||
L = format(spec[MILLISECONDS] || '.%L'), | ||
S = format(spec[SECONDS] || ':%S'), | ||
M = format(spec[MINUTES] || '%I:%M'), | ||
H = format(spec[HOURS] || '%I %p'), | ||
d = format(spec[DATE] || spec[DAY] || '%a %d'), | ||
w = format(spec[WEEK] || '%b %d'), | ||
m = format(spec[MONTH] || '%B'), | ||
q = format(spec[QUARTER] || '%B'), | ||
y = format(spec[YEAR] || '%Y'); | ||
return function(date) { | ||
return (second(date) < date ? L | ||
: minute(date) < date ? S | ||
: hour(date) < date ? M | ||
: day(date) < date ? H | ||
: month(date) < date ? (week(date) < date ? d : w) | ||
: year(date) < date ? (quarter(date) < date ? m : q) | ||
: y)(date); | ||
}; | ||
} | ||
const durationSecond = 1000, | ||
@@ -443,7 +394,17 @@ durationMinute = durationSecond * 60, | ||
exports.DATE = DATE; | ||
exports.DAY = DAY; | ||
exports.DAYOFYEAR = DAYOFYEAR; | ||
exports.HOURS = HOURS; | ||
exports.MILLISECONDS = MILLISECONDS; | ||
exports.MINUTES = MINUTES; | ||
exports.MONTH = MONTH; | ||
exports.QUARTER = QUARTER; | ||
exports.SECONDS = SECONDS; | ||
exports.TIME_UNITS = TIME_UNITS; | ||
exports.WEEK = WEEK; | ||
exports.YEAR = YEAR; | ||
exports.dayofyear = dayofyear; | ||
exports.timeBin = bin; | ||
exports.timeFloor = timeFloor; | ||
exports.timeFormat = timeFormat; | ||
exports.timeInterval = timeInterval; | ||
@@ -455,3 +416,2 @@ exports.timeOffset = timeOffset; | ||
exports.utcFloor = utcFloor; | ||
exports.utcFormat = utcFormat; | ||
exports.utcInterval = utcInterval; | ||
@@ -458,0 +418,0 @@ exports.utcOffset = utcOffset; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vega-util"),require("d3-time"),require("d3-time-format"),require("d3-array")):"function"==typeof define&&define.amd?define(["exports","vega-util","d3-time","d3-time-format","d3-array"],t):t((e=e||self).vega={},e.vega,e.d3,e.d3,e.d3)}(this,(function(e,t,n,r,o){"use strict";const i="year",u="quarter",a="month",c="week",s="date",f="day",l="hours",d="minutes",m="seconds",y=[i,u,a,c,s,f,"dayofyear",l,d,m,"milliseconds"],g=y.reduce((e,t,n)=>(e[t]=1+n,e),{});function D(e){const n=t.array(e).slice(),r={};return n.length||t.error("Missing time unit."),n.forEach(e=>{t.hasOwnProperty(g,e)?r[e]=1:t.error(`Invalid time unit: ${e}.`)}),(r[c]||r.day?1:0)+(r[u]||r[a]||r[s]?1:0)+(r.dayofyear?1:0)>1&&t.error("Incompatible time units: "+e),n.sort((e,t)=>g[e]-g[t]),n}const M=new Date;function h(e){return M.setFullYear(e),M.setMonth(0),M.setDate(1),M.setHours(0,0,0,0),M}function T(e){return n.timeDay.count(h(e.getFullYear())-1,e)}function U(e){return n.timeWeek.count(h(e.getFullYear())-1,e)}function C(e){return h(e).getDay()}function p(e,t,n,r,o,i,u){if(0<=e&&e<100){var a=new Date(-1,t,n,r,o,i,u);return a.setFullYear(e),a}return new Date(e,t,n,r,o,i,u)}function v(e){const t=Date.UTC(e.getUTCFullYear(),0,1);return n.utcDay.count(t-1,e)}function F(e){const t=Date.UTC(e.getUTCFullYear(),0,1);return n.utcWeek.count(t-1,e)}function Y(e){return M.setTime(Date.UTC(e,0,1)),M.getUTCDay()}function w(e,t,n,r,o,i,u){if(0<=e&&e<100){var a=new Date(Date.UTC(-1,t,n,r,o,i,u));return a.setUTCFullYear(n.y),a}return new Date(Date.UTC(e,t,n,r,o,i,u))}function S(e,n,r,o,y){const g=n||1,D=t.peek(e),M=(e,t,n)=>function(e,t,n,r){const o=n<=1?e:r?(t,o)=>r+n*Math.floor((e(t,o)-r)/n):(t,r)=>n*Math.floor(e(t,r)/n);return t?(e,n)=>t(o(e,n),n):o}(r[n=n||e],o[n],e===D&&g,t),h=new Date,T=t.toSet(e),U=T[i]?M(i):t.constant(2012),C=T[a]?M(a):T[u]?M(u):t.zero,p=T[c]&&T.day?M(f,1,c+f):T[c]?M(c,1):T.day?M(f,1):T[s]?M(s,1):T.dayofyear?M("dayofyear",1):t.one,v=T[l]?M(l):t.zero,F=T[d]?M(d):t.zero,Y=T[m]?M(m):t.zero,w=T.milliseconds?M("milliseconds"):t.zero;return function(e){h.setTime(+e);const t=U(h);return y(t,C(h),p(h,t),v(h),F(h),Y(h),w(h))}}function k(e,t,n){return t+7*e-(n+6)%7}const b={[i]:e=>e.getFullYear(),[u]:e=>Math.floor(e.getMonth()/3),[a]:e=>e.getMonth(),[s]:e=>e.getDate(),[l]:e=>e.getHours(),[d]:e=>e.getMinutes(),[m]:e=>e.getSeconds(),milliseconds:e=>e.getMilliseconds(),dayofyear:e=>T(e),[c]:e=>U(e),[c+f]:(e,t)=>k(U(e),e.getDay(),C(t)),[f]:(e,t)=>k(1,e.getDay(),C(t))},I={[u]:e=>3*e,[c]:(e,t)=>k(e,0,C(t))};const q={[i]:e=>e.getUTCFullYear(),[u]:e=>Math.floor(e.getUTCMonth()/3),[a]:e=>e.getUTCMonth(),[s]:e=>e.getUTCDate(),[l]:e=>e.getUTCHours(),[d]:e=>e.getUTCMinutes(),[m]:e=>e.getUTCSeconds(),milliseconds:e=>e.getUTCMilliseconds(),dayofyear:e=>v(e),[c]:e=>F(e),[f]:(e,t)=>k(1,e.getUTCDay(),Y(t)),[c+f]:(e,t)=>k(F(e),e.getUTCDay(),Y(t))},x={[u]:e=>3*e,[c]:(e,t)=>k(e,0,Y(t))};const H={[i]:n.timeYear,[u]:n.timeMonth.every(3),[a]:n.timeMonth,[c]:n.timeWeek,[s]:n.timeDay,[f]:n.timeDay,dayofyear:n.timeDay,[l]:n.timeHour,[d]:n.timeMinute,[m]:n.timeSecond,milliseconds:n.timeMillisecond},j={[i]:n.utcYear,[u]:n.utcMonth.every(3),[a]:n.utcMonth,[c]:n.utcWeek,[s]:n.utcDay,[f]:n.utcDay,dayofyear:n.utcDay,[l]:n.utcHour,[d]:n.utcMinute,[m]:n.utcSecond,milliseconds:n.utcMillisecond};function z(e){return H[e]}function O(e){return j[e]}function W(e,t,n){return e?e.offset(t,n):void 0}function B(e,t,n,r){return e?e.range(t,n,r):void 0}const _={[i]:"%Y ",[u]:"Q%q ",[a]:"%b ",[s]:"%d ",[c]:"W%U ",[f]:"%a ",dayofyear:"%j ",[l]:"%H:00",[d]:"00:%M",[m]:":%S",milliseconds:".%L","year-month":"%Y-%m ","year-month-date":"%Y-%m-%d ",["hours-"+d]:"%H:%M"};function E(e,n,r){return t.isString(r)?e(r):function(e,n,r){r=r||{},t.isObject(r)||t.error("Invalid time multi-format specifier: "+r);const o=n(m),f=n(d),y=n(l),g=n(s),D=n(c),M=n(a),h=n(u),T=n(i),U=e(r.milliseconds||".%L"),C=e(r[m]||":%S"),p=e(r[d]||"%I:%M"),v=e(r[l]||"%I %p"),F=e(r[s]||r.day||"%a %d"),Y=e(r[c]||"%b %d"),w=e(r[a]||"%B"),S=e(r[u]||"%B"),k=e(r[i]||"%Y");return function(e){return(o(e)<e?U:f(e)<e?C:y(e)<e?p:g(e)<e?v:M(e)<e?D(e)<e?F:Y:T(e)<e?h(e)<e?w:S:k)(e)}}(e,n,r)}const L=[i,a,s,l,d,m,"milliseconds"],P=L.slice(0,-1),N=P.slice(0,-1),Q=N.slice(0,-1),$=Q.slice(0,-1),A=[i,a],G=[i],J=[[P,1,1e3],[P,5,5e3],[P,15,15e3],[P,30,3e4],[N,1,6e4],[N,5,3e5],[N,15,9e5],[N,30,18e5],[Q,1,36e5],[Q,3,108e5],[Q,6,216e5],[Q,12,432e5],[$,1,864e5],[[i,c],1,6048e5],[A,1,2592e6],[A,3,7776e6],[G,1,31536e6]];e.TIME_UNITS=y,e.dayofyear=function(e){return T(new Date(e))},e.timeBin=function(e){const n=e.extent,r=e.maxbins||40,i=Math.abs(t.span(n))/r;let u,a,c=o.bisector(e=>e[2]).right(J,i);return c===J.length?(u=G,a=o.tickStep(n[0]/31536e6,n[1]/31536e6,r)):c?(c=J[i/J[c-1][2]<J[c][2]/i?c-1:c],u=c[0],a=c[1]):(u=L,a=Math.max(o.tickStep(n[0],n[1],r),1)),{units:u,step:a}},e.timeFloor=function(e,t){return S(e,t||1,b,I,p)},e.timeFormat=function(e){return E(r.timeFormat,z,e)},e.timeInterval=z,e.timeOffset=function(e,t,n){return W(z(e),t,n)},e.timeSequence=function(e,t,n,r){return B(z(e),t,n,r)},e.timeUnitSpecifier=function(e,n){const r=t.extend({},_,n),o=D(e),i=o.length;let u,a,c="",s=0;for(s=0;s<i;)for(u=o.length;u>s;--u)if(a=o.slice(s,u).join("-"),null!=r[a]){c+=r[a],s=u;break}return c.trim()},e.timeUnits=D,e.utcFloor=function(e,t){return S(e,t||1,q,x,w)},e.utcFormat=function(e){return E(r.utcFormat,O,e)},e.utcInterval=O,e.utcOffset=function(e,t,n){return W(O(e),t,n)},e.utcSequence=function(e,t,n,r){return B(O(e),t,n,r)},e.utcdayofyear=function(e){return v(new Date(e))},e.utcweek=function(e){return F(new Date(e))},e.week=function(e){return U(new Date(e))},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vega-util"),require("d3-time"),require("d3-array")):"function"==typeof define&&define.amd?define(["exports","vega-util","d3-time","d3-array"],t):t((e=e||self).vega={},e.vega,e.d3,e.d3)}(this,(function(e,t,n,r){"use strict";const o="year",i="quarter",u="month",a="week",c="date",s="day",l="hours",f="minutes",d="seconds",y=[o,i,u,a,c,s,"dayofyear",l,f,d,"milliseconds"],m=y.reduce((e,t,n)=>(e[t]=1+n,e),{});function g(e){const n=t.array(e).slice(),r={};return n.length||t.error("Missing time unit."),n.forEach(e=>{t.hasOwnProperty(m,e)?r[e]=1:t.error(`Invalid time unit: ${e}.`)}),(r[a]||r.day?1:0)+(r[i]||r[u]||r[c]?1:0)+(r.dayofyear?1:0)>1&&t.error("Incompatible time units: "+e),n.sort((e,t)=>m[e]-m[t]),n}const D={[o]:"%Y ",[i]:"Q%q ",[u]:"%b ",[c]:"%d ",[a]:"W%U ",[s]:"%a ",dayofyear:"%j ",[l]:"%H:00",[f]:"00:%M",[d]:":%S",milliseconds:".%L","year-month":"%Y-%m ","year-month-date":"%Y-%m-%d ",["hours-"+f]:"%H:%M"};const M=new Date;function h(e){return M.setFullYear(e),M.setMonth(0),M.setDate(1),M.setHours(0,0,0,0),M}function T(e){return n.timeDay.count(h(e.getFullYear())-1,e)}function U(e){return n.timeWeek.count(h(e.getFullYear())-1,e)}function C(e){return h(e).getDay()}function S(e,t,n,r,o,i,u){if(0<=e&&e<100){var a=new Date(-1,t,n,r,o,i,u);return a.setFullYear(e),a}return new Date(e,t,n,r,o,i,u)}function Y(e){const t=Date.UTC(e.getUTCFullYear(),0,1);return n.utcDay.count(t-1,e)}function p(e){const t=Date.UTC(e.getUTCFullYear(),0,1);return n.utcWeek.count(t-1,e)}function v(e){return M.setTime(Date.UTC(e,0,1)),M.getUTCDay()}function w(e,t,n,r,o,i,u){if(0<=e&&e<100){var a=new Date(Date.UTC(-1,t,n,r,o,i,u));return a.setUTCFullYear(n.y),a}return new Date(Date.UTC(e,t,n,r,o,i,u))}function F(e,n,r,y,m){const g=n||1,D=t.peek(e),M=(e,t,n)=>function(e,t,n,r){const o=n<=1?e:r?(t,o)=>r+n*Math.floor((e(t,o)-r)/n):(t,r)=>n*Math.floor(e(t,r)/n);return t?(e,n)=>t(o(e,n),n):o}(r[n=n||e],y[n],e===D&&g,t),h=new Date,T=t.toSet(e),U=T[o]?M(o):t.constant(2012),C=T[u]?M(u):T[i]?M(i):t.zero,S=T[a]&&T.day?M(s,1,a+s):T[a]?M(a,1):T.day?M(s,1):T[c]?M(c,1):T.dayofyear?M("dayofyear",1):t.one,Y=T[l]?M(l):t.zero,p=T[f]?M(f):t.zero,v=T[d]?M(d):t.zero,w=T.milliseconds?M("milliseconds"):t.zero;return function(e){h.setTime(+e);const t=U(h);return m(t,C(h),S(h,t),Y(h),p(h),v(h),w(h))}}function k(e,t,n){return t+7*e-(n+6)%7}const E={[o]:e=>e.getFullYear(),[i]:e=>Math.floor(e.getMonth()/3),[u]:e=>e.getMonth(),[c]:e=>e.getDate(),[l]:e=>e.getHours(),[f]:e=>e.getMinutes(),[d]:e=>e.getSeconds(),milliseconds:e=>e.getMilliseconds(),dayofyear:e=>T(e),[a]:e=>U(e),[a+s]:(e,t)=>k(U(e),e.getDay(),C(t)),[s]:(e,t)=>k(1,e.getDay(),C(t))},H={[i]:e=>3*e,[a]:(e,t)=>k(e,0,C(t))};const I={[o]:e=>e.getUTCFullYear(),[i]:e=>Math.floor(e.getUTCMonth()/3),[u]:e=>e.getUTCMonth(),[c]:e=>e.getUTCDate(),[l]:e=>e.getUTCHours(),[f]:e=>e.getUTCMinutes(),[d]:e=>e.getUTCSeconds(),milliseconds:e=>e.getUTCMilliseconds(),dayofyear:e=>Y(e),[a]:e=>p(e),[s]:(e,t)=>k(1,e.getUTCDay(),v(t)),[a+s]:(e,t)=>k(p(e),e.getUTCDay(),v(t))},O={[i]:e=>3*e,[a]:(e,t)=>k(e,0,v(t))};const b={[o]:n.timeYear,[i]:n.timeMonth.every(3),[u]:n.timeMonth,[a]:n.timeWeek,[c]:n.timeDay,[s]:n.timeDay,dayofyear:n.timeDay,[l]:n.timeHour,[f]:n.timeMinute,[d]:n.timeSecond,milliseconds:n.timeMillisecond},q={[o]:n.utcYear,[i]:n.utcMonth.every(3),[u]:n.utcMonth,[a]:n.utcWeek,[c]:n.utcDay,[s]:n.utcDay,dayofyear:n.utcDay,[l]:n.utcHour,[f]:n.utcMinute,[d]:n.utcSecond,milliseconds:n.utcMillisecond};function x(e){return b[e]}function A(e){return q[e]}function W(e,t,n){return e?e.offset(t,n):void 0}function z(e,t,n,r){return e?e.range(t,n,r):void 0}const N=[o,u,c,l,f,d,"milliseconds"],R=N.slice(0,-1),j=R.slice(0,-1),L=j.slice(0,-1),_=L.slice(0,-1),P=[o,u],Q=[o],B=[[R,1,1e3],[R,5,5e3],[R,15,15e3],[R,30,3e4],[j,1,6e4],[j,5,3e5],[j,15,9e5],[j,30,18e5],[L,1,36e5],[L,3,108e5],[L,6,216e5],[L,12,432e5],[_,1,864e5],[[o,a],1,6048e5],[P,1,2592e6],[P,3,7776e6],[Q,1,31536e6]];e.DATE=c,e.DAY=s,e.DAYOFYEAR="dayofyear",e.HOURS=l,e.MILLISECONDS="milliseconds",e.MINUTES=f,e.MONTH=u,e.QUARTER=i,e.SECONDS=d,e.TIME_UNITS=y,e.WEEK=a,e.YEAR=o,e.dayofyear=function(e){return T(new Date(e))},e.timeBin=function(e){const n=e.extent,o=e.maxbins||40,i=Math.abs(t.span(n))/o;let u,a,c=r.bisector(e=>e[2]).right(B,i);return c===B.length?(u=Q,a=r.tickStep(n[0]/31536e6,n[1]/31536e6,o)):c?(c=B[i/B[c-1][2]<B[c][2]/i?c-1:c],u=c[0],a=c[1]):(u=N,a=Math.max(r.tickStep(n[0],n[1],o),1)),{units:u,step:a}},e.timeFloor=function(e,t){return F(e,t||1,E,H,S)},e.timeInterval=x,e.timeOffset=function(e,t,n){return W(x(e),t,n)},e.timeSequence=function(e,t,n,r){return z(x(e),t,n,r)},e.timeUnitSpecifier=function(e,n){const r=t.extend({},D,n),o=g(e),i=o.length;let u,a,c="",s=0;for(s=0;s<i;)for(u=o.length;u>s;--u)if(a=o.slice(s,u).join("-"),null!=r[a]){c+=r[a],s=u;break}return c.trim()},e.timeUnits=g,e.utcFloor=function(e,t){return F(e,t||1,I,O,w)},e.utcInterval=A,e.utcOffset=function(e,t,n){return W(A(e),t,n)},e.utcSequence=function(e,t,n,r){return z(A(e),t,n,r)},e.utcdayofyear=function(e){return Y(new Date(e))},e.utcweek=function(e){return p(new Date(e))},e.week=function(e){return U(new Date(e))},Object.defineProperty(e,"__esModule",{value:!0})})); |
22
index.js
export { | ||
timeUnits, | ||
TIME_UNITS | ||
TIME_UNITS, | ||
YEAR, | ||
QUARTER, | ||
MONTH, | ||
WEEK, | ||
DATE, | ||
DAY, | ||
DAYOFYEAR, | ||
HOURS, | ||
MINUTES, | ||
SECONDS, | ||
MILLISECONDS, | ||
timeUnitSpecifier, | ||
timeUnits | ||
} from './src/units'; | ||
@@ -19,8 +31,2 @@ | ||
export { | ||
timeUnitSpecifier, | ||
timeFormat, | ||
utcFormat | ||
} from './src/format'; | ||
export { | ||
timeInterval, | ||
@@ -27,0 +33,0 @@ timeOffset, |
{ | ||
"name": "vega-time", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "JavaScript date/time utilities for Vega.", | ||
@@ -18,3 +18,3 @@ "keywords": [ | ||
"scripts": { | ||
"rollup": "rollup -g d3-array:d3,d3-time:d3,d3-time-format:d3,vega-util:vega -f umd -n vega -o build/vega-time.js -- index.js", | ||
"rollup": "rollup -g d3-array:d3,d3-time:d3,vega-util:vega -f umd -n vega -o build/vega-time.js -- index.js", | ||
"prebuild": "rimraf build && mkdir build", | ||
@@ -31,6 +31,5 @@ "build": "yarn rollup", | ||
"d3-time": "^1.1.0", | ||
"d3-time-format": "^2.2.3", | ||
"vega-util": "^1.13.2" | ||
"vega-util": "^1.14.0" | ||
}, | ||
"gitHead": "35e31c5c6b54db9dc3a577b5adad8d15ec274d32" | ||
"gitHead": "48c85218f2202242171aa569f2dca0f53cf2b51f" | ||
} |
@@ -74,29 +74,4 @@ # vega-time | ||
### Local Time Utilities | ||
<a name="timeFormat" href="#timeFormat">#</a> | ||
vega.<b>timeFormat</b>([<i>specifier</i>]) | ||
[<>](https://github.com/vega/vega/blob/master/packages/vega-time/src/format.js "Source") | ||
Returns a function that takes a date or timestamp as input and returns a formatted string in the local timezone. If a string-valued format _specifier_ is provided, it must follow the [d3-time-format](https://github.com/d3/d3-time-format/#locale_format) syntax. In this case, this method is equivalent to d3-time-format's [timeFormat](https://github.com/d3/d3-time-format/#timeFormat) method. | ||
If an object-valued _specifier_ is provided, a multi-format function will be generated, which selects among different format specifiers based on the granularity of the input date value (that is, values residing on a year, month, date, _etc._, boundary can all be formatted differently). The input object should use proper time unit strings for keys. If no time format _specifier_ is provided, a default multi-format function is returned, equivalent to using the following _specifier_: | ||
```json | ||
{ | ||
"year": "%Y", | ||
"quarter": "%B", | ||
"month": "%B", | ||
"week": "%b %d", | ||
"date": "%a %d", | ||
"hours": "%I %p", | ||
"minutes": "%I:%M", | ||
"seconds": ":%S", | ||
"milliseconds": ".%L" | ||
} | ||
``` | ||
If an input _specifier_ object omits any of these key values, a default value will be used. Note that for this method the `"date"` and `"day"` units are interchangeable; if both are defined the `"date"` entry take precedence. | ||
<a name="timeFloor" href="#timeFloor">#</a> | ||
@@ -140,10 +115,2 @@ vega.<b>timeFloor</b>(<i>units</i>[, <i>step</i>]) | ||
<a name="utcFormat" href="#utcFormat">#</a> | ||
vega.<b>utcFormat</b>([<i>specifier</i>]) | ||
[<>](https://github.com/vega/vega/blob/master/packages/vega-time/src/format.js "Source") | ||
Returns a function that takes a date or timestamp as input and returns a formatted string in [Coordinated Universal Time](https://en.wikipedia.org/wiki/Coordinated_Universal_Time) (UTC). If a string-valued format _specifier_ is provided, it must follow the [d3-time-format](https://github.com/d3/d3-time-format/#locale_format) syntax. In this case, this method is equivalent to d3-time-format's [utcFormat](https://github.com/d3/d3-time-format/#utcFormat) method. | ||
This method also accepts object-valued _specifiers_ for creating multi-format functions. If no argumennts are provided, a defualt multi-format function will be returned. For more details, see the [timeFormat](#timeFormat) method documentation. | ||
<a name="utcFloor" href="#utcFloor">#</a> | ||
@@ -150,0 +117,0 @@ vega.<b>utcFloor</b>(<i>units</i>[, <i>step</i>]) |
@@ -1,2 +0,2 @@ | ||
import {array, error, hasOwnProperty} from 'vega-util'; | ||
import {array, error, extend, hasOwnProperty} from 'vega-util'; | ||
@@ -61,1 +61,39 @@ export const YEAR = 'year'; | ||
} | ||
const defaultSpecifiers = { | ||
[YEAR]: '%Y ', | ||
[QUARTER]: 'Q%q ', | ||
[MONTH]: '%b ', | ||
[DATE]: '%d ', | ||
[WEEK]: 'W%U ', | ||
[DAY]: '%a ', | ||
[DAYOFYEAR]: '%j ', | ||
[HOURS]: '%H:00', | ||
[MINUTES]: '00:%M', | ||
[SECONDS]: ':%S', | ||
[MILLISECONDS]: '.%L', | ||
[`${YEAR}-${MONTH}`]: '%Y-%m ', | ||
[`${YEAR}-${MONTH}-${DATE}`]: '%Y-%m-%d ', | ||
[`${HOURS}-${MINUTES}`]: '%H:%M' | ||
}; | ||
export function timeUnitSpecifier(units, specifiers) { | ||
const s = extend({}, defaultSpecifiers, specifiers), | ||
u = timeUnits(units), | ||
n = u.length; | ||
let fmt = '', start = 0, end, key; | ||
for (start=0; start<n; ) { | ||
for (end=u.length; end > start; --end) { | ||
key = u.slice(start, end).join('-'); | ||
if (s[key] != null) { | ||
fmt += s[key]; | ||
start = end; | ||
break; | ||
} | ||
} | ||
} | ||
return fmt.trim(); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3
41648
11
777
149
- Removedd3-time-format@^2.2.3
- Removedd3-time-format@2.3.0(transitive)
Updatedvega-util@^1.14.0