Socket
Socket
Sign inDemoInstall

angular-calendar-heatmap

Package Overview
Dependencies
3
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.3 to 0.2.4

6

bower.json
{
"name": "angular-calendar-heatmap",
"version": "0.2.3",
"version": "0.2.4",
"main": [
"calendar-heatmap.js",
"calendar-heatmap.css"
"dist/calendar-heatmap.min.js",
"dist/calendar-heatmap.min.css"
],

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

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

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

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

@@ -55,2 +55,10 @@ 'use strict';

var getNumberOfWeeks = function () {
var dayInMillis = 1000*60*60*24;
var extraDays = ((moment() - moment().subtract(1, 'year').subtract(1, 'day')) / dayInMillis) - 52 * 7;
var currentDay = Math.ceil((moment() - moment().startOf('week')) / dayInMillis);
var numWeeks = currentDay < extraDays ? 54 : 53;
return numWeeks;
}
scope.$watch(function () {

@@ -61,3 +69,3 @@ return element[0].clientWidth;

width = w < 1000 ? 1000 : w;
item_size = ((width - label_padding) / 53 - gutter);
item_size = ((width - label_padding) / getNumberOfWeeks() - gutter);
height = label_padding + 7 * (item_size + gutter);

@@ -64,0 +72,0 @@ svg.attr({'width': width, 'height': height});

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc