forked from nikopol/Harry-Plotter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathharry.timeline.min.js
7 lines (7 loc) · 2.6 KB
/
harry.timeline.min.js
1
2
3
4
5
6
7
// harry plotter timeline serie generator - 0.3
// ~L~ [email protected] 2012-2014
// https://github.com/nikopol/Harry-Plotter
harry.timeline=function(){var g=function(a){var b=new Date(a);if(!isNaN(a))return b;if(/^(\d{4})\D(\d{2})\D(\d{2})(?:\D(\d{2}))?(?:\D(\d{2}))?(?:\D(\d{2}))?/.test(a))return new Date(RegExp.$1,RegExp.$2-1,RegExp.$3,RegExp.$4||0,RegExp.$5||0,RegExp.$6||0);console.error("unable to parse date ",a," please setup a parser");return null},v=function(a){return a.getFullYear()},w=function(a){return a.toISOString().substr(0,7)},x=function(a){return a.getDate()},y=function(a){return a.getDate()+" "+a.getHours()},z=function(a){return a.toTimeString().substr(0,5)},A=function(a){return a.toTimeString().substr(0,8)},B={eval:function(a){return a.getFullYear()},next:function(a){return a+1},date:function(a){return new Date(a+"-01-01T00:00:00Z")}},C={eval:function(a){return(new Date(a.getFullYear(),a.getMonth(),1,0,0,0,0)).toISOString()},next:function(a){var b=new Date(a);a=b.getFullYear();b=b.getMonth()+1;11<b&&(a++,b=0);return(new Date(a,b,1,0,0,0,0)).toISOString()},date:function(a){return new Date(a)}},D={eval:function(a){return(new Date(a.getFullYear(),
a.getMonth(),a.getDate(),0,0,0,0)).toISOString()},next:function(a){return(new Date((new Date(a)).getTime()+864E5)).toISOString()},date:function(a){return new Date(a)}},E={eval:function(a){return Math.floor(a.getTime()/36E5)},next:function(a){return a+1},date:function(a){return new Date(36E5*a)}},F={eval:function(a){return Math.floor(a.getTime()/6E4)},next:function(a){return a+1},date:function(a){return new Date(6E4*a)}},G={eval:function(a){return Math.floor(a.getTime()/1E3)},next:function(a){return a+
1},date:function(a){return new Date(1E3*a)}},e=function(a,b,d,g){var e=null,k=null,q=[],l=[],m=[],s=[],t={},f,h,c,r;a instanceof Array||(a=[a]);for(f in a){var p={},n=a[f];n.datas&&(n=n.datas);for(r in n){c=d(r);c=b.eval(c);if(null===e||c<e)e=c;if(null===k||c>k)k=c;var u=parseFloat(n[r]);p[c]=p[c]?p[c]+u:u}l.push(p);m.push(a[f].datas?{title:a[f].title,color:a[f].color}:{title:!1,color:!1})}for(h in l){d={values:[]};m[h].title&&(d.title=m[h].title);m[h].color&&(d.color=m[h].color);if(0==h)for(c=e,
a=0;c<=k;c=b.next(c),a++)s.push(g(b.date(c))),t[c]=a;for(c=e;c<=k;c=b.next(c))d.values.push(null);d.labels=s;q.push(d)}for(f in l)for(c in l[f])h=t[c],q[f].values[h]=l[f][c];return q};return{year:function(a,b,d){return e(a,B,b||g,d||v)},month:function(a,b,d){return e(a,C,b||g,d||w)},day:function(a,b,d){return e(a,D,b||g,d||x)},hour:function(a,b,d){return e(a,E,b||g,d||y)},minute:function(a,b,d){return e(a,F,b||g,d||z)},second:function(a,b,d){return e(a,G,b||g,d||A)}}}();