angular-calendar-heatmap
Advanced tools
Comparing version 0.2.5 to 0.2.6
{ | ||
"name": "angular-calendar-heatmap", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"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,c=40,s=20,d=500,u=!1,m=250,f=15;e.overview=e.overview||"year",e.history=["year"],e.selected={};var v=d3.select(n[0]).append("svg").attr("class","svg"),h=v.append("g"),y=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.floor((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-c)/k()-a,i=c+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&&("year"===e.overview?e.drawYearOverview():"month"===e.overview?e.drawMonthOverview():"week"===e.overview?e.drawWeekOverview():"day"===e.overview&&e.drawDayOverview())},e.drawYearOverview=function(){e.history[e.history.length-1]!==e.overview&&e.history.push(e.overview);var t=moment().startOf("day").subtract(1,"year"),n=d3.max(e.data,function(t){return t.total}),r=d3.scale.linear().range(["#ffffff",e.color||"#ff4500"]).domain([-.15*n,n]),s=function(e){var n=moment(e.date),r=Math.floor((n-moment(t).startOf("week"))/864e5),o=Math.trunc(r/7);return o*(l+a)+c},v=function(t){return c+moment(t.date).weekday()*(l+a)},p=function(t){return n<=0?l:.75*l+l*t.total/n*.25};h.selectAll(".item-circle").remove(),h.selectAll(".item-circle").data(e.data).enter().append("rect").attr("class","item item-circle").style("opacity",0).attr("x",function(t){return s(t)+(l-p(t))/2}).attr("y",function(t){return v(t)+(l-p(t))/2}).attr("rx",function(t){return p(t)}).attr("ry",function(t){return p(t)}).attr("width",function(t){return p(t)}).attr("height",function(t){return p(t)}).attr("fill",function(t){return t.total>0?r(t.total):"transparent"}).on("click",function(t){u||0!==t.total&&(u=!0,e.selected=t,e.hideTooltip(),e.removeYearOverview(),e.overview="day",e.drawChart())}).on("mouseover",function(t){if(!u){var n=d3.select(this);!function c(){n=n.transition().duration(d).ease("ease-in").attr("x",function(t){return s(t)-(1.1*l-l)/2}).attr("y",function(t){return v(t)-(1.1*l-l)/2}).attr("width",1.1*l).attr("height",1.1*l).transition().duration(d).ease("ease-in").attr("x",function(t){return s(t)+(l-p(t))/2}).attr("y",function(t){return v(t)+(l-p(t))/2}).attr("width",function(t){return p(t)}).attr("height",function(t){return p(t)}).each("end",c)}();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=s(t)+l;o-r<m+3*f&&(r-=m+2*f);var i=v(t)+l;w.html(a).style("left",r+"px").style("top",i+"px").transition().duration(d/2).ease("ease-in").style("opacity",1)}}).on("mouseout",function(){u||(d3.select(this).transition().duration(d/2).ease("ease-in").attr("x",function(t){return s(t)+(l-p(t))/2}).attr("y",function(t){return v(t)+(l-p(t))/2}).attr("width",function(t){return p(t)}).attr("height",function(t){return p(t)}),e.hideTooltip())}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*d}).duration(function(){return d}).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(){u=!1});var k=moment().endOf("day"),g=moment().startOf("day").subtract(1,"year"),b=d3.time.months(g.startOf("month"),k),x=d3.scale.linear().range([0,o]).domain([0,b.length]);y.selectAll(".label-month").remove(),y.selectAll(".label-month").data(b).enter().append("text").attr("class","label label-month").attr("font-size",function(){return Math.floor(c/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",c/2).on("mouseenter",function(t){if(!u){var e=moment(t);h.selectAll(".item-circle").transition().duration(d).ease("ease-in").style("opacity",function(t){return moment(t.date).isSame(e,"month")?1:.1})}}).on("mouseout",function(){u||h.selectAll(".item-circle").transition().duration(d).ease("ease-in").style("opacity",1)}).on("click",function(t){if(!u){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},u=!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([c,i]).domain(A.map(function(t){return moment(t).weekday()}));y.selectAll(".label-day").remove(),y.selectAll(".label-day").data(A).enter().append("text").attr("class","label label-day").attr("x",c/3).attr("y",function(t,e){return M(e)+M.rangeBand()/1.75}).style("text-anchor","left").attr("font-size",function(){return Math.floor(c/3)+"px"}).text(function(t){return moment(t).format("dddd")[0]}).on("mouseenter",function(t){if(!u){var e=moment(t);h.selectAll(".item-circle").transition().duration(d).ease("ease-in").style("opacity",function(t){return moment(t.date).day()===e.day()?1:.1})}}).on("mouseout",function(){u||h.selectAll(".item-circle").transition().duration(d).ease("ease-in").style("opacity",1)})},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([c,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([c,o],.05).domain(g.map(function(t){return t.week()}));h.selectAll(".item-block-month").remove();var x=h.selectAll(".item-block-month").data(l).enter().append("g").attr("class","item item-block-month").attr("width",function(){return(o-c)/g.length-5*a}).attr("height",function(){return Math.min(k.rangeBand(),s)}).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){u||0!==t.total&&(u=!0,e.selected=t,e.hideTooltip(),e.removeMonthOverview(),e.overview="day",e.drawChart())}),A=(o-c)/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(),s)}).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(!u){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(d/2).ease("ease-in").style("opacity",1)}}).on("mouseout",function(){u||e.hideTooltip()}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*d}).duration(function(){return d}).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(){u=!1}),y.selectAll(".label-week").remove(),y.selectAll(".label-week").data(g).enter().append("text").attr("class","label label-week").attr("font-size",function(){return Math.floor(c/3)+"px"}).text(function(t){return"Week "+t.week()}).attr("x",function(t){return b(t.week())}).attr("y",c/2).on("mouseenter",function(t){u||h.selectAll(".item-block-month").transition().duration(d).ease("ease-in").style("opacity",function(e){return moment(e.date).week()===t.week()?1:.1})}).on("mouseout",function(){u||h.selectAll(".item-block-month").transition().duration(d).ease("ease-in").style("opacity",1)}).on("click",function(t){if(!u){var n=e.data.filter(function(e){return t.startOf("week")<=moment(e.date)&&moment(e.date)<t.endOf("week")});n.length&&(u=!0,e.selected={date:t},e.hideTooltip(),e.removeMonthOverview(),e.overview="week",e.drawChart())}}),y.selectAll(".label-day").remove(),y.selectAll(".label-day").data(p).enter().append("text").attr("class","label label-day").attr("x",c/3).attr("y",function(t,e){return k(e)+k.rangeBand()/1.75}).style("text-anchor","left").attr("font-size",function(){return Math.floor(c/3)+"px"}).text(function(t){return moment(t).format("dddd")[0]}).on("mouseenter",function(t){if(!u){var e=moment(t);h.selectAll(".item-block-month").transition().duration(d).ease("ease-in").style("opacity",function(t){return moment(t.date).day()===e.day()?1:.1})}}).on("mouseout",function(){u||h.selectAll(".item-block-month").transition().duration(d).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([c,i]).domain(p.map(function(t){return moment(t).weekday()})),g=[t],b=d3.scale.ordinal().rangeRoundBands([c,o],.01).domain(g.map(function(t){return t.week()}));h.selectAll(".item-block-week").remove();var x=h.selectAll(".item-block-week").data(l).enter().append("g").attr("class","item item-block-week").attr("width",function(){return(o-c)/g.length-5*a}).attr("height",function(){return Math.min(k.rangeBand(),s)}).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){u||0!==t.total&&(u=!0,e.selected=t,e.hideTooltip(),e.removeWeekOverview(),e.overview="day",e.drawChart())}),A=(o-c)/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(),s)}).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(!u){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(d/2).ease("ease-in").style("opacity",1)}}).on("mouseout",function(){u||e.hideTooltip()}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*d}).duration(function(){return d}).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(){u=!1}),y.selectAll(".label-week").remove(),y.selectAll(".label-week").data(g).enter().append("text").attr("class","label label-week").attr("font-size",function(){return Math.floor(c/3)+"px"}).text(function(t){return"Week "+t.week()}).attr("x",function(t){return b(t.week())}).attr("y",c/2).on("mouseenter",function(t){u||h.selectAll(".item-block-week").transition().duration(d).ease("ease-in").style("opacity",function(e){return moment(e.date).week()===t.week()?1:.1})}).on("mouseout",function(){u||h.selectAll(".item-block-week").transition().duration(d).ease("ease-in").style("opacity",1)}),y.selectAll(".label-day").remove(),y.selectAll(".label-day").data(p).enter().append("text").attr("class","label label-day").attr("x",c/3).attr("y",function(t,e){return k(e)+k.rangeBand()/1.75}).style("text-anchor","left").attr("font-size",function(){return Math.floor(c/3)+"px"}).text(function(t){return moment(t).format("dddd")[0]}).on("mouseenter",function(t){if(!u){var e=moment(t);h.selectAll(".item-block-week").transition().duration(d).ease("ease-in").style("opacity",function(t){return moment(t.date).day()===e.day()?1:.1})}}).on("mouseout",function(){u||h.selectAll(".item-block-week").transition().duration(d).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([c,i]).domain(t),r=d3.time.scale().range([2*c,o]).domain([moment(e.selected.date).startOf("day"),moment(e.selected.date).endOf("day")]);h.selectAll(".item-block").remove(),h.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(),s)}).attr("fill",function(){return e.color||"#ff4500"}).style("opacity",0).on("mouseover",function(t){if(!u){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(d/2).ease("ease-in").style("opacity",1)}}).on("mouseout",function(){u||e.hideTooltip()}).on("click",function(t){e.handler&&e.handler(t)}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*d}).duration(function(){return d}).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(){u=!1});var l=d3.time.hours(moment(e.selected.date).startOf("day"),moment(e.selected.date).endOf("day")),v=d3.time.scale().range([2*c,o]).domain([0,l.length]);y.selectAll(".label-time").remove(),y.selectAll(".label-time").data(l).enter().append("text").attr("class","label label-time").attr("font-size",function(){return Math.floor(c/3)+"px"}).text(function(t){return moment(t).format("HH:mm")}).attr("x",function(t,e){return v(e)}).attr("y",c/2).on("mouseenter",function(t){if(!u){var e=r(moment(t));h.selectAll(".item-block").transition().duration(d).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(){u||h.selectAll(".item-block").transition().duration(d).ease("ease-in").style("opacity",.5)}),y.selectAll(".label-project").remove(),y.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(c/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*c&&n.length>0;)n=n.slice(0,-1),t.text(n+"..."),e=t.node().getComputedTextLength()}).on("mouseenter",function(t){u||h.selectAll(".item-block").transition().duration(d).ease("ease-in").style("opacity",function(e){return e.name===t?1:.1})}).on("mouseout",function(){u||h.selectAll(".item-block").transition().duration(d).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(){u||(u=!0,"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",c/2.25).attr("cy",c/2.5).attr("r",l/2),t.append("text").attr("x",c/2.25).attr("y",c/2.75).attr("dy",function(){return Math.floor(o/100)/2.5}).attr("font-size",function(){return Math.floor(c/3)+"px"}).html("←"),t.transition().duration(d).ease("ease-in").style("opacity",1)},e.removeYearOverview=function(){h.selectAll(".item-circle").transition().duration(d).ease("ease").style("opacity",0).remove(),y.selectAll(".label-day").remove(),y.selectAll(".label-month").remove()},e.removeMonthOverview=function(){h.selectAll(".item-block-month").selectAll(".item-block-rect").transition().duration(d).ease("ease-in").style("opacity",0).attr("x",function(t,e){return e%2===0?-o/3:o/3}).remove(),y.selectAll(".label-day").remove(),y.selectAll(".label-week").remove(),e.hideBackButton()},e.removeWeekOverview=function(){h.selectAll(".item-block-week").selectAll(".item-block-rect").transition().duration(d).ease("ease-in").style("opacity",0).attr("x",function(t,e){return e%2===0?-o/3:o/3}).remove(),y.selectAll(".label-day").remove(),y.selectAll(".label-week").remove(),e.hideBackButton()},e.removeDayOverview=function(){h.selectAll(".item-block").transition().duration(d).ease("ease-in").style("opacity",0).attr("x",function(t,e){return e%2===0?-o/3:o/3}).remove(),y.selectAll(".label-time").remove(),y.selectAll(".label-project").remove(),e.hideBackButton()},e.hideTooltip=function(){w.transition().duration(d/2).ease("ease-in").style("opacity",0)},e.hideBackButton=function(){p.selectAll(".button").transition().duration(d).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,c=40,s=20,d=500,u=!1,m=250,f=15;e.overview=e.overview||"year",e.history=["year"],e.selected={};var v=d3.select(n[0]).append("svg").attr("class","svg"),h=v.append("g"),y=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-c)/k()-a,i=c+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&&("year"===e.overview?e.drawYearOverview():"month"===e.overview?e.drawMonthOverview():"week"===e.overview?e.drawWeekOverview():"day"===e.overview&&e.drawDayOverview())},e.drawYearOverview=function(){e.history[e.history.length-1]!==e.overview&&e.history.push(e.overview);var t=moment().startOf("day").subtract(1,"year"),n=d3.max(e.data,function(t){return t.total}),r=d3.scale.linear().range(["#ffffff",e.color||"#ff4500"]).domain([-.15*n,n]),s=function(e){var n=moment(e.date),r=Math.round((n-moment(t).startOf("week"))/864e5),o=Math.trunc(r/7);return o*(l+a)+c},v=function(t){return c+moment(t.date).weekday()*(l+a)},p=function(t){return n<=0?l:.75*l+l*t.total/n*.25};h.selectAll(".item-circle").remove(),h.selectAll(".item-circle").data(e.data).enter().append("rect").attr("class","item item-circle").style("opacity",0).attr("x",function(t){return s(t)+(l-p(t))/2}).attr("y",function(t){return v(t)+(l-p(t))/2}).attr("rx",function(t){return p(t)}).attr("ry",function(t){return p(t)}).attr("width",function(t){return p(t)}).attr("height",function(t){return p(t)}).attr("fill",function(t){return t.total>0?r(t.total):"transparent"}).on("click",function(t){u||0!==t.total&&(u=!0,e.selected=t,e.hideTooltip(),e.removeYearOverview(),e.overview="day",e.drawChart())}).on("mouseover",function(t){if(!u){var n=d3.select(this);!function c(){n=n.transition().duration(d).ease("ease-in").attr("x",function(t){return s(t)-(1.1*l-l)/2}).attr("y",function(t){return v(t)-(1.1*l-l)/2}).attr("width",1.1*l).attr("height",1.1*l).transition().duration(d).ease("ease-in").attr("x",function(t){return s(t)+(l-p(t))/2}).attr("y",function(t){return v(t)+(l-p(t))/2}).attr("width",function(t){return p(t)}).attr("height",function(t){return p(t)}).each("end",c)}();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=s(t)+l;o-r<m+3*f&&(r-=m+2*f);var i=v(t)+l;w.html(a).style("left",r+"px").style("top",i+"px").transition().duration(d/2).ease("ease-in").style("opacity",1)}}).on("mouseout",function(){u||(d3.select(this).transition().duration(d/2).ease("ease-in").attr("x",function(t){return s(t)+(l-p(t))/2}).attr("y",function(t){return v(t)+(l-p(t))/2}).attr("width",function(t){return p(t)}).attr("height",function(t){return p(t)}),e.hideTooltip())}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*d}).duration(function(){return d}).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(){u=!1});var k=moment().endOf("day"),g=moment().startOf("day").subtract(1,"year"),b=d3.time.months(g.startOf("month"),k),x=d3.scale.linear().range([0,o]).domain([0,b.length]);y.selectAll(".label-month").remove(),y.selectAll(".label-month").data(b).enter().append("text").attr("class","label label-month").attr("font-size",function(){return Math.floor(c/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",c/2).on("mouseenter",function(t){if(!u){var e=moment(t);h.selectAll(".item-circle").transition().duration(d).ease("ease-in").style("opacity",function(t){return moment(t.date).isSame(e,"month")?1:.1})}}).on("mouseout",function(){u||h.selectAll(".item-circle").transition().duration(d).ease("ease-in").style("opacity",1)}).on("click",function(t){if(!u){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},u=!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([c,i]).domain(A.map(function(t){return moment(t).weekday()}));y.selectAll(".label-day").remove(),y.selectAll(".label-day").data(A).enter().append("text").attr("class","label label-day").attr("x",c/3).attr("y",function(t,e){return M(e)+M.rangeBand()/1.75}).style("text-anchor","left").attr("font-size",function(){return Math.floor(c/3)+"px"}).text(function(t){return moment(t).format("dddd")[0]}).on("mouseenter",function(t){if(!u){var e=moment(t);h.selectAll(".item-circle").transition().duration(d).ease("ease-in").style("opacity",function(t){return moment(t.date).day()===e.day()?1:.1})}}).on("mouseout",function(){u||h.selectAll(".item-circle").transition().duration(d).ease("ease-in").style("opacity",1)})},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([c,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([c,o],.05).domain(g.map(function(t){return t.week()}));h.selectAll(".item-block-month").remove();var x=h.selectAll(".item-block-month").data(l).enter().append("g").attr("class","item item-block-month").attr("width",function(){return(o-c)/g.length-5*a}).attr("height",function(){return Math.min(k.rangeBand(),s)}).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){u||0!==t.total&&(u=!0,e.selected=t,e.hideTooltip(),e.removeMonthOverview(),e.overview="day",e.drawChart())}),A=(o-c)/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(),s)}).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(!u){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(d/2).ease("ease-in").style("opacity",1)}}).on("mouseout",function(){u||e.hideTooltip()}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*d}).duration(function(){return d}).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(){u=!1}),y.selectAll(".label-week").remove(),y.selectAll(".label-week").data(g).enter().append("text").attr("class","label label-week").attr("font-size",function(){return Math.floor(c/3)+"px"}).text(function(t){return"Week "+t.week()}).attr("x",function(t){return b(t.week())}).attr("y",c/2).on("mouseenter",function(t){u||h.selectAll(".item-block-month").transition().duration(d).ease("ease-in").style("opacity",function(e){return moment(e.date).week()===t.week()?1:.1})}).on("mouseout",function(){u||h.selectAll(".item-block-month").transition().duration(d).ease("ease-in").style("opacity",1)}).on("click",function(t){if(!u){var n=e.data.filter(function(e){return t.startOf("week")<=moment(e.date)&&moment(e.date)<t.endOf("week")});n.length&&(u=!0,e.selected={date:t},e.hideTooltip(),e.removeMonthOverview(),e.overview="week",e.drawChart())}}),y.selectAll(".label-day").remove(),y.selectAll(".label-day").data(p).enter().append("text").attr("class","label label-day").attr("x",c/3).attr("y",function(t,e){return k(e)+k.rangeBand()/1.75}).style("text-anchor","left").attr("font-size",function(){return Math.floor(c/3)+"px"}).text(function(t){return moment(t).format("dddd")[0]}).on("mouseenter",function(t){if(!u){var e=moment(t);h.selectAll(".item-block-month").transition().duration(d).ease("ease-in").style("opacity",function(t){return moment(t.date).day()===e.day()?1:.1})}}).on("mouseout",function(){u||h.selectAll(".item-block-month").transition().duration(d).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([c,i]).domain(p.map(function(t){return moment(t).weekday()})),g=[t],b=d3.scale.ordinal().rangeRoundBands([c,o],.01).domain(g.map(function(t){return t.week()}));h.selectAll(".item-block-week").remove();var x=h.selectAll(".item-block-week").data(l).enter().append("g").attr("class","item item-block-week").attr("width",function(){return(o-c)/g.length-5*a}).attr("height",function(){return Math.min(k.rangeBand(),s)}).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){u||0!==t.total&&(u=!0,e.selected=t,e.hideTooltip(),e.removeWeekOverview(),e.overview="day",e.drawChart())}),A=(o-c)/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(),s)}).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(!u){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(d/2).ease("ease-in").style("opacity",1)}}).on("mouseout",function(){u||e.hideTooltip()}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*d}).duration(function(){return d}).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(){u=!1}),y.selectAll(".label-week").remove(),y.selectAll(".label-week").data(g).enter().append("text").attr("class","label label-week").attr("font-size",function(){return Math.floor(c/3)+"px"}).text(function(t){return"Week "+t.week()}).attr("x",function(t){return b(t.week())}).attr("y",c/2).on("mouseenter",function(t){u||h.selectAll(".item-block-week").transition().duration(d).ease("ease-in").style("opacity",function(e){return moment(e.date).week()===t.week()?1:.1})}).on("mouseout",function(){u||h.selectAll(".item-block-week").transition().duration(d).ease("ease-in").style("opacity",1)}),y.selectAll(".label-day").remove(),y.selectAll(".label-day").data(p).enter().append("text").attr("class","label label-day").attr("x",c/3).attr("y",function(t,e){return k(e)+k.rangeBand()/1.75}).style("text-anchor","left").attr("font-size",function(){return Math.floor(c/3)+"px"}).text(function(t){return moment(t).format("dddd")[0]}).on("mouseenter",function(t){if(!u){var e=moment(t);h.selectAll(".item-block-week").transition().duration(d).ease("ease-in").style("opacity",function(t){return moment(t.date).day()===e.day()?1:.1})}}).on("mouseout",function(){u||h.selectAll(".item-block-week").transition().duration(d).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([c,i]).domain(t),r=d3.time.scale().range([2*c,o]).domain([moment(e.selected.date).startOf("day"),moment(e.selected.date).endOf("day")]);h.selectAll(".item-block").remove(),h.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(),s)}).attr("fill",function(){return e.color||"#ff4500"}).style("opacity",0).on("mouseover",function(t){if(!u){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(d/2).ease("ease-in").style("opacity",1)}}).on("mouseout",function(){u||e.hideTooltip()}).on("click",function(t){e.handler&&e.handler(t)}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*d}).duration(function(){return d}).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(){u=!1});var l=d3.time.hours(moment(e.selected.date).startOf("day"),moment(e.selected.date).endOf("day")),v=d3.time.scale().range([2*c,o]).domain([0,l.length]);y.selectAll(".label-time").remove(),y.selectAll(".label-time").data(l).enter().append("text").attr("class","label label-time").attr("font-size",function(){return Math.floor(c/3)+"px"}).text(function(t){return moment(t).format("HH:mm")}).attr("x",function(t,e){return v(e)}).attr("y",c/2).on("mouseenter",function(t){if(!u){var e=r(moment(t));h.selectAll(".item-block").transition().duration(d).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(){u||h.selectAll(".item-block").transition().duration(d).ease("ease-in").style("opacity",.5)}),y.selectAll(".label-project").remove(),y.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(c/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*c&&n.length>0;)n=n.slice(0,-1),t.text(n+"..."),e=t.node().getComputedTextLength()}).on("mouseenter",function(t){u||h.selectAll(".item-block").transition().duration(d).ease("ease-in").style("opacity",function(e){return e.name===t?1:.1})}).on("mouseout",function(){u||h.selectAll(".item-block").transition().duration(d).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(){u||(u=!0,"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",c/2.25).attr("cy",c/2.5).attr("r",l/2),t.append("text").attr("x",c/2.25).attr("y",c/2.75).attr("dy",function(){return Math.floor(o/100)/2.5}).attr("font-size",function(){return Math.floor(c/3)+"px"}).html("←"),t.transition().duration(d).ease("ease-in").style("opacity",1)},e.removeYearOverview=function(){h.selectAll(".item-circle").transition().duration(d).ease("ease").style("opacity",0).remove(),y.selectAll(".label-day").remove(),y.selectAll(".label-month").remove()},e.removeMonthOverview=function(){h.selectAll(".item-block-month").selectAll(".item-block-rect").transition().duration(d).ease("ease-in").style("opacity",0).attr("x",function(t,e){return e%2===0?-o/3:o/3}).remove(),y.selectAll(".label-day").remove(),y.selectAll(".label-week").remove(),e.hideBackButton()},e.removeWeekOverview=function(){h.selectAll(".item-block-week").selectAll(".item-block-rect").transition().duration(d).ease("ease-in").style("opacity",0).attr("x",function(t,e){return e%2===0?-o/3:o/3}).remove(),y.selectAll(".label-day").remove(),y.selectAll(".label-week").remove(),e.hideBackButton()},e.removeDayOverview=function(){h.selectAll(".item-block").transition().duration(d).ease("ease-in").style("opacity",0).attr("x",function(t,e){return e%2===0?-o/3:o/3}).remove(),y.selectAll(".label-time").remove(),y.selectAll(".label-project").remove(),e.hideBackButton()},e.hideTooltip=function(){w.transition().duration(d/2).ease("ease-in").style("opacity",0)},e.hideBackButton=function(){p.selectAll(".button").transition().duration(d).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}}}}]); |
{ | ||
"name": "angular-calendar-heatmap", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"description": "Angular directive of calendar heatmap graph representing time series data.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/g1eb/calendar-heatmap#readme", |
@@ -56,3 +56,3 @@ 'use strict'; | ||
var getNumberOfWeeks = function () { | ||
var dayIndex = Math.floor((moment() - moment().subtract(1, 'year').startOf('week')) / 86400000); | ||
var dayIndex = Math.round((moment() - moment().subtract(1, 'year').startOf('week')) / 86400000); | ||
var colIndex = Math.trunc(dayIndex / 7); | ||
@@ -152,3 +152,3 @@ var numWeeks = colIndex + 1; | ||
var date = moment(d.date); | ||
var dayIndex = Math.floor((date - moment(year_ago).startOf('week')) / 86400000); | ||
var dayIndex = Math.round((date - moment(year_ago).startOf('week')) / 86400000); | ||
var colIndex = Math.trunc(dayIndex / 7); | ||
@@ -155,0 +155,0 @@ return colIndex * (item_size + gutter) + label_padding; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package