diff --git a/dist/timesheet.js b/dist/timesheet.js index 17b13b2..7a5b929 100644 --- a/dist/timesheet.js +++ b/dist/timesheet.js @@ -1 +1 @@ -!function(){"use strict";var Bubble=function(wMonth,min,start,end){this.min=min,this.start=start,this.end=end,this.widthMonth=wMonth};Bubble.prototype.formatMonth=function(num){return num=parseInt(num,10),num>=10?num:"0"+num},Bubble.prototype.getStartOffset=function(){return this.widthMonth/12*(12*(this.start.getFullYear()-this.min)+this.start.getMonth())},Bubble.prototype.getFullYears=function(){return(this.end&&this.end.getFullYear()||this.start.getFullYear())-this.start.getFullYear()},Bubble.prototype.getMonths=function(){var fullYears=this.getFullYears(),months=0;return this.end?this.end.hasMonth?(months+=this.end.getMonth()+1,months+=12-(this.start.hasMonth?this.start.getMonth():0),months+=12*(fullYears-1)):(months+=12-(this.start.hasMonth?this.start.getMonth():0),months+=12*(fullYears-1>0?fullYears-1:0)):months+=this.start.hasMonth?1:12,months},Bubble.prototype.getWidth=function(){return this.widthMonth/12*this.getMonths()},Bubble.prototype.getDateLabel=function(){return[(this.start.hasMonth?this.formatMonth(this.start.getMonth()+1)+"/":"")+this.start.getFullYear(),this.end?"-"+((this.end.hasMonth?this.formatMonth(this.end.getMonth()+1)+"/":"")+this.end.getFullYear()):""].join("")},window.TimesheetBubble=Bubble}(),function(){"use strict";var Timesheet=function(container,min,max,data){this.data=[],this.year={min:min,max:max},this.parse(data||[]),"undefined"!=typeof document&&(this.container="string"==typeof container?document.querySelector("#"+container):container,this.drawSections(),this.insertData())};Timesheet.prototype.insertData=function(){for(var html=[],widthMonth=this.container.querySelector(".scale section").offsetWidth,n=0,m=this.data.length;m>n;n++){var cur=this.data[n],bubble=new TimesheetBubble(widthMonth,this.year.min,cur.start,cur.end),line=['',''+bubble.getDateLabel()+" ",''+cur.label+""].join("");html.push("
  • "+line+"
  • ")}this.container.innerHTML+='"},Timesheet.prototype.drawSections=function(){for(var html=[],c=this.year.min;c<=this.year.max;c++)html.push("
    "+c+"
    ");this.container.className="timesheet color-scheme-default",this.container.innerHTML='
    '+html.join("")+"
    "},Timesheet.prototype.parseDate=function(date){return-1===date.indexOf("/")?(date=new Date(parseInt(date,10),0,1),date.hasMonth=!1):(date=date.split("/"),date=new Date(parseInt(date[1],10),parseInt(date[0],10)-1,1),date.hasMonth=!0),date},Timesheet.prototype.parse=function(data){for(var n=0,m=data.length;m>n;n++){var beg=this.parseDate(data[n][0]),end=4===data[n].length?this.parseDate(data[n][1]):null,lbl=4===data[n].length?data[n][2]:data[n][1],cat=data[n][3]||"default";beg.getFullYear()this.year.max?this.year.max=end.getFullYear():beg.getFullYear()>this.year.max&&(this.year.max=beg.getFullYear()),this.data.push({start:beg,end:end,label:lbl,type:cat})}},window.Timesheet=Timesheet}(); \ No newline at end of file +!function(){"use strict";var Bubble=function(wMonth,min,start,end,endless){this.min=min,this.start=start,this.end=end,this.endless=endless,this.widthMonth=wMonth};Bubble.prototype.formatMonth=function(num){return num=parseInt(num,10),num>=10?num:"0"+num},Bubble.prototype.getStartOffset=function(){return this.widthMonth/12*(12*(this.start.getFullYear()-this.min)+this.start.getMonth())},Bubble.prototype.getFullYears=function(){return(this.end&&this.end.getFullYear()||this.start.getFullYear())-this.start.getFullYear()},Bubble.prototype.getMonths=function(){var fullYears=this.getFullYears(),months=0;return this.end?this.end.hasMonth?(months+=this.end.getMonth()+1,months+=12-(this.start.hasMonth?this.start.getMonth():0),months+=12*(fullYears-1)):(months+=12-(this.start.hasMonth?this.start.getMonth():0),months+=12*(fullYears-1>0?fullYears-1:0)):months+=this.start.hasMonth?1:12,months},Bubble.prototype.getWidth=function(){return this.widthMonth/12*this.getMonths()},Bubble.prototype.getDateLabel=function(){return[(this.start.hasMonth?this.formatMonth(this.start.getMonth()+1)+"/":"")+this.start.getFullYear(),this.endless?"—":this.end?"–"+((this.end.hasMonth?this.formatMonth(this.end.getMonth()+1)+"/":"")+this.end.getFullYear()):""].join("")},window.TimesheetBubble=Bubble}(),function(){"use strict";var Timesheet=function(container,min,max,data){this.data=[],this.year={min:min,max:max},this.parse(data||[]),"undefined"!=typeof document&&(this.container="string"==typeof container?document.querySelector("#"+container):container,this.drawSections(),this.insertData())};Timesheet.prototype.insertData=function(){for(var html=[],widthMonth=this.container.querySelector(".scale section").offsetWidth,n=0,m=this.data.length;m>n;n++){var cur=this.data[n],bubble=new TimesheetBubble(widthMonth,this.year.min,cur.start,cur.end?cur.end:new Date(this.year.max+1,0,1),cur.end?!1:!0),line=['',''+bubble.getDateLabel()+" ",''+cur.label+""].join("");html.push("
  • "+line+"
  • ")}this.container.innerHTML+='"},Timesheet.prototype.drawSections=function(){for(var html=[],c=this.year.min;c<=this.year.max;c++)html.push("
    "+c+"
    ");this.container.className="timesheet color-scheme-default",this.container.innerHTML='
    '+html.join("")+"
    "},Timesheet.prototype.parseDate=function(date){return"present"===date?null:(-1===date.indexOf("/")?(date=new Date(parseInt(date,10),0,1),date.hasMonth=!1):(date=date.split("/"),date=new Date(parseInt(date[1],10),parseInt(date[0],10)-1,1),date.hasMonth=!0),date)},Timesheet.prototype.parse=function(data){for(var n=0,m=data.length;m>n;n++){var beg=this.parseDate(data[n][0]),end=4===data[n].length?this.parseDate(data[n][1]):null,lbl=4===data[n].length?data[n][2]:data[n][1],cat=data[n][3]||"default";beg.getFullYear()this.year.max?this.year.max=end.getFullYear():beg.getFullYear()>this.year.max&&(this.year.max=beg.getFullYear()),this.data.push({start:beg,end:end,label:lbl,type:cat})}},window.Timesheet=Timesheet}(); \ No newline at end of file diff --git a/source/javascripts/timesheet.bubble.js b/source/javascripts/timesheet.bubble.js index 98d3af8..2885e6f 100644 --- a/source/javascripts/timesheet.bubble.js +++ b/source/javascripts/timesheet.bubble.js @@ -4,10 +4,11 @@ /** * Timesheet Bubble */ - var Bubble = function(wMonth, min, start, end) { + var Bubble = function(wMonth, min, start, end, endless) { this.min = min; this.start = start; this.end = end; + this.endless = endless; this.widthMonth = wMonth; }; @@ -70,7 +71,9 @@ Bubble.prototype.getDateLabel = function() { return [ (this.start.hasMonth ? this.formatMonth(this.start.getMonth() + 1) + '/' : '' ) + this.start.getFullYear(), - (this.end ? '-' + ((this.end.hasMonth ? this.formatMonth(this.end.getMonth() + 1) + '/' : '' ) + this.end.getFullYear()) : '') + (this.endless ? '—' : + (this.end ? '–' + ((this.end.hasMonth ? this.formatMonth(this.end.getMonth() + 1) + '/' : '' ) + this.end.getFullYear()) : '') + ) ].join(''); }; diff --git a/source/javascripts/timesheet.js b/source/javascripts/timesheet.js index 3b79f15..0a7d773 100644 --- a/source/javascripts/timesheet.js +++ b/source/javascripts/timesheet.js @@ -33,7 +33,7 @@ for (var n = 0, m = this.data.length; n < m; n++) { var cur = this.data[n]; - var bubble = new TimesheetBubble(widthMonth, this.year.min, cur.start, cur.end); + var bubble = new TimesheetBubble(widthMonth, this.year.min, cur.start, cur.end ? cur.end : new Date(this.year.max+1, 0, 1), cur.end ? false : true); var line = [ '', @@ -65,6 +65,9 @@ * Parse data string */ Timesheet.prototype.parseDate = function(date) { + if (date === 'present') { + return null; + } if (date.indexOf('/') === -1) { date = new Date(parseInt(date, 10), 0, 1); date.hasMonth = false;