Socket
Socket
Sign inDemoInstall

angular-calendar-heatmap

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-calendar-heatmap - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

2

bower.json
{
"name": "angular-calendar-heatmap",
"version": "0.3.0",
"version": "0.3.1",
"main": [

@@ -5,0 +5,0 @@ "dist/calendar-heatmap.min.js",

@@ -1,1 +0,1 @@

"use strict";angular.module("g1b.calendar-heatmap",[]).directive("calendarHeatmap",["$window",function(t){return{restrict:"E",scope:{data:"=",color:"=?",overview:"=?",handler:"=?"},replace:!0,template:'<div class="calendar-heatmap"></div>',link:function(e,n){var a=5,r=1,o=1e3,i=200,l=10,s=40,c=20,u=500,d=!1,m=250,f=15;e.overview=e.overview||"global",e.history=["global"],e.selected={};var v=d3.select(n[0]).append("svg").attr("class","svg"),y=v.append("g"),h=v.append("g"),p=v.append("g"),w=d3.select(n[0]).append("div").attr("class","heatmap-tooltip").style("opacity",0),k=function(){var t=Math.round((moment()-moment().subtract(1,"year").startOf("week"))/864e5),e=Math.trunc(t/7),n=e+1;return n};e.$watch(function(){return n[0].clientWidth},function(t){t&&(o=t<1e3?1e3:t,l=(o-s)/k()-a,i=s+7*(l+a),v.attr({width:o,height:i}),e.data&&e.data[0].summary&&e.drawChart())}),angular.element(t).bind("resize",function(){e.$apply()}),e.$watch("data",function(t){t&&(t[0].summary||t.map(function(t){var e=t.details.reduce(function(t,e){return t[e.name]?t[e.name].value+=e.value:t[e.name]={value:e.value},t},{}),n=Object.keys(e).map(function(t){return{name:t,value:e[t].value}});return t.summary=n.sort(function(t,e){return e.value-t.value}),t}),e.drawChart())}),e.drawChart=function(){e.data&&("global"===e.overview?e.drawGlobalOverview():"year"===e.overview?e.drawYearOverview():"month"===e.overview?e.drawMonthOverview():"week"===e.overview?e.drawWeekOverview():"day"===e.overview&&e.drawDayOverview())},e.drawGlobalOverview=function(){e.history[e.history.length-1]!==e.overview&&e.history.push(e.overview);var t=moment(e.data[0].date).startOf("year"),n=moment(e.data[e.data.length-1].date).endOf("year"),r=d3.time.years(t,n).map(function(t){var n=moment(t);return{date:n,total:e.data.reduce(function(t,e){return moment(e.date).year()===n.year()&&(t+=e.total),t},0),summary:function(){var t=e.data.reduce(function(t,e){if(moment(e.date).year()===n.year())for(var a=0;a<e.summary.length;a++)t[e.summary[a].name]?t[e.summary[a].name].value+=e.summary[a].value:t[e.summary[a].name]={value:e.summary[a].value};return t},{}),a=Object.keys(t).map(function(e){return{name:e,value:t[e].value}});return a.sort(function(t,e){return e.value-t.value})}()}}),l=d3.max(r,function(t){return t.total}),c=d3.time.years(t,n).map(function(t){return moment(t)}),d=d3.scale.ordinal().rangeRoundBands([0,o],.05).domain(c.map(function(t){return t.year()}));y.selectAll(".item-block-year").remove();y.selectAll(".item-block-year").data(r).enter().append("rect").attr("class","item item-block-year").attr("width",function(){return(o-s)/c.length-5*a}).attr("height",function(){return i-s}).attr("transform",function(t){return"translate("+d(t.date.year())+","+2*f+")"}).attr("fill",function(t){var n=d3.scale.linear().range(["#ffffff",e.color||"#ff4500"]).domain([-.15*l,l]);return n(t.total)||"#ff4500"}).on("click",function(t){e.in_transition||(e.in_transition=!0,e.selected=t,e.hideTooltip(),e.removeGlobalOverview(),e.overview="year",e.drawChart())}).style("opacity",0).on("mouseover",function(t){if(!e.in_transition){var n="";n+='<div class="header"><strong>'+(t.total?e.formatTime(t.total):"No time")+" tracked</strong></div>",n+="<div>in "+t.date.year()+"</div><br>";for(var a=0;a<t.summary.length;a++)n+="<div><span><strong>"+t.summary[a].name+"</strong></span>",n+="<span>"+e.formatTime(t.summary[a].value)+"</span></div>";for(var r=d(t.date.year())+f;o-r<m+3*f;)r-=10;var i=3*f;w.html(n).style("left",r+"px").style("top",i+"px").transition().duration(u/2).ease("ease-in").style("opacity",1)}}).on("mouseout",function(){e.in_transition||e.hideTooltip()}).transition().delay(function(t,e){return u*(e+1)/10}).duration(function(){return u}).ease("ease-in").style("opacity",1).call(function(t,e){t.empty()&&e();var n=0;t.each(function(){++n}).each("end",function(){--n||e.apply(this,arguments)})},function(){e.in_transition=!1});h.selectAll(".label-year").remove(),h.selectAll(".label-year").data(c).enter().append("text").attr("class","label label-year").attr("font-size",function(){return Math.floor(s/3)+"px"}).text(function(t){return t.year()}).attr("x",function(t){return d(t.year())}).attr("y",s/2).on("mouseenter",function(t){e.in_transition||y.selectAll(".item-block-year").transition().duration(u).ease("ease-in").style("opacity",function(e){return moment(e.date).year()===t.year()?1:.1})}).on("mouseout",function(){e.in_transition||y.selectAll(".item-block-year").transition().duration(u).ease("ease-in").style("opacity",1)}).on("click",function(t){e.in_transition||(e.in_transition=!0,e.selected=t,e.hideTooltip(),e.removeGlobalOverview(),e.overview="year",e.drawChart())})},e.drawYearOverview=function(){e.history[e.history.length-1]!==e.overview&&e.history.push(e.overview);var t=(moment().startOf("day").subtract(1,"year"),d3.max(e.data,function(t){return t.total})),n=moment(e.selected.date).startOf("year"),r=moment(e.selected.date).endOf("year"),c=e.data.filter(function(t){return n<=moment(t.date)&&moment(t.date)<r}),t=d3.max(c,function(t){return t.total}),v=d3.scale.linear().range(["#ffffff",e.color||"#ff4500"]).domain([-.15*t,t]),p=function(t){var e=moment(t.date),r=Math.round((e-moment(n).startOf("week"))/864e5),o=Math.trunc(r/7);return o*(l+a)+s},k=function(t){return s+moment(t.date).weekday()*(l+a)},b=function(e){return t<=0?l:.75*l+l*e.total/t*.25};y.selectAll(".item-circle").remove(),y.selectAll(".item-circle").data(c).enter().append("rect").attr("class","item item-circle").style("opacity",0).attr("x",function(t){return p(t)+(l-b(t))/2}).attr("y",function(t){return k(t)+(l-b(t))/2}).attr("rx",function(t){return b(t)}).attr("ry",function(t){return b(t)}).attr("width",function(t){return b(t)}).attr("height",function(t){return b(t)}).attr("fill",function(t){return t.total>0?v(t.total):"transparent"}).on("click",function(t){d||0!==t.total&&(d=!0,e.selected=t,e.hideTooltip(),e.removeYearOverview(),e.overview="day",e.drawChart())}).on("mouseover",function(t){if(!d){var n=d3.select(this);!function s(){n=n.transition().duration(u).ease("ease-in").attr("x",function(t){return p(t)-(1.1*l-l)/2}).attr("y",function(t){return k(t)-(1.1*l-l)/2}).attr("width",1.1*l).attr("height",1.1*l).transition().duration(u).ease("ease-in").attr("x",function(t){return p(t)+(l-b(t))/2}).attr("y",function(t){return k(t)+(l-b(t))/2}).attr("width",function(t){return b(t)}).attr("height",function(t){return b(t)}).each("end",s)}();var a="";a+='<div class="header"><strong>'+(t.total?e.formatTime(t.total):"No time")+" tracked</strong></div>",a+="<div>on "+moment(t.date).format("dddd, MMM Do YYYY")+"</div><br>",angular.forEach(t.summary,function(t){a+="<div><span><strong>"+t.name+"</strong></span>",a+="<span>"+e.formatTime(t.value)+"</span></div>"});var r=p(t)+l;o-r<m+3*f&&(r-=m+2*f);var i=k(t)+l;w.html(a).style("left",r+"px").style("top",i+"px").transition().duration(u/2).ease("ease-in").style("opacity",1)}}).on("mouseout",function(){d||(d3.select(this).transition().duration(u/2).ease("ease-in").attr("x",function(t){return p(t)+(l-b(t))/2}).attr("y",function(t){return k(t)+(l-b(t))/2}).attr("width",function(t){return b(t)}).attr("height",function(t){return b(t)}),e.hideTooltip())}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*u}).duration(function(){return u}).ease("ease-in").style("opacity",1).call(function(t,e){t.empty()&&e();var n=0;t.each(function(){++n}).each("end",function(){--n||e.apply(this,arguments)})},function(){d=!1});var g=d3.time.months(n,r),x=d3.scale.linear().range([0,o]).domain([0,g.length]);h.selectAll(".label-month").remove(),h.selectAll(".label-month").data(g).enter().append("text").attr("class","label label-month").attr("font-size",function(){return Math.floor(s/3)+"px"}).text(function(t){return t.toLocaleDateString("en-us",{month:"short"})}).attr("x",function(t,e){return x(e)+(x(e)-x(e-1))/2}).attr("y",s/2).on("mouseenter",function(t){if(!d){var e=moment(t);y.selectAll(".item-circle").transition().duration(u).ease("ease-in").style("opacity",function(t){return moment(t.date).isSame(e,"month")?1:.1})}}).on("mouseout",function(){d||y.selectAll(".item-circle").transition().duration(u).ease("ease-in").style("opacity",1)}).on("click",function(t){if(!d){var n=e.data.filter(function(e){return moment(t).startOf("month")<=moment(e.date)&&moment(e.date)<moment(t).endOf("month")});n.length&&(e.selected={date:t},d=!0,e.hideTooltip(),e.removeYearOverview(),e.overview="month",e.drawChart())}});var A=d3.time.days(moment().startOf("week"),moment().endOf("week")),M=d3.scale.ordinal().rangeRoundBands([s,i]).domain(A.map(function(t){return moment(t).weekday()}));h.selectAll(".label-day").remove(),h.selectAll(".label-day").data(A).enter().append("text").attr("class","label label-day").attr("x",s/3).attr("y",function(t,e){return M(e)+M.rangeBand()/1.75}).style("text-anchor","left").attr("font-size",function(){return Math.floor(s/3)+"px"}).text(function(t){return moment(t).format("dddd")[0]}).on("mouseenter",function(t){if(!d){var e=moment(t);y.selectAll(".item-circle").transition().duration(u).ease("ease-in").style("opacity",function(t){return moment(t.date).day()===e.day()?1:.1})}}).on("mouseout",function(){d||y.selectAll(".item-circle").transition().duration(u).ease("ease-in").style("opacity",1)}),e.drawButton()},e.drawMonthOverview=function(){e.history[e.history.length-1]!==e.overview&&e.history.push(e.overview);for(var t=moment(e.selected.date).startOf("month"),n=moment(e.selected.date).endOf("month"),l=e.data.filter(function(e){return t<=moment(e.date)&&moment(e.date)<n}),v=d3.max(l,function(t){return d3.max(t.summary,function(t){return t.value})}),p=d3.time.days(moment().startOf("week"),moment().endOf("week")),k=d3.scale.ordinal().rangeRoundBands([s,i]).domain(p.map(function(t){return moment(t).weekday()})),b=[t.clone()];t.week()!==n.week();)b.push(t.add(1,"week").clone());var g=d3.scale.ordinal().rangeRoundBands([s,o],.05).domain(b.map(function(t){return t.week()}));y.selectAll(".item-block-month").remove();var x=y.selectAll(".item-block-month").data(l).enter().append("g").attr("class","item item-block-month").attr("width",function(){return(o-s)/b.length-5*a}).attr("height",function(){return Math.min(k.rangeBand(),c)}).attr("transform",function(t){return"translate("+g(moment(t.date).week())+","+(k(moment(t.date).weekday())+k.rangeBand()/1.75-15)+")"}).attr("total",function(t){return t.total}).attr("date",function(t){return t.date}).attr("offset",0).on("click",function(t){d||0!==t.total&&(d=!0,e.selected=t,e.hideTooltip(),e.removeMonthOverview(),e.overview="day",e.drawChart())}),A=(o-s)/b.length-5*a,M=d3.scale.linear().rangeRound([0,A]);x.selectAll(".item-block-rect").data(function(t){return t.summary}).enter().append("rect").attr("class","item item-block-rect").attr("x",function(t){var e=parseInt(d3.select(this.parentNode).attr("total")),n=parseInt(d3.select(this.parentNode).attr("offset"));return M.domain([0,e]),d3.select(this.parentNode).attr("offset",n+M(t.value)),n}).attr("width",function(t){var e=parseInt(d3.select(this.parentNode).attr("total"));return M.domain([0,e]),Math.max(M(t.value)-r,1)}).attr("height",function(){return Math.min(k.rangeBand(),c)}).attr("fill",function(t){var n=d3.scale.linear().range(["#ffffff",e.color||"#ff4500"]).domain([-.15*v,v]);return n(t.value)||"#ff4500"}).style("opacity",0).on("mouseover",function(t){if(!d){var n=new Date(d3.select(this.parentNode).attr("date")),a="";a+='<div class="header"><strong>'+t.name+"</strong></div><br>",a+="<div><strong>"+(t.value?e.formatTime(t.value):"No time")+" tracked</strong></div>",a+="<div>on "+moment(n).format("dddd, MMM Do YYYY")+"</div>";for(var r=g(moment(n).week())+f;o-r<m+3*f;)r-=10;var i=k(moment(n).weekday())+2*f;w.html(a).style("left",r+"px").style("top",i+"px").transition().duration(u/2).ease("ease-in").style("opacity",1)}}).on("mouseout",function(){d||e.hideTooltip()}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*u}).duration(function(){return u}).ease("ease-in").style("opacity",1).call(function(t,e){t.empty()&&e();var n=0;t.each(function(){++n}).each("end",function(){--n||e.apply(this,arguments)})},function(){d=!1}),h.selectAll(".label-week").remove(),h.selectAll(".label-week").data(b).enter().append("text").attr("class","label label-week").attr("font-size",function(){return Math.floor(s/3)+"px"}).text(function(t){return"Week "+t.week()}).attr("x",function(t){return g(t.week())}).attr("y",s/2).on("mouseenter",function(t){d||y.selectAll(".item-block-month").transition().duration(u).ease("ease-in").style("opacity",function(e){return moment(e.date).week()===t.week()?1:.1})}).on("mouseout",function(){d||y.selectAll(".item-block-month").transition().duration(u).ease("ease-in").style("opacity",1)}).on("click",function(t){if(!d){var n=e.data.filter(function(e){return t.startOf("week")<=moment(e.date)&&moment(e.date)<t.endOf("week")});n.length&&(d=!0,e.selected={date:t},e.hideTooltip(),e.removeMonthOverview(),e.overview="week",e.drawChart())}}),h.selectAll(".label-day").remove(),h.selectAll(".label-day").data(p).enter().append("text").attr("class","label label-day").attr("x",s/3).attr("y",function(t,e){return k(e)+k.rangeBand()/1.75}).style("text-anchor","left").attr("font-size",function(){return Math.floor(s/3)+"px"}).text(function(t){return moment(t).format("dddd")[0]}).on("mouseenter",function(t){if(!d){var e=moment(t);y.selectAll(".item-block-month").transition().duration(u).ease("ease-in").style("opacity",function(t){return moment(t.date).day()===e.day()?1:.1})}}).on("mouseout",function(){d||y.selectAll(".item-block-month").transition().duration(u).ease("ease-in").style("opacity",1)}),e.drawButton()},e.drawWeekOverview=function(){e.history[e.history.length-1]!==e.overview&&e.history.push(e.overview);var t=moment(e.selected.date).startOf("week"),n=moment(e.selected.date).endOf("week"),l=e.data.filter(function(e){return t<=moment(e.date)&&moment(e.date)<n}),v=d3.max(l,function(t){return d3.max(t.summary,function(t){return t.value})}),p=d3.time.days(moment().startOf("week"),moment().endOf("week")),k=d3.scale.ordinal().rangeRoundBands([s,i]).domain(p.map(function(t){return moment(t).weekday()})),b=[t],g=d3.scale.ordinal().rangeRoundBands([s,o],.01).domain(b.map(function(t){return t.week()}));y.selectAll(".item-block-week").remove();var x=y.selectAll(".item-block-week").data(l).enter().append("g").attr("class","item item-block-week").attr("width",function(){return(o-s)/b.length-5*a}).attr("height",function(){return Math.min(k.rangeBand(),c)}).attr("transform",function(t){return"translate("+g(moment(t.date).week())+","+(k(moment(t.date).weekday())+k.rangeBand()/1.75-15)+")"}).attr("total",function(t){return t.total}).attr("date",function(t){return t.date}).attr("offset",0).on("click",function(t){d||0!==t.total&&(d=!0,e.selected=t,e.hideTooltip(),e.removeWeekOverview(),e.overview="day",e.drawChart())}),A=(o-s)/b.length-5*a,M=d3.scale.linear().rangeRound([0,A]);x.selectAll(".item-block-rect").data(function(t){return t.summary}).enter().append("rect").attr("class","item item-block-rect").attr("x",function(t){var e=parseInt(d3.select(this.parentNode).attr("total")),n=parseInt(d3.select(this.parentNode).attr("offset"));return M.domain([0,e]),d3.select(this.parentNode).attr("offset",n+M(t.value)),n}).attr("width",function(t){var e=parseInt(d3.select(this.parentNode).attr("total"));return M.domain([0,e]),Math.max(M(t.value)-r,1)}).attr("height",function(){return Math.min(k.rangeBand(),c)}).attr("fill",function(t){var n=d3.scale.linear().range(["#ffffff",e.color||"#ff4500"]).domain([-.15*v,v]);return n(t.value)||"#ff4500"}).style("opacity",0).on("mouseover",function(t){if(!d){var n=new Date(d3.select(this.parentNode).attr("date")),a="";a+='<div class="header"><strong>'+t.name+"</strong></div><br>",a+="<div><strong>"+(t.value?e.formatTime(t.value):"No time")+" tracked</strong></div>",a+="<div>on "+moment(n).format("dddd, MMM Do YYYY")+"</div>";var r=parseInt(d3.select(this.parentNode).attr("total"));M.domain([0,r]);for(var i=parseInt(d3.select(this).attr("x"))+M(t.value)/4+m/4;o-i<m+3*f;)i-=10;var l=k(moment(n).weekday())+1.5*f;w.html(a).style("left",i+"px").style("top",l+"px").transition().duration(u/2).ease("ease-in").style("opacity",1)}}).on("mouseout",function(){d||e.hideTooltip()}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*u}).duration(function(){return u}).ease("ease-in").style("opacity",1).call(function(t,e){t.empty()&&e();var n=0;t.each(function(){++n}).each("end",function(){--n||e.apply(this,arguments)})},function(){d=!1}),h.selectAll(".label-week").remove(),h.selectAll(".label-week").data(b).enter().append("text").attr("class","label label-week").attr("font-size",function(){return Math.floor(s/3)+"px"}).text(function(t){return"Week "+t.week()}).attr("x",function(t){return g(t.week())}).attr("y",s/2).on("mouseenter",function(t){d||y.selectAll(".item-block-week").transition().duration(u).ease("ease-in").style("opacity",function(e){return moment(e.date).week()===t.week()?1:.1})}).on("mouseout",function(){d||y.selectAll(".item-block-week").transition().duration(u).ease("ease-in").style("opacity",1)}),h.selectAll(".label-day").remove(),h.selectAll(".label-day").data(p).enter().append("text").attr("class","label label-day").attr("x",s/3).attr("y",function(t,e){return k(e)+k.rangeBand()/1.75}).style("text-anchor","left").attr("font-size",function(){return Math.floor(s/3)+"px"}).text(function(t){return moment(t).format("dddd")[0]}).on("mouseenter",function(t){if(!d){var e=moment(t);y.selectAll(".item-block-week").transition().duration(u).ease("ease-in").style("opacity",function(t){return moment(t.date).day()===e.day()?1:.1})}}).on("mouseout",function(){d||y.selectAll(".item-block-week").transition().duration(u).ease("ease-in").style("opacity",1)}),e.drawButton()},e.drawDayOverview=function(){e.history[e.history.length-1]!==e.overview&&e.history.push(e.overview),Object.keys(e.selected).length||(e.selected=e.data[e.data.length-1]);var t=e.selected.summary.map(function(t){return t.name}),n=d3.scale.ordinal().rangeRoundBands([s,i]).domain(t),r=d3.time.scale().range([2*s,o]).domain([moment(e.selected.date).startOf("day"),moment(e.selected.date).endOf("day")]);y.selectAll(".item-block").remove(),y.selectAll(".item-block").data(e.selected.details).enter().append("rect").attr("class","item item-block").attr("x",function(t){return r(moment(t.date))}).attr("y",function(t){return n(t.name)+n.rangeBand()/2-15}).attr("width",function(t){var e=r(d3.time.second.offset(moment(t.date),t.value));return Math.max(e-r(moment(t.date)),1)}).attr("height",function(){return Math.min(n.rangeBand(),c)}).attr("fill",function(){return e.color||"#ff4500"}).style("opacity",0).on("mouseover",function(t){if(!d){var a="";a+='<div class="header"><strong>'+t.name+"</strong><div><br>",a+="<div><strong>"+(t.value?e.formatTime(t.value):"No time")+" tracked</strong></div>",a+="<div>on "+moment(t.date).format("dddd, MMM Do YYYY HH:mm")+"</div>";for(var i=100*t.value/86400+r(moment(t.date));o-i<m+3*f;)i-=10;var l=n(t.name)+n.rangeBand()/2+f/2;w.html(a).style("left",i+"px").style("top",l+"px").transition().duration(u/2).ease("ease-in").style("opacity",1)}}).on("mouseout",function(){d||e.hideTooltip()}).on("click",function(t){e.handler&&e.handler(t)}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*u}).duration(function(){return u}).ease("ease-in").style("opacity",.5).call(function(t,e){t.empty()&&e();var n=0;t.each(function(){++n}).each("end",function(){--n||e.apply(this,arguments)})},function(){d=!1});var l=d3.time.hours(moment(e.selected.date).startOf("day"),moment(e.selected.date).endOf("day")),v=d3.time.scale().range([2*s,o]).domain([0,l.length]);h.selectAll(".label-time").remove(),h.selectAll(".label-time").data(l).enter().append("text").attr("class","label label-time").attr("font-size",function(){return Math.floor(s/3)+"px"}).text(function(t){return moment(t).format("HH:mm")}).attr("x",function(t,e){return v(e)}).attr("y",s/2).on("mouseenter",function(t){if(!d){var e=r(moment(t));y.selectAll(".item-block").transition().duration(u).ease("ease-in").style("opacity",function(t){var n=r(moment(t.date)),a=r(moment(t.date).add(t.value,"seconds"));return e>=n&&e<=a?1:.1})}}).on("mouseout",function(){d||y.selectAll(".item-block").transition().duration(u).ease("ease-in").style("opacity",.5)}),h.selectAll(".label-project").remove(),h.selectAll(".label-project").data(t).enter().append("text").attr("class","label label-project").attr("x",a).attr("y",function(t){return n(t)+n.rangeBand()/2}).attr("min-height",function(){return n.rangeBand()}).style("text-anchor","left").attr("font-size",function(){return Math.floor(s/3)+"px"}).text(function(t){return t}).each(function(){for(var t=d3.select(this),e=t.node().getComputedTextLength(),n=t.text();e>1.5*s&&n.length>0;)n=n.slice(0,-1),t.text(n+"..."),e=t.node().getComputedTextLength()}).on("mouseenter",function(t){d||y.selectAll(".item-block").transition().duration(u).ease("ease-in").style("opacity",function(e){return e.name===t?1:.1})}).on("mouseout",function(){d||y.selectAll(".item-block").transition().duration(u).ease("ease-in").style("opacity",.5)}),e.drawButton()},e.drawButton=function(){p.selectAll(".button").remove();var t=p.append("g").attr("class","button button-back").style("opacity",0).on("click",function(){d||(d=!0,"year"===e.overview?e.removeYearOverview():"month"===e.overview?e.removeMonthOverview():"week"===e.overview?e.removeWeekOverview():"day"===e.overview&&e.removeDayOverview(),e.history.pop(),e.overview=e.history.pop(),e.drawChart())});t.append("circle").attr("cx",s/2.25).attr("cy",s/2.5).attr("r",l/2),t.append("text").attr("x",s/2.25).attr("y",s/2.5).attr("dy",function(){return Math.floor(o/100)/3}).attr("font-size",function(){return Math.floor(s/3)+"px"}).html("&#x2190;"),t.transition().duration(u).ease("ease-in").style("opacity",1)},e.removeGlobalOverview=function(){y.selectAll(".item-block-year").transition().duration(u).ease("ease-out").style("opacity",0).remove(),h.selectAll(".label-year").remove()},e.removeYearOverview=function(){y.selectAll(".item-circle").transition().duration(u).ease("ease").style("opacity",0).remove(),h.selectAll(".label-day").remove(),h.selectAll(".label-month").remove(),e.hideBackButton()},e.removeMonthOverview=function(){y.selectAll(".item-block-month").selectAll(".item-block-rect").transition().duration(u).ease("ease-in").style("opacity",0).attr("x",function(t,e){return e%2===0?-o/3:o/3}).remove(),h.selectAll(".label-day").remove(),h.selectAll(".label-week").remove(),e.hideBackButton()},e.removeWeekOverview=function(){y.selectAll(".item-block-week").selectAll(".item-block-rect").transition().duration(u).ease("ease-in").style("opacity",0).attr("x",function(t,e){return e%2===0?-o/3:o/3}).remove(),h.selectAll(".label-day").remove(),h.selectAll(".label-week").remove(),e.hideBackButton()},e.removeDayOverview=function(){y.selectAll(".item-block").transition().duration(u).ease("ease-in").style("opacity",0).attr("x",function(t,e){return e%2===0?-o/3:o/3}).remove(),h.selectAll(".label-time").remove(),h.selectAll(".label-project").remove(),e.hideBackButton()},e.hideTooltip=function(){w.transition().duration(u/2).ease("ease-in").style("opacity",0)},e.hideBackButton=function(){p.selectAll(".button").transition().duration(u).ease("ease").style("opacity",0).remove()},e.formatTime=function(t){var e=parseInt(t,10),n=Math.floor(e/3600),a=Math.floor((e-3600*n)/60),r="";return n>0&&(r+=1===n?"1 hour ":n+" hours "),a>0&&(r+=1===a?"1 minute":a+" minutes"),0===n&&0===a&&(r=t+" seconds"),r}}}}]);
"use strict";angular.module("g1b.calendar-heatmap",[]).directive("calendarHeatmap",["$window",function(t){return{restrict:"E",scope:{data:"=",color:"=?",overview:"=?",handler:"=?"},replace:!0,template:'<div class="calendar-heatmap"></div>',link:function(e,n){var a=5,r=1,o=1e3,i=200,l=10,s=40,c=20,u=500,d=!1,m=250,f=15;e.overview=e.overview||"global",e.history=["global"],e.selected={};var v=d3.select(n[0]).append("svg").attr("class","svg"),y=v.append("g"),h=v.append("g"),p=v.append("g"),w=d3.select(n[0]).append("div").attr("class","heatmap-tooltip").style("opacity",0),k=function(){var t=Math.round((moment()-moment().subtract(1,"year").startOf("week"))/864e5),e=Math.trunc(t/7),n=e+1;return n};e.$watch(function(){return n[0].clientWidth},function(t){t&&(o=t<1e3?1e3:t,l=(o-s)/k()-a,i=s+7*(l+a),v.attr({width:o,height:i}),e.data&&e.data[0].summary&&e.drawChart())}),angular.element(t).bind("resize",function(){e.$apply()}),e.$watch("data",function(t){t&&(t[0].summary||t.map(function(t){var e=t.details.reduce(function(t,e){return t[e.name]?t[e.name].value+=e.value:t[e.name]={value:e.value},t},{}),n=Object.keys(e).map(function(t){return{name:t,value:e[t].value}});return t.summary=n.sort(function(t,e){return e.value-t.value}),t}),e.drawChart())}),e.drawChart=function(){e.data&&("global"===e.overview?e.drawGlobalOverview():"year"===e.overview?e.drawYearOverview():"month"===e.overview?e.drawMonthOverview():"week"===e.overview?e.drawWeekOverview():"day"===e.overview&&e.drawDayOverview())},e.drawGlobalOverview=function(){e.history[e.history.length-1]!==e.overview&&e.history.push(e.overview);var t=moment(e.data[0].date).startOf("year"),n=moment(e.data[e.data.length-1].date).endOf("year"),r=d3.time.years(t,n).map(function(t){var n=moment(t);return{date:n,total:e.data.reduce(function(t,e){return moment(e.date).year()===n.year()&&(t+=e.total),t},0),summary:function(){var t=e.data.reduce(function(t,e){if(moment(e.date).year()===n.year())for(var a=0;a<e.summary.length;a++)t[e.summary[a].name]?t[e.summary[a].name].value+=e.summary[a].value:t[e.summary[a].name]={value:e.summary[a].value};return t},{}),a=Object.keys(t).map(function(e){return{name:e,value:t[e].value}});return a.sort(function(t,e){return e.value-t.value})}()}}),l=d3.max(r,function(t){return t.total}),c=d3.time.years(t,n).map(function(t){return moment(t)}),d=d3.scale.ordinal().rangeRoundBands([0,o],.05).domain(c.map(function(t){return t.year()}));y.selectAll(".item-block-year").remove();y.selectAll(".item-block-year").data(r).enter().append("rect").attr("class","item item-block-year").attr("width",function(){return(o-s)/c.length-5*a}).attr("height",function(){return i-s}).attr("transform",function(t){return"translate("+d(t.date.year())+","+2*f+")"}).attr("fill",function(t){var n=d3.scale.linear().range(["#ffffff",e.color||"#ff4500"]).domain([-.15*l,l]);return n(t.total)||"#ff4500"}).on("click",function(t){e.in_transition||(e.in_transition=!0,e.selected=t,e.hideTooltip(),e.removeGlobalOverview(),e.overview="year",e.drawChart())}).style("opacity",0).on("mouseover",function(t){if(!e.in_transition){var n="";n+="<div><span><strong>Total time tracked:</strong></span>";var a=parseInt(t.total,10),r=Math.floor(a/86400);r>0&&(n+="<span>"+(1===r?"1 day":r+" days")+"</span></div>");var i=Math.floor((a-86400*r)/3600);i>0&&(n+=r>0?"<div><span></span><span>"+(1===i?"1 hour":i+" hours")+"</span></div>":"<span>"+(1===i?"1 hour":i+" hours")+"</span></div>");var l=Math.floor((a-86400*r-3600*i)/60);if(l>0&&(n+=r>0||i>0?"<div><span></span><span>"+(1===l?"1 minute":l+" minutes")+"</span></div>":"<span>"+(1===l?"1 minute":l+" minutes")+"</span></div>"),n+="<br />",t.summary.length<=5)for(var s=0;s<t.summary.length;s++)n+="<div><span><strong>"+t.summary[s].name+"</strong></span>",n+="<span>"+e.formatTime(t.summary[s].value)+"</span></div>";else{for(var s=0;s<5;s++)n+="<div><span><strong>"+t.summary[s].name+"</strong></span>",n+="<span>"+e.formatTime(t.summary[s].value)+"</span></div>";n+="<br />";for(var c=0,s=5;s<t.summary.length;s++)c=+t.summary[s].value;n+="<div><span><strong>Other:</strong></span>",n+="<span>"+e.formatTime(c)+"</span></div>"}for(var v=d(t.date.year())+2*f;o-v<m+5*f;)v-=10;var y=3*f;w.html(n).style("left",v+"px").style("top",y+"px").transition().duration(u/2).ease("ease-in").style("opacity",1)}}).on("mouseout",function(){e.in_transition||e.hideTooltip()}).transition().delay(function(t,e){return u*(e+1)/10}).duration(function(){return u}).ease("ease-in").style("opacity",1).call(function(t,e){t.empty()&&e();var n=0;t.each(function(){++n}).each("end",function(){--n||e.apply(this,arguments)})},function(){e.in_transition=!1});h.selectAll(".label-year").remove(),h.selectAll(".label-year").data(c).enter().append("text").attr("class","label label-year").attr("font-size",function(){return Math.floor(s/3)+"px"}).text(function(t){return t.year()}).attr("x",function(t){return d(t.year())}).attr("y",s/2).on("mouseenter",function(t){e.in_transition||y.selectAll(".item-block-year").transition().duration(u).ease("ease-in").style("opacity",function(e){return moment(e.date).year()===t.year()?1:.1})}).on("mouseout",function(){e.in_transition||y.selectAll(".item-block-year").transition().duration(u).ease("ease-in").style("opacity",1)}).on("click",function(t){e.in_transition||(e.in_transition=!0,e.selected=t,e.hideTooltip(),e.removeGlobalOverview(),e.overview="year",e.drawChart())})},e.drawYearOverview=function(){e.history[e.history.length-1]!==e.overview&&e.history.push(e.overview);var t=(moment().startOf("day").subtract(1,"year"),d3.max(e.data,function(t){return t.total})),n=moment(e.selected.date).startOf("year"),r=moment(e.selected.date).endOf("year"),c=e.data.filter(function(t){return n<=moment(t.date)&&moment(t.date)<r}),t=d3.max(c,function(t){return t.total}),v=d3.scale.linear().range(["#ffffff",e.color||"#ff4500"]).domain([-.15*t,t]),p=function(t){var e=moment(t.date),r=Math.round((e-moment(n).startOf("week"))/864e5),o=Math.trunc(r/7);return o*(l+a)+s},k=function(t){return s+moment(t.date).weekday()*(l+a)},g=function(e){return t<=0?l:.75*l+l*e.total/t*.25};y.selectAll(".item-circle").remove(),y.selectAll(".item-circle").data(c).enter().append("rect").attr("class","item item-circle").style("opacity",0).attr("x",function(t){return p(t)+(l-g(t))/2}).attr("y",function(t){return k(t)+(l-g(t))/2}).attr("rx",function(t){return g(t)}).attr("ry",function(t){return g(t)}).attr("width",function(t){return g(t)}).attr("height",function(t){return g(t)}).attr("fill",function(t){return t.total>0?v(t.total):"transparent"}).on("click",function(t){d||0!==t.total&&(d=!0,e.selected=t,e.hideTooltip(),e.removeYearOverview(),e.overview="day",e.drawChart())}).on("mouseover",function(t){if(!d){var n=d3.select(this);!function s(){n=n.transition().duration(u).ease("ease-in").attr("x",function(t){return p(t)-(1.1*l-l)/2}).attr("y",function(t){return k(t)-(1.1*l-l)/2}).attr("width",1.1*l).attr("height",1.1*l).transition().duration(u).ease("ease-in").attr("x",function(t){return p(t)+(l-g(t))/2}).attr("y",function(t){return k(t)+(l-g(t))/2}).attr("width",function(t){return g(t)}).attr("height",function(t){return g(t)}).each("end",s)}();var a="";a+='<div class="header"><strong>'+(t.total?e.formatTime(t.total):"No time")+" tracked</strong></div>",a+="<div>on "+moment(t.date).format("dddd, MMM Do YYYY")+"</div><br>",angular.forEach(t.summary,function(t){a+="<div><span><strong>"+t.name+"</strong></span>",a+="<span>"+e.formatTime(t.value)+"</span></div>"});var r=p(t)+l;o-r<m+3*f&&(r-=m+2*f);var i=k(t)+l;w.html(a).style("left",r+"px").style("top",i+"px").transition().duration(u/2).ease("ease-in").style("opacity",1)}}).on("mouseout",function(){d||(d3.select(this).transition().duration(u/2).ease("ease-in").attr("x",function(t){return p(t)+(l-g(t))/2}).attr("y",function(t){return k(t)+(l-g(t))/2}).attr("width",function(t){return g(t)}).attr("height",function(t){return g(t)}),e.hideTooltip())}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*u}).duration(function(){return u}).ease("ease-in").style("opacity",1).call(function(t,e){t.empty()&&e();var n=0;t.each(function(){++n}).each("end",function(){--n||e.apply(this,arguments)})},function(){d=!1});var b=d3.time.months(n,r),x=d3.scale.linear().range([0,o]).domain([0,b.length]);h.selectAll(".label-month").remove(),h.selectAll(".label-month").data(b).enter().append("text").attr("class","label label-month").attr("font-size",function(){return Math.floor(s/3)+"px"}).text(function(t){return t.toLocaleDateString("en-us",{month:"short"})}).attr("x",function(t,e){return x(e)+(x(e)-x(e-1))/2}).attr("y",s/2).on("mouseenter",function(t){if(!d){var e=moment(t);y.selectAll(".item-circle").transition().duration(u).ease("ease-in").style("opacity",function(t){return moment(t.date).isSame(e,"month")?1:.1})}}).on("mouseout",function(){d||y.selectAll(".item-circle").transition().duration(u).ease("ease-in").style("opacity",1)}).on("click",function(t){if(!d){var n=e.data.filter(function(e){return moment(t).startOf("month")<=moment(e.date)&&moment(e.date)<moment(t).endOf("month")});n.length&&(e.selected={date:t},d=!0,e.hideTooltip(),e.removeYearOverview(),e.overview="month",e.drawChart())}});var A=d3.time.days(moment().startOf("week"),moment().endOf("week")),M=d3.scale.ordinal().rangeRoundBands([s,i]).domain(A.map(function(t){return moment(t).weekday()}));h.selectAll(".label-day").remove(),h.selectAll(".label-day").data(A).enter().append("text").attr("class","label label-day").attr("x",s/3).attr("y",function(t,e){return M(e)+M.rangeBand()/1.75}).style("text-anchor","left").attr("font-size",function(){return Math.floor(s/3)+"px"}).text(function(t){return moment(t).format("dddd")[0]}).on("mouseenter",function(t){if(!d){var e=moment(t);y.selectAll(".item-circle").transition().duration(u).ease("ease-in").style("opacity",function(t){return moment(t.date).day()===e.day()?1:.1})}}).on("mouseout",function(){d||y.selectAll(".item-circle").transition().duration(u).ease("ease-in").style("opacity",1)}),e.drawButton()},e.drawMonthOverview=function(){e.history[e.history.length-1]!==e.overview&&e.history.push(e.overview);for(var t=moment(e.selected.date).startOf("month"),n=moment(e.selected.date).endOf("month"),l=e.data.filter(function(e){return t<=moment(e.date)&&moment(e.date)<n}),v=d3.max(l,function(t){return d3.max(t.summary,function(t){return t.value})}),p=d3.time.days(moment().startOf("week"),moment().endOf("week")),k=d3.scale.ordinal().rangeRoundBands([s,i]).domain(p.map(function(t){return moment(t).weekday()})),g=[t.clone()];t.week()!==n.week();)g.push(t.add(1,"week").clone());var b=d3.scale.ordinal().rangeRoundBands([s,o],.05).domain(g.map(function(t){return t.week()}));y.selectAll(".item-block-month").remove();var x=y.selectAll(".item-block-month").data(l).enter().append("g").attr("class","item item-block-month").attr("width",function(){return(o-s)/g.length-5*a}).attr("height",function(){return Math.min(k.rangeBand(),c)}).attr("transform",function(t){return"translate("+b(moment(t.date).week())+","+(k(moment(t.date).weekday())+k.rangeBand()/1.75-15)+")"}).attr("total",function(t){return t.total}).attr("date",function(t){return t.date}).attr("offset",0).on("click",function(t){d||0!==t.total&&(d=!0,e.selected=t,e.hideTooltip(),e.removeMonthOverview(),e.overview="day",e.drawChart())}),A=(o-s)/g.length-5*a,M=d3.scale.linear().rangeRound([0,A]);x.selectAll(".item-block-rect").data(function(t){return t.summary}).enter().append("rect").attr("class","item item-block-rect").attr("x",function(t){var e=parseInt(d3.select(this.parentNode).attr("total")),n=parseInt(d3.select(this.parentNode).attr("offset"));return M.domain([0,e]),d3.select(this.parentNode).attr("offset",n+M(t.value)),n}).attr("width",function(t){var e=parseInt(d3.select(this.parentNode).attr("total"));return M.domain([0,e]),Math.max(M(t.value)-r,1)}).attr("height",function(){return Math.min(k.rangeBand(),c)}).attr("fill",function(t){var n=d3.scale.linear().range(["#ffffff",e.color||"#ff4500"]).domain([-.15*v,v]);return n(t.value)||"#ff4500"}).style("opacity",0).on("mouseover",function(t){if(!d){var n=new Date(d3.select(this.parentNode).attr("date")),a="";a+='<div class="header"><strong>'+t.name+"</strong></div><br>",a+="<div><strong>"+(t.value?e.formatTime(t.value):"No time")+" tracked</strong></div>",a+="<div>on "+moment(n).format("dddd, MMM Do YYYY")+"</div>";for(var r=b(moment(n).week())+f;o-r<m+3*f;)r-=10;var i=k(moment(n).weekday())+2*f;w.html(a).style("left",r+"px").style("top",i+"px").transition().duration(u/2).ease("ease-in").style("opacity",1)}}).on("mouseout",function(){d||e.hideTooltip()}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*u}).duration(function(){return u}).ease("ease-in").style("opacity",1).call(function(t,e){t.empty()&&e();var n=0;t.each(function(){++n}).each("end",function(){--n||e.apply(this,arguments)})},function(){d=!1}),h.selectAll(".label-week").remove(),h.selectAll(".label-week").data(g).enter().append("text").attr("class","label label-week").attr("font-size",function(){return Math.floor(s/3)+"px"}).text(function(t){return"Week "+t.week()}).attr("x",function(t){return b(t.week())}).attr("y",s/2).on("mouseenter",function(t){d||y.selectAll(".item-block-month").transition().duration(u).ease("ease-in").style("opacity",function(e){return moment(e.date).week()===t.week()?1:.1})}).on("mouseout",function(){d||y.selectAll(".item-block-month").transition().duration(u).ease("ease-in").style("opacity",1)}).on("click",function(t){if(!d){var n=e.data.filter(function(e){return t.startOf("week")<=moment(e.date)&&moment(e.date)<t.endOf("week")});n.length&&(d=!0,e.selected={date:t},e.hideTooltip(),e.removeMonthOverview(),e.overview="week",e.drawChart())}}),h.selectAll(".label-day").remove(),h.selectAll(".label-day").data(p).enter().append("text").attr("class","label label-day").attr("x",s/3).attr("y",function(t,e){return k(e)+k.rangeBand()/1.75}).style("text-anchor","left").attr("font-size",function(){return Math.floor(s/3)+"px"}).text(function(t){return moment(t).format("dddd")[0]}).on("mouseenter",function(t){if(!d){var e=moment(t);y.selectAll(".item-block-month").transition().duration(u).ease("ease-in").style("opacity",function(t){return moment(t.date).day()===e.day()?1:.1})}}).on("mouseout",function(){d||y.selectAll(".item-block-month").transition().duration(u).ease("ease-in").style("opacity",1)}),e.drawButton()},e.drawWeekOverview=function(){e.history[e.history.length-1]!==e.overview&&e.history.push(e.overview);var t=moment(e.selected.date).startOf("week"),n=moment(e.selected.date).endOf("week"),l=e.data.filter(function(e){return t<=moment(e.date)&&moment(e.date)<n}),v=d3.max(l,function(t){return d3.max(t.summary,function(t){return t.value})}),p=d3.time.days(moment().startOf("week"),moment().endOf("week")),k=d3.scale.ordinal().rangeRoundBands([s,i]).domain(p.map(function(t){return moment(t).weekday()})),g=[t],b=d3.scale.ordinal().rangeRoundBands([s,o],.01).domain(g.map(function(t){return t.week()}));y.selectAll(".item-block-week").remove();var x=y.selectAll(".item-block-week").data(l).enter().append("g").attr("class","item item-block-week").attr("width",function(){return(o-s)/g.length-5*a}).attr("height",function(){return Math.min(k.rangeBand(),c)}).attr("transform",function(t){return"translate("+b(moment(t.date).week())+","+(k(moment(t.date).weekday())+k.rangeBand()/1.75-15)+")"}).attr("total",function(t){return t.total}).attr("date",function(t){return t.date}).attr("offset",0).on("click",function(t){d||0!==t.total&&(d=!0,e.selected=t,e.hideTooltip(),e.removeWeekOverview(),e.overview="day",e.drawChart())}),A=(o-s)/g.length-5*a,M=d3.scale.linear().rangeRound([0,A]);x.selectAll(".item-block-rect").data(function(t){return t.summary}).enter().append("rect").attr("class","item item-block-rect").attr("x",function(t){var e=parseInt(d3.select(this.parentNode).attr("total")),n=parseInt(d3.select(this.parentNode).attr("offset"));return M.domain([0,e]),d3.select(this.parentNode).attr("offset",n+M(t.value)),n}).attr("width",function(t){var e=parseInt(d3.select(this.parentNode).attr("total"));return M.domain([0,e]),Math.max(M(t.value)-r,1)}).attr("height",function(){return Math.min(k.rangeBand(),c)}).attr("fill",function(t){var n=d3.scale.linear().range(["#ffffff",e.color||"#ff4500"]).domain([-.15*v,v]);return n(t.value)||"#ff4500"}).style("opacity",0).on("mouseover",function(t){if(!d){var n=new Date(d3.select(this.parentNode).attr("date")),a="";a+='<div class="header"><strong>'+t.name+"</strong></div><br>",a+="<div><strong>"+(t.value?e.formatTime(t.value):"No time")+" tracked</strong></div>",a+="<div>on "+moment(n).format("dddd, MMM Do YYYY")+"</div>";var r=parseInt(d3.select(this.parentNode).attr("total"));M.domain([0,r]);for(var i=parseInt(d3.select(this).attr("x"))+M(t.value)/4+m/4;o-i<m+3*f;)i-=10;var l=k(moment(n).weekday())+1.5*f;w.html(a).style("left",i+"px").style("top",l+"px").transition().duration(u/2).ease("ease-in").style("opacity",1)}}).on("mouseout",function(){d||e.hideTooltip()}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*u}).duration(function(){return u}).ease("ease-in").style("opacity",1).call(function(t,e){t.empty()&&e();var n=0;t.each(function(){++n}).each("end",function(){--n||e.apply(this,arguments)})},function(){d=!1}),h.selectAll(".label-week").remove(),h.selectAll(".label-week").data(g).enter().append("text").attr("class","label label-week").attr("font-size",function(){return Math.floor(s/3)+"px"}).text(function(t){return"Week "+t.week()}).attr("x",function(t){return b(t.week())}).attr("y",s/2).on("mouseenter",function(t){d||y.selectAll(".item-block-week").transition().duration(u).ease("ease-in").style("opacity",function(e){return moment(e.date).week()===t.week()?1:.1})}).on("mouseout",function(){d||y.selectAll(".item-block-week").transition().duration(u).ease("ease-in").style("opacity",1)}),h.selectAll(".label-day").remove(),h.selectAll(".label-day").data(p).enter().append("text").attr("class","label label-day").attr("x",s/3).attr("y",function(t,e){return k(e)+k.rangeBand()/1.75}).style("text-anchor","left").attr("font-size",function(){return Math.floor(s/3)+"px"}).text(function(t){return moment(t).format("dddd")[0]}).on("mouseenter",function(t){if(!d){var e=moment(t);y.selectAll(".item-block-week").transition().duration(u).ease("ease-in").style("opacity",function(t){return moment(t.date).day()===e.day()?1:.1})}}).on("mouseout",function(){d||y.selectAll(".item-block-week").transition().duration(u).ease("ease-in").style("opacity",1)}),e.drawButton()},e.drawDayOverview=function(){e.history[e.history.length-1]!==e.overview&&e.history.push(e.overview),Object.keys(e.selected).length||(e.selected=e.data[e.data.length-1]);var t=e.selected.summary.map(function(t){return t.name}),n=d3.scale.ordinal().rangeRoundBands([s,i]).domain(t),r=d3.time.scale().range([2*s,o]).domain([moment(e.selected.date).startOf("day"),moment(e.selected.date).endOf("day")]);y.selectAll(".item-block").remove(),y.selectAll(".item-block").data(e.selected.details).enter().append("rect").attr("class","item item-block").attr("x",function(t){return r(moment(t.date))}).attr("y",function(t){return n(t.name)+n.rangeBand()/2-15}).attr("width",function(t){var e=r(d3.time.second.offset(moment(t.date),t.value));return Math.max(e-r(moment(t.date)),1)}).attr("height",function(){return Math.min(n.rangeBand(),c)}).attr("fill",function(){return e.color||"#ff4500"}).style("opacity",0).on("mouseover",function(t){if(!d){var a="";a+='<div class="header"><strong>'+t.name+"</strong><div><br>",a+="<div><strong>"+(t.value?e.formatTime(t.value):"No time")+" tracked</strong></div>",a+="<div>on "+moment(t.date).format("dddd, MMM Do YYYY HH:mm")+"</div>";for(var i=100*t.value/86400+r(moment(t.date));o-i<m+3*f;)i-=10;var l=n(t.name)+n.rangeBand()/2+f/2;w.html(a).style("left",i+"px").style("top",l+"px").transition().duration(u/2).ease("ease-in").style("opacity",1)}}).on("mouseout",function(){d||e.hideTooltip()}).on("click",function(t){e.handler&&e.handler(t)}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*u}).duration(function(){return u}).ease("ease-in").style("opacity",.5).call(function(t,e){t.empty()&&e();var n=0;t.each(function(){++n}).each("end",function(){--n||e.apply(this,arguments)})},function(){d=!1});var l=d3.time.hours(moment(e.selected.date).startOf("day"),moment(e.selected.date).endOf("day")),v=d3.time.scale().range([2*s,o]).domain([0,l.length]);h.selectAll(".label-time").remove(),h.selectAll(".label-time").data(l).enter().append("text").attr("class","label label-time").attr("font-size",function(){return Math.floor(s/3)+"px"}).text(function(t){return moment(t).format("HH:mm")}).attr("x",function(t,e){return v(e)}).attr("y",s/2).on("mouseenter",function(t){if(!d){var e=r(moment(t));y.selectAll(".item-block").transition().duration(u).ease("ease-in").style("opacity",function(t){var n=r(moment(t.date)),a=r(moment(t.date).add(t.value,"seconds"));return e>=n&&e<=a?1:.1})}}).on("mouseout",function(){d||y.selectAll(".item-block").transition().duration(u).ease("ease-in").style("opacity",.5)}),h.selectAll(".label-project").remove(),h.selectAll(".label-project").data(t).enter().append("text").attr("class","label label-project").attr("x",a).attr("y",function(t){return n(t)+n.rangeBand()/2}).attr("min-height",function(){return n.rangeBand()}).style("text-anchor","left").attr("font-size",function(){return Math.floor(s/3)+"px"}).text(function(t){return t}).each(function(){for(var t=d3.select(this),e=t.node().getComputedTextLength(),n=t.text();e>1.5*s&&n.length>0;)n=n.slice(0,-1),t.text(n+"..."),e=t.node().getComputedTextLength()}).on("mouseenter",function(t){d||y.selectAll(".item-block").transition().duration(u).ease("ease-in").style("opacity",function(e){return e.name===t?1:.1})}).on("mouseout",function(){d||y.selectAll(".item-block").transition().duration(u).ease("ease-in").style("opacity",.5)}),e.drawButton()},e.drawButton=function(){p.selectAll(".button").remove();var t=p.append("g").attr("class","button button-back").style("opacity",0).on("click",function(){d||(d=!0,"year"===e.overview?e.removeYearOverview():"month"===e.overview?e.removeMonthOverview():"week"===e.overview?e.removeWeekOverview():"day"===e.overview&&e.removeDayOverview(),e.history.pop(),e.overview=e.history.pop(),e.drawChart())});t.append("circle").attr("cx",s/2.25).attr("cy",s/2.5).attr("r",l/2),t.append("text").attr("x",s/2.25).attr("y",s/2.5).attr("dy",function(){return Math.floor(o/100)/3}).attr("font-size",function(){return Math.floor(s/3)+"px"}).html("&#x2190;"),t.transition().duration(u).ease("ease-in").style("opacity",1)},e.removeGlobalOverview=function(){y.selectAll(".item-block-year").transition().duration(u).ease("ease-out").style("opacity",0).remove(),h.selectAll(".label-year").remove()},e.removeYearOverview=function(){y.selectAll(".item-circle").transition().duration(u).ease("ease").style("opacity",0).remove(),h.selectAll(".label-day").remove(),h.selectAll(".label-month").remove(),e.hideBackButton()},e.removeMonthOverview=function(){y.selectAll(".item-block-month").selectAll(".item-block-rect").transition().duration(u).ease("ease-in").style("opacity",0).attr("x",function(t,e){return e%2===0?-o/3:o/3}).remove(),h.selectAll(".label-day").remove(),h.selectAll(".label-week").remove(),e.hideBackButton()},e.removeWeekOverview=function(){y.selectAll(".item-block-week").selectAll(".item-block-rect").transition().duration(u).ease("ease-in").style("opacity",0).attr("x",function(t,e){return e%2===0?-o/3:o/3}).remove(),h.selectAll(".label-day").remove(),h.selectAll(".label-week").remove(),e.hideBackButton()},e.removeDayOverview=function(){y.selectAll(".item-block").transition().duration(u).ease("ease-in").style("opacity",0).attr("x",function(t,e){return e%2===0?-o/3:o/3}).remove(),h.selectAll(".label-time").remove(),h.selectAll(".label-project").remove(),e.hideBackButton()},e.hideTooltip=function(){w.transition().duration(u/2).ease("ease-in").style("opacity",0)},e.hideBackButton=function(){p.selectAll(".button").transition().duration(u).ease("ease").style("opacity",0).remove()},e.formatTime=function(t){var e=parseInt(t,10),n=Math.floor(e/3600),a=Math.floor((e-3600*n)/60),r="";return n>0&&(r+=1===n?"1 hour ":n+" hours "),a>0&&(r+=1===a?"1 minute":a+" minutes"),0===n&&0===a&&(r=Math.round(t)+" seconds"),r}}}}]);

@@ -5,3 +5,3 @@ var gulp = require('gulp');

var uglify = require('gulp-uglify');
gulp.task('build', ['js', 'css']);

@@ -8,0 +8,0 @@

{
"name": "angular-calendar-heatmap",
"version": "0.3.0",
"version": "0.3.1",
"description": "Angular directive for d3.js calendar heatmap graph.",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/g1eb/angular-calendar-heatmap#readme",

@@ -248,14 +248,51 @@ 'use strict';

var tooltip_html = '';
tooltip_html += '<div class="header"><strong>' + (d.total ? scope.formatTime(d.total) : 'No time') + ' tracked</strong></div>';
tooltip_html += '<div>in ' + d.date.year() + '</div><br>';
tooltip_html += '<div><span><strong>Total time tracked:</strong></span>';
var sec = parseInt(d.total, 10);
var days = Math.floor(sec / 86400);
if ( days > 0 ) {
tooltip_html += '<span>' + (days === 1 ? '1 day' : days + ' days') + '</span></div>';
}
var hours = Math.floor((sec - (days * 86400)) / 3600);
if ( hours > 0 ) {
if ( days > 0 ) {
tooltip_html += '<div><span></span><span>' + (hours === 1 ? '1 hour' : hours + ' hours') + '</span></div>';
} else {
tooltip_html += '<span>' + (hours === 1 ? '1 hour' : hours + ' hours') + '</span></div>';
}
}
var minutes = Math.floor((sec - (days * 86400) - (hours * 3600)) / 60);
if ( minutes > 0 ) {
if ( days > 0 || hours > 0 ) {
tooltip_html += '<div><span></span><span>' + (minutes === 1 ? '1 minute' : minutes + ' minutes') + '</span></div>';
} else {
tooltip_html += '<span>' + (minutes === 1 ? '1 minute' : minutes + ' minutes') + '</span></div>';
}
}
tooltip_html += '<br />';
// Add summary to the tooltip
for ( var i = 0; i < d.summary.length; i++ ) {
tooltip_html += '<div><span><strong>' + d.summary[i].name + '</strong></span>';
tooltip_html += '<span>' + scope.formatTime(d.summary[i].value) + '</span></div>';
};
if ( d.summary.length <= 5 ) {
for ( var i = 0; i < d.summary.length; i++ ) {
tooltip_html += '<div><span><strong>' + d.summary[i].name + '</strong></span>';
tooltip_html += '<span>' + scope.formatTime(d.summary[i].value) + '</span></div>';
};
} else {
for ( var i = 0; i < 5; i++ ) {
tooltip_html += '<div><span><strong>' + d.summary[i].name + '</strong></span>';
tooltip_html += '<span>' + scope.formatTime(d.summary[i].value) + '</span></div>';
};
tooltip_html += '<br />';
var other_projects_sum = 0;
for ( var i = 5; i < d.summary.length; i++ ) {
other_projects_sum =+ d.summary[i].value;
};
tooltip_html += '<div><span><strong>Other:</strong></span>';
tooltip_html += '<span>' + scope.formatTime(other_projects_sum) + '</span></div>';
}
// Calculate tooltip position
var x = yearScale(d.date.year()) + tooltip_padding;
while ( width - x < (tooltip_width + tooltip_padding * 3) ) {
var x = yearScale(d.date.year()) + tooltip_padding * 2;
while ( width - x < (tooltip_width + tooltip_padding * 5) ) {
x -= 10;

@@ -682,3 +719,3 @@ }

// Add button to switch back to year overview
// Add button to switch back to previous overview
scope.drawButton();

@@ -970,3 +1007,3 @@ };

// Add button to switch back to year overview
// Add button to switch back to previous overview
scope.drawButton();

@@ -1230,3 +1267,3 @@ };

// Add button to switch back to year overview
// Add button to switch back to previous overview
scope.drawButton();

@@ -1439,3 +1476,3 @@ };

// Add button to switch back to year overview
// Add button to switch back to previous overview
scope.drawButton();

@@ -1497,3 +1534,3 @@ };

/**
* Transition and remove items and labels related to year overview
* Transition and remove items and labels related to global overview
*/

@@ -1624,3 +1661,3 @@ scope.removeGlobalOverview = function () {

if ( hours === 0 && minutes === 0 ) {
time = seconds + ' seconds';
time = Math.round(seconds) + ' seconds';
}

@@ -1627,0 +1664,0 @@ return time;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc