1 line
4.4 KiB
JavaScript
1 line
4.4 KiB
JavaScript
!function(e){function t(e,t){return t*Math.floor(e/t)}function n(e,t,n,r){if("function"==typeof e.strftime)return e.strftime(t);var a,i=function(e,t){return t=""+(null==t?"0":t),1==(e=""+e).length?t+e:e},o=[],s=!1,u=e.getHours(),c=u<12;null==n&&(n=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]),null==r&&(r=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]),a=u>12?u-12:0==u?12:u;for(var m=0;m<t.length;++m){var h=t.charAt(m);if(s){switch(h){case"a":h=""+r[e.getDay()];break;case"b":h=""+n[e.getMonth()];break;case"d":h=i(e.getDate());break;case"e":h=i(e.getDate()," ");break;case"H":h=i(u);break;case"I":h=i(a);break;case"l":h=i(a," ");break;case"m":h=i(e.getMonth()+1);break;case"M":h=i(e.getMinutes());break;case"q":h=""+(Math.floor(e.getMonth()/3)+1);break;case"S":h=i(e.getSeconds());break;case"y":h=i(e.getFullYear()%100);break;case"Y":h=""+e.getFullYear();break;case"p":h=c?"am":"pm";break;case"P":h=c?"AM":"PM";break;case"w":h=""+e.getDay()}o.push(h),s=!1}else"%"==h?s=!0:o.push(h)}return o.join("")}function r(e){function t(e,t,n,r){e[t]=function(){return n[r].apply(n,arguments)}}var n={date:e};null!=e.strftime&&t(n,"strftime",e,"strftime"),t(n,"getTime",e,"getTime"),t(n,"setTime",e,"setTime");for(var r=["Date","Day","FullYear","Hours","Milliseconds","Minutes","Month","Seconds"],a=0;a<r.length;a++)t(n,"get"+r[a],e,"getUTC"+r[a]),t(n,"set"+r[a],e,"setUTC"+r[a]);return n}function a(e,t){if("browser"==t.timezone)return new Date(e);if(t.timezone&&"utc"!=t.timezone){if("undefined"!=typeof timezoneJS&&void 0!==timezoneJS.Date){var n=new timezoneJS.Date;return n.setTimezone(t.timezone),n.setTime(e),n}return r(new Date(e))}return r(new Date(e))}var i={second:1e3,minute:6e4,hour:36e5,day:864e5,month:2592e6,quarter:7776e6,year:525949.2*60*1e3},o=[[1,"second"],[2,"second"],[5,"second"],[10,"second"],[30,"second"],[1,"minute"],[2,"minute"],[5,"minute"],[10,"minute"],[30,"minute"],[1,"hour"],[2,"hour"],[4,"hour"],[8,"hour"],[12,"hour"],[1,"day"],[2,"day"],[3,"day"],[.25,"month"],[.5,"month"],[1,"month"],[2,"month"]],s=o.concat([[3,"month"],[6,"month"],[1,"year"]]),u=o.concat([[1,"quarter"],[2,"quarter"],[1,"year"]]);e.plot.plugins.push({init:function(r){r.hooks.processDatapoints.push((function(r,o,c){e.each(r.getAxes(),(function(e,r){var o=r.options;"time"==o.mode&&(r.tickGenerator=function(e){var n=[],r=a(e.min,o),c=0,m=o.tickSize&&"quarter"===o.tickSize[1]||o.minTickSize&&"quarter"===o.minTickSize[1]?u:s;null!=o.minTickSize&&(c="number"==typeof o.tickSize?o.tickSize:o.minTickSize[0]*i[o.minTickSize[1]]);for(var h=0;h<m.length-1&&!(e.delta<(m[h][0]*i[m[h][1]]+m[h+1][0]*i[m[h+1][1]])/2&&m[h][0]*i[m[h][1]]>=c);++h);var l=m[h][0],f=m[h][1];if("year"==f){if(null!=o.minTickSize&&"year"==o.minTickSize[1])l=Math.floor(o.minTickSize[0]);else{var k=Math.pow(10,Math.floor(Math.log(e.delta/i.year)/Math.LN10)),M=e.delta/i.year/k;l=M<1.5?1:M<3?2:M<7.5?5:10,l*=k}l<1&&(l=1)}e.tickSize=o.tickSize||[l,f];var g=e.tickSize[0];f=e.tickSize[1];var d=g*i[f];"second"==f?r.setSeconds(t(r.getSeconds(),g)):"minute"==f?r.setMinutes(t(r.getMinutes(),g)):"hour"==f?r.setHours(t(r.getHours(),g)):"month"==f?r.setMonth(t(r.getMonth(),g)):"quarter"==f?r.setMonth(3*t(r.getMonth()/3,g)):"year"==f&&r.setFullYear(t(r.getFullYear(),g)),r.setMilliseconds(0),d>=i.minute?r.setSeconds(0):d>=i.hour?r.setMinutes(0):d>=i.day?r.setHours(0):d>=4*i.day?r.setDate(1):d>=2*i.month?r.setMonth(t(r.getMonth(),3)):d>=2*i.quarter?r.setMonth(t(r.getMonth(),6)):d>=i.year&&r.setMonth(0);var S,y=0,z=Number.NaN;do{if(S=z,z=r.getTime(),n.push(z),"month"==f||"quarter"==f)if(g<1){r.setDate(1);var p=r.getTime();r.setMonth(r.getMonth()+("quarter"==f?3:1));var T=r.getTime();r.setTime(z+y*i.hour+(T-p)*g),y=r.getHours(),r.setHours(0)}else r.setMonth(r.getMonth()+g*("quarter"==f?3:1));else"year"==f?r.setFullYear(r.getFullYear()+g):r.setTime(z+d)}while(z<e.max&&z!=S);return n},r.tickFormatter=function(e,t){var r=a(e,t.options);if(null!=o.timeformat)return n(r,o.timeformat,o.monthNames,o.dayNames);var s=t.options.tickSize&&"quarter"==t.options.tickSize[1]||t.options.minTickSize&&"quarter"==t.options.minTickSize[1],u=t.tickSize[0]*i[t.tickSize[1]],c=t.max-t.min,m=o.twelveHourClock?" %p":"",h=o.twelveHourClock?"%I":"%H";return n(r,u<i.minute?h+":%M:%S"+m:u<i.day?c<2*i.day?h+":%M"+m:"%b %d "+h+":%M"+m:u<i.month?"%b %d":s&&u<i.quarter||!s&&u<i.year?c<i.year?"%b":"%b %Y":s&&u<i.year?c<i.year?"Q%q":"Q%q %Y":"%Y",o.monthNames,o.dayNames)})}))}))},options:{},name:"time",version:"1.0"}),e.plot.formatDate=n}(jQuery); |