(function(){var t=function(t,e){return function(){return t.apply(e,arguments)}};this.Calendar=function(){function e(e,r){this.calendar_activities_path=r,this.clickDay=t(this.clickDay,this),this.currentSelectedDate="",this.daySpace=1,this.daySize=15,this.daySizeWithSpace=this.daySize+2*this.daySpace,this.monthNames=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],this.months=[],this.timestampsTmp=[];var i=0,a=new Date;a.setHours(0,0,0,0,0);var n=new Date(a);n.setFullYear(a.getFullYear()-1);for(var s=gl.utils.getDayDifference(n,a),c=0;s>=c;c++){var o=new Date(n);o.setDate(o.getDate()+c);var h=o.getDay(),d=e[dateFormat(o,"yyyy-mm-dd")];(0===h&&0!==c||0===c)&&(this.timestampsTmp.push([]),i++);var u=this.timestampsTmp[i-1];u.push({count:d||0,date:o,day:h})}this.colorKey=this.initColorKey(),this.color=this.initColor(),this.renderSvg(i),this.renderDays(),this.renderMonths(),this.renderDayTitles(),this.renderKey(),this.initTooltips()}return e.prototype.getExtraWidthPadding=function(t){var e=0,r=this.timestampsTmp[t-1][0].date.getMonth(),i=this.timestampsTmp[t-2][0].date.getMonth();return r!=i&&(e=3),e},e.prototype.renderSvg=function(t){var e=(t+1)*this.daySizeWithSpace+this.getExtraWidthPadding(t);return this.svg=d3.select(".js-contrib-calendar").append("svg").attr("width",e).attr("height",167).attr("class","contrib-calendar")},e.prototype.renderDays=function(){return this.svg.selectAll("g").data(this.timestampsTmp).enter().append("g").attr("transform",function(t){return function(e,r){return _.each(e,function(e,i){var a,n,s,c;if(0===i&&0===e.day){if(s=e.date.getMonth(),c=t.daySizeWithSpace*r+1+t.daySizeWithSpace,a=_.last(t.months),null!=a&&(n=a.x),null==a)return t.months.push({month:s,x:c});if(s!==a.month&&c-t.daySizeWithSpace!==n)return t.months.push({month:s,x:c})}}),"translate("+(t.daySizeWithSpace*r+1+t.daySizeWithSpace)+", 18)"}}(this)).selectAll("rect").data(function(t){return t}).enter().append("rect").attr("x","0").attr("y",function(t){return function(e,r){return t.daySizeWithSpace*e.day}}(this)).attr("width",this.daySize).attr("height",this.daySize).attr("title",function(t){return function(t){var e,r,i;return r=new Date(t.date),e="No contributions",t.count>0&&(e=t.count+" contribution"+(t.count>1?"s":"")),i=dateFormat(r,"mmm d, yyyy"),e+"<br />"+gl.utils.getDayName(r)+" "+i}}(this)).attr("class","user-contrib-cell js-tooltip").attr("fill",function(t){return function(e){return 0!==e.count?t.color(Math.min(e.count,40)):"#ededed"}}(this)).attr("data-container","body").on("click",this.clickDay)},e.prototype.renderDayTitles=function(){var t;return t=[{text:"M",y:29+1*this.daySizeWithSpace},{text:"W",y:29+3*this.daySizeWithSpace},{text:"F",y:29+5*this.daySizeWithSpace}],this.svg.append("g").selectAll("text").data(t).enter().append("text").attr("text-anchor","middle").attr("x",8).attr("y",function(t){return t.y}).text(function(t){return t.text}).attr("class","user-contrib-text")},e.prototype.renderMonths=function(){return this.svg.append("g").selectAll("text").data(this.months).enter().append("text").attr("x",function(t){return t.x}).attr("y",10).attr("class","user-contrib-text").text(function(t){return function(e){return t.monthNames[e.month]}}(this))},e.prototype.renderKey=function(){var t;return t=["#ededed",this.colorKey(0),this.colorKey(1),this.colorKey(2),this.colorKey(3)],this.svg.append("g").attr("transform","translate(18, "+(8*this.daySizeWithSpace+16)+")").selectAll("rect").data(t).enter().append("rect").attr("width",this.daySize).attr("height",this.daySize).attr("x",function(t){return function(e,r){return t.daySizeWithSpace*r}}(this)).attr("y",0).attr("fill",function(t){return t})},e.prototype.initColor=function(){var t;return t=["#ededed",this.colorKey(0),this.colorKey(1),this.colorKey(2),this.colorKey(3)],d3.scale.threshold().domain([0,10,20,30]).range(t)},e.prototype.initColorKey=function(){return d3.scale.linear().range(["#acd5f2","#254e77"]).domain([0,3])},e.prototype.clickDay=function(t){var e;return this.currentSelectedDate!==t.date?(this.currentSelectedDate=t.date,e=this.currentSelectedDate.getFullYear()+"-"+(this.currentSelectedDate.getMonth()+1)+"-"+this.currentSelectedDate.getDate(),$.ajax({url:this.calendar_activities_path,data:{date:e},cache:!1,dataType:"html",beforeSend:function(){return $(".user-calendar-activities").html('<div class="text-center"><i class="fa fa-spinner fa-spin user-calendar-activities-loading"></i></div>')},success:function(t){return $(".user-calendar-activities").html(t)}})):(this.currentSelectedDate="",$(".user-calendar-activities").html(""))},e.prototype.initTooltips=function(){return $(".js-contrib-calendar .js-tooltip").tooltip({html:!0})},e}()}).call(this),function(){}.call(this);