calendar-heatmap-graph
Advanced tools
Comparing version 0.0.8 to 0.0.9
{ | ||
"name": "calendar-heatmap-graph", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "d3.js calendar heatmap graph.", | ||
@@ -22,4 +22,4 @@ "homepage": "https://github.com/g1eb/calendar-heatmap", | ||
"dependencies": { | ||
"d3": "^3.5.16", | ||
"moment": "^2.12.0" | ||
"d3": "^4.10.2", | ||
"moment": "^2.18.1" | ||
}, | ||
@@ -26,0 +26,0 @@ "keywords": [ |
@@ -1,2 +0,1 @@ | ||
"use strict";var calendarHeatmap={settings:{gutter:5,item_gutter:1,width:1e3,height:200,item_size:10,label_padding:40,max_block_height:20,transition_duration:500,tooltip_width:250,tooltip_padding:15},init:function(a,e,t,n){calendarHeatmap.data=a,calendarHeatmap.color=e||"#ff4500",calendarHeatmap.overview=t||"global",calendarHeatmap.history=["global"],calendarHeatmap.selected={},calendarHeatmap.handler=n,calendarHeatmap.in_transition=!1,calendarHeatmap.createElements(),calendarHeatmap.parseData(),calendarHeatmap.drawChart()},createElements:function(){var a=document.createElement("div");a.className="calendar-heatmap",document.body.appendChild(a);var e=d3.select(a).append("svg").attr("class","svg");calendarHeatmap.items=e.append("g"),calendarHeatmap.labels=e.append("g"),calendarHeatmap.buttons=e.append("g"),calendarHeatmap.tooltip=d3.select(a).append("div").attr("class","heatmap-tooltip").style("opacity",0);var t=function(){var t=Math.round((moment()-moment().subtract(1,"year").startOf("week"))/864e5),n=Math.trunc(t/7),r=n+1;calendarHeatmap.settings.width=a.offsetWidth<1e3?1e3:a.offsetWidth,calendarHeatmap.settings.item_size=(calendarHeatmap.settings.width-calendarHeatmap.settings.label_padding)/r-calendarHeatmap.settings.gutter,calendarHeatmap.settings.height=calendarHeatmap.settings.label_padding+7*(calendarHeatmap.settings.item_size+calendarHeatmap.settings.gutter),e.attr({width:calendarHeatmap.settings.width,height:calendarHeatmap.settings.height}),calendarHeatmap.data&&calendarHeatmap.data[0].summary&&calendarHeatmap.drawChart()};t(),window.onresize=function(a){t()}},parseData:function(){calendarHeatmap.data&&(calendarHeatmap.data[0].summary||calendarHeatmap.data.map(function(a){var e=a.details.reduce(function(a,e){return a[e.name]?a[e.name].value+=e.value:a[e.name]={value:e.value},a},{}),t=Object.keys(e).map(function(a){return{name:a,value:e[a].value}});return a.summary=t.sort(function(a,e){return e.value-a.value}),a}))},drawChart:function(){"global"===calendarHeatmap.overview?calendarHeatmap.drawGlobalOverview():"year"===calendarHeatmap.overview?calendarHeatmap.drawYearOverview():"month"===calendarHeatmap.overview?calendarHeatmap.drawMonthOverview():"week"===calendarHeatmap.overview?calendarHeatmap.drawWeekOverview():"day"===calendarHeatmap.overview&&calendarHeatmap.drawDayOverview()},drawGlobalOverview:function(){calendarHeatmap.history[calendarHeatmap.history.length-1]!==calendarHeatmap.overview&&calendarHeatmap.history.push(calendarHeatmap.overview);var a=moment(calendarHeatmap.data[0].date).startOf("year"),e=moment(calendarHeatmap.data[calendarHeatmap.data.length-1].date).endOf("year"),t=d3.time.years(a,e).map(function(a){var e=moment(a);return{date:e,total:calendarHeatmap.data.reduce(function(a,t){return moment(t.date).year()===e.year()&&(a+=t.total),a},0),summary:function(){var a=calendarHeatmap.data.reduce(function(a,t){if(moment(t.date).year()===e.year())for(var n=0;n<t.summary.length;n++)a[t.summary[n].name]?a[t.summary[n].name].value+=t.summary[n].value:a[t.summary[n].name]={value:t.summary[n].value};return a},{}),t=Object.keys(a).map(function(e){return{name:e,value:a[e].value}});return t.sort(function(a,e){return e.value-a.value})}()}}),n=d3.max(t,function(a){return a.total}),r=d3.time.years(a,e).map(function(a){return moment(a)}),i=d3.scale.ordinal().rangeRoundBands([0,calendarHeatmap.settings.width],.05).domain(r.map(function(a){return a.year()}));calendarHeatmap.items.selectAll(".item-block-year").remove();calendarHeatmap.items.selectAll(".item-block-year").data(t).enter().append("rect").attr("class","item item-block-year").attr("width",function(){return(calendarHeatmap.settings.width-calendarHeatmap.settings.label_padding)/r.length-5*calendarHeatmap.settings.gutter}).attr("height",function(){return calendarHeatmap.settings.height-calendarHeatmap.settings.label_padding}).attr("transform",function(a){return"translate("+i(a.date.year())+","+2*calendarHeatmap.settings.tooltip_padding+")"}).attr("fill",function(a){var e=d3.scale.linear().range(["#ffffff",calendarHeatmap.color||"#ff4500"]).domain([-.15*n,n]);return e(a.total)||"#ff4500"}).on("click",function(a){calendarHeatmap.in_transition||(calendarHeatmap.in_transition=!0,calendarHeatmap.selected=a,calendarHeatmap.hideTooltip(),calendarHeatmap.removeGlobalOverview(),calendarHeatmap.overview="year",calendarHeatmap.drawChart())}).style("opacity",0).on("mouseover",function(a){if(!calendarHeatmap.in_transition){var e="";e+="<div><span><strong>Total time tracked:</strong></span>";var t=parseInt(a.total,10),n=Math.floor(t/86400);n>0&&(e+="<span>"+(1===n?"1 day":n+" days")+"</span></div>");var r=Math.floor((t-86400*n)/3600);r>0&&(e+=n>0?"<div><span></span><span>"+(1===r?"1 hour":r+" hours")+"</span></div>":"<span>"+(1===r?"1 hour":r+" hours")+"</span></div>");var l=Math.floor((t-86400*n-3600*r)/60);if(l>0&&(e+=n>0||r>0?"<div><span></span><span>"+(1===l?"1 minute":l+" minutes")+"</span></div>":"<span>"+(1===l?"1 minute":l+" minutes")+"</span></div>"),e+="<br />",a.summary.length<=5)for(var d=0;d<a.summary.length;d++)e+="<div><span><strong>"+a.summary[d].name+"</strong></span>",e+="<span>"+calendarHeatmap.formatTime(a.summary[d].value)+"</span></div>";else{for(var d=0;d<5;d++)e+="<div><span><strong>"+a.summary[d].name+"</strong></span>",e+="<span>"+calendarHeatmap.formatTime(a.summary[d].value)+"</span></div>";e+="<br />";for(var o=0,d=5;d<a.summary.length;d++)o=+a.summary[d].value;e+="<div><span><strong>Other:</strong></span>",e+="<span>"+calendarHeatmap.formatTime(o)+"</span></div>"}for(var s=i(a.date.year())+2*calendarHeatmap.settings.tooltip_padding;calendarHeatmap.settings.width-s<calendarHeatmap.settings.tooltip_width+5*calendarHeatmap.settings.tooltip_padding;)s-=10;var m=3*calendarHeatmap.settings.tooltip_padding;calendarHeatmap.tooltip.html(e).style("left",s+"px").style("top",m+"px").transition().duration(calendarHeatmap.settings.transition_duration/2).ease("ease-in").style("opacity",1)}}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.hideTooltip()}).transition().delay(function(a,e){return calendarHeatmap.settings.transition_duration*(e+1)/10}).duration(function(){return calendarHeatmap.settings.transition_duration}).ease("ease-in").style("opacity",1).call(function(a,e){a.empty()&&e();var t=0;a.each(function(){++t}).each("end",function(){--t||e.apply(this,arguments)})},function(){calendarHeatmap.in_transition=!1});calendarHeatmap.labels.selectAll(".label-year").remove(),calendarHeatmap.labels.selectAll(".label-year").data(r).enter().append("text").attr("class","label label-year").attr("font-size",function(){return Math.floor(calendarHeatmap.settings.label_padding/3)+"px"}).text(function(a){return a.year()}).attr("x",function(a){return i(a.year())}).attr("y",calendarHeatmap.settings.label_padding/2).on("mouseenter",function(a){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-block-year").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").style("opacity",function(e){return moment(e.date).year()===a.year()?1:.1})}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-block-year").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").style("opacity",1)}).on("click",function(a){calendarHeatmap.in_transition||(calendarHeatmap.in_transition=!0,calendarHeatmap.selected=a,calendarHeatmap.hideTooltip(),calendarHeatmap.removeGlobalOverview(),calendarHeatmap.overview="year",calendarHeatmap.drawChart())})},drawYearOverview:function(){calendarHeatmap.history[calendarHeatmap.history.length-1]!==calendarHeatmap.overview&&calendarHeatmap.history.push(calendarHeatmap.overview);var a=moment(calendarHeatmap.selected.date).startOf("year"),e=moment(calendarHeatmap.selected.date).endOf("year"),t=calendarHeatmap.data.filter(function(t){return a<=moment(t.date)&&moment(t.date)<e}),n=d3.max(t,function(a){return a.total}),r=d3.scale.linear().range(["#ffffff",calendarHeatmap.color||"#ff4500"]).domain([-.15*n,n]),i=function(e){var t=moment(e.date),n=Math.round((t-moment(a).startOf("week"))/864e5),r=Math.trunc(n/7);return r*(calendarHeatmap.settings.item_size+calendarHeatmap.settings.gutter)+calendarHeatmap.settings.label_padding},l=function(a){return calendarHeatmap.settings.label_padding+moment(a.date).weekday()*(calendarHeatmap.settings.item_size+calendarHeatmap.settings.gutter)},d=function(a){return n<=0?calendarHeatmap.settings.item_size:.75*calendarHeatmap.settings.item_size+calendarHeatmap.settings.item_size*a.total/n*.25};calendarHeatmap.items.selectAll(".item-circle").remove(),calendarHeatmap.items.selectAll(".item-circle").data(t).enter().append("rect").attr("class","item item-circle").style("opacity",0).attr("x",function(a){return i(a)+(calendarHeatmap.settings.item_size-d(a))/2}).attr("y",function(a){return l(a)+(calendarHeatmap.settings.item_size-d(a))/2}).attr("rx",function(a){return d(a)}).attr("ry",function(a){return d(a)}).attr("width",function(a){return d(a)}).attr("height",function(a){return d(a)}).attr("fill",function(a){return a.total>0?r(a.total):"transparent"}).on("click",function(a){calendarHeatmap.in_transition||0!==a.total&&(calendarHeatmap.in_transition=!0,calendarHeatmap.selected=a,calendarHeatmap.hideTooltip(),calendarHeatmap.removeYearOverview(),calendarHeatmap.overview="day",calendarHeatmap.drawChart())}).on("mouseover",function(a){if(!calendarHeatmap.in_transition){var e=d3.select(this);!function s(){e=e.transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").attr("x",function(a){return i(a)-(1.1*calendarHeatmap.settings.item_size-calendarHeatmap.settings.item_size)/2}).attr("y",function(a){return l(a)-(1.1*calendarHeatmap.settings.item_size-calendarHeatmap.settings.item_size)/2}).attr("width",1.1*calendarHeatmap.settings.item_size).attr("height",1.1*calendarHeatmap.settings.item_size).transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").attr("x",function(a){return i(a)+(calendarHeatmap.settings.item_size-d(a))/2}).attr("y",function(a){return l(a)+(calendarHeatmap.settings.item_size-d(a))/2}).attr("width",function(a){return d(a)}).attr("height",function(a){return d(a)}).each("end",s)}();var t="";t+='<div class="header"><strong>'+(a.total?calendarHeatmap.formatTime(a.total):"No time")+" tracked</strong></div>",t+="<div>on "+moment(a.date).format("dddd, MMM Do YYYY")+"</div><br>";for(var n=0;n<a.summary.length;n++)t+="<div><span><strong>"+a.summary[n].name+"</strong></span>",t+="<span>"+calendarHeatmap.formatTime(a.summary[n].value)+"</span></div>";var r=i(a)+calendarHeatmap.settings.item_size;calendarHeatmap.settings.width-r<calendarHeatmap.settings.tooltip_width+3*calendarHeatmap.settings.tooltip_padding&&(r-=calendarHeatmap.settings.tooltip_width+2*calendarHeatmap.settings.tooltip_padding);var o=l(a)+calendarHeatmap.settings.item_size;calendarHeatmap.tooltip.html(t).style("left",r+"px").style("top",o+"px").transition().duration(calendarHeatmap.settings.transition_duration/2).ease("ease-in").style("opacity",1)}}).on("mouseout",function(){calendarHeatmap.in_transition||(d3.select(this).transition().duration(calendarHeatmap.settings.transition_duration/2).ease("ease-in").attr("x",function(a){return i(a)+(calendarHeatmap.settings.item_size-d(a))/2}).attr("y",function(a){return l(a)+(calendarHeatmap.settings.item_size-d(a))/2}).attr("width",function(a){return d(a)}).attr("height",function(a){return d(a)}),calendarHeatmap.hideTooltip())}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*calendarHeatmap.settings.transition_duration}).duration(function(){return calendarHeatmap.settings.transition_duration}).ease("ease-in").style("opacity",1).call(function(a,e){a.empty()&&e();var t=0;a.each(function(){++t}).each("end",function(){--t||e.apply(this,arguments)})},function(){calendarHeatmap.in_transition=!1});var o=d3.time.months(a,e),s=d3.scale.linear().range([0,calendarHeatmap.settings.width]).domain([0,o.length]);calendarHeatmap.labels.selectAll(".label-month").remove(),calendarHeatmap.labels.selectAll(".label-month").data(o).enter().append("text").attr("class","label label-month").attr("font-size",function(){return Math.floor(calendarHeatmap.settings.label_padding/3)+"px"}).text(function(a){return a.toLocaleDateString("en-us",{month:"short"})}).attr("x",function(a,e){return s(e)+(s(e)-s(e-1))/2}).attr("y",calendarHeatmap.settings.label_padding/2).on("mouseenter",function(a){if(!calendarHeatmap.in_transition){var e=moment(a);calendarHeatmap.items.selectAll(".item-circle").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").style("opacity",function(a){return moment(a.date).isSame(e,"month")?1:.1})}}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-circle").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").style("opacity",1)}).on("click",function(a){if(!calendarHeatmap.in_transition){var e=calendarHeatmap.data.filter(function(e){return moment(a).startOf("month")<=moment(e.date)&&moment(e.date)<moment(a).endOf("month")});e.length&&(calendarHeatmap.selected={date:a},calendarHeatmap.in_transition=!0,calendarHeatmap.hideTooltip(),calendarHeatmap.removeYearOverview(),calendarHeatmap.overview="month",calendarHeatmap.drawChart())}});var m=d3.time.days(moment().startOf("week"),moment().endOf("week")),c=d3.scale.ordinal().rangeRoundBands([calendarHeatmap.settings.label_padding,calendarHeatmap.settings.height]).domain(m.map(function(a){return moment(a).weekday()}));calendarHeatmap.labels.selectAll(".label-day").remove(),calendarHeatmap.labels.selectAll(".label-day").data(m).enter().append("text").attr("class","label label-day").attr("x",calendarHeatmap.settings.label_padding/3).attr("y",function(a,e){return c(e)+c.rangeBand()/1.75}).style("text-anchor","left").attr("font-size",function(){return Math.floor(calendarHeatmap.settings.label_padding/3)+"px"}).text(function(a){return moment(a).format("dddd")[0]}).on("mouseenter",function(a){if(!calendarHeatmap.in_transition){var e=moment(a);calendarHeatmap.items.selectAll(".item-circle").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").style("opacity",function(a){return moment(a.date).day()===e.day()?1:.1})}}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-circle").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").style("opacity",1)}),calendarHeatmap.drawButton()},drawMonthOverview:function(){calendarHeatmap.history[calendarHeatmap.history.length-1]!==calendarHeatmap.overview&&calendarHeatmap.history.push(calendarHeatmap.overview);for(var a=moment(calendarHeatmap.selected.date).startOf("month"),e=moment(calendarHeatmap.selected.date).endOf("month"),t=calendarHeatmap.data.filter(function(t){return a<=moment(t.date)&&moment(t.date)<e}),n=d3.max(t,function(a){return d3.max(a.summary,function(a){return a.value})}),r=d3.time.days(moment().startOf("week"),moment().endOf("week")),i=d3.scale.ordinal().rangeRoundBands([calendarHeatmap.settings.label_padding,calendarHeatmap.settings.height]).domain(r.map(function(a){return moment(a).weekday()})),l=[a.clone()];a.week()!==e.week();)l.push(a.add(1,"week").clone());var d=d3.scale.ordinal().rangeRoundBands([calendarHeatmap.settings.label_padding,calendarHeatmap.settings.width],.05).domain(l.map(function(a){return a.week()}));calendarHeatmap.items.selectAll(".item-block-month").remove();var o=calendarHeatmap.items.selectAll(".item-block-month").data(t).enter().append("g").attr("class","item item-block-month").attr("width",function(){return(calendarHeatmap.settings.width-calendarHeatmap.settings.label_padding)/l.length-5*calendarHeatmap.settings.gutter}).attr("height",function(){return Math.min(i.rangeBand(),calendarHeatmap.settings.max_block_height)}).attr("transform",function(a){return"translate("+d(moment(a.date).week())+","+(i(moment(a.date).weekday())+i.rangeBand()/1.75-15)+")"}).attr("total",function(a){return a.total}).attr("date",function(a){return a.date}).attr("offset",0).on("click",function(a){calendarHeatmap.in_transition||0!==a.total&&(calendarHeatmap.in_transition=!0,calendarHeatmap.selected=a,calendarHeatmap.hideTooltip(),calendarHeatmap.removeMonthOverview(),calendarHeatmap.overview="day",calendarHeatmap.drawChart())}),s=(calendarHeatmap.settings.width-calendarHeatmap.settings.label_padding)/l.length-5*calendarHeatmap.settings.gutter,m=d3.scale.linear().rangeRound([0,s]);o.selectAll(".item-block-rect").data(function(a){return a.summary}).enter().append("rect").attr("class","item item-block-rect").attr("x",function(a){var e=parseInt(d3.select(this.parentNode).attr("total")),t=parseInt(d3.select(this.parentNode).attr("offset"));return m.domain([0,e]),d3.select(this.parentNode).attr("offset",t+m(a.value)),t}).attr("width",function(a){var e=parseInt(d3.select(this.parentNode).attr("total"));return m.domain([0,e]),Math.max(m(a.value)-calendarHeatmap.settings.item_gutter,1)}).attr("height",function(){return Math.min(i.rangeBand(),calendarHeatmap.settings.max_block_height)}).attr("fill",function(a){var e=d3.scale.linear().range(["#ffffff",calendarHeatmap.color||"#ff4500"]).domain([-.15*n,n]);return e(a.value)||"#ff4500"}).style("opacity",0).on("mouseover",function(a){if(!calendarHeatmap.in_transition){var e=new Date(d3.select(this.parentNode).attr("date")),t="";t+='<div class="header"><strong>'+a.name+"</strong></div><br>",t+="<div><strong>"+(a.value?calendarHeatmap.formatTime(a.value):"No time")+" tracked</strong></div>",t+="<div>on "+moment(e).format("dddd, MMM Do YYYY")+"</div>";for(var n=d(moment(e).week())+calendarHeatmap.settings.tooltip_padding;calendarHeatmap.settings.width-n<calendarHeatmap.settings.tooltip_width+3*calendarHeatmap.settings.tooltip_padding;)n-=10;var r=i(moment(e).weekday())+2*calendarHeatmap.settings.tooltip_padding;calendarHeatmap.tooltip.html(t).style("left",n+"px").style("top",r+"px").transition().duration(calendarHeatmap.settings.transition_duration/2).ease("ease-in").style("opacity",1)}}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.hideTooltip()}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*calendarHeatmap.settings.transition_duration}).duration(function(){return calendarHeatmap.settings.transition_duration}).ease("ease-in").style("opacity",1).call(function(a,e){a.empty()&&e();var t=0;a.each(function(){++t}).each("end",function(){--t||e.apply(this,arguments)})},function(){calendarHeatmap.in_transition=!1}),calendarHeatmap.labels.selectAll(".label-week").remove(),calendarHeatmap.labels.selectAll(".label-week").data(l).enter().append("text").attr("class","label label-week").attr("font-size",function(){return Math.floor(calendarHeatmap.settings.label_padding/3)+"px"}).text(function(a){return"Week "+a.week()}).attr("x",function(a){return d(a.week())}).attr("y",calendarHeatmap.settings.label_padding/2).on("mouseenter",function(a){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-block-month").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").style("opacity",function(e){return moment(e.date).week()===a.week()?1:.1})}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-block-month").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").style("opacity",1)}).on("click",function(a){if(!calendarHeatmap.in_transition){var e=calendarHeatmap.data.filter(function(e){return a.startOf("week")<=moment(e.date)&&moment(e.date)<a.endOf("week")});e.length&&(calendarHeatmap.in_transition=!0,calendarHeatmap.selected={date:a},calendarHeatmap.hideTooltip(),calendarHeatmap.removeMonthOverview(),calendarHeatmap.overview="week",calendarHeatmap.drawChart())}}),calendarHeatmap.labels.selectAll(".label-day").remove(),calendarHeatmap.labels.selectAll(".label-day").data(r).enter().append("text").attr("class","label label-day").attr("x",calendarHeatmap.settings.label_padding/3).attr("y",function(a,e){return i(e)+i.rangeBand()/1.75}).style("text-anchor","left").attr("font-size",function(){return Math.floor(calendarHeatmap.settings.label_padding/3)+"px"}).text(function(a){return moment(a).format("dddd")[0]}).on("mouseenter",function(a){if(!calendarHeatmap.in_transition){var e=moment(a);calendarHeatmap.items.selectAll(".item-block-month").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").style("opacity",function(a){return moment(a.date).day()===e.day()?1:.1})}}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-block-month").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").style("opacity",1)}),calendarHeatmap.drawButton()},drawWeekOverview:function(){calendarHeatmap.history[calendarHeatmap.history.length-1]!==calendarHeatmap.overview&&calendarHeatmap.history.push(calendarHeatmap.overview);var a=moment(calendarHeatmap.selected.date).startOf("week"),e=moment(calendarHeatmap.selected.date).endOf("week"),t=calendarHeatmap.data.filter(function(t){return a<=moment(t.date)&&moment(t.date)<e}),n=d3.max(t,function(a){return d3.max(a.summary,function(a){return a.value})}),r=d3.time.days(moment().startOf("week"),moment().endOf("week")),i=d3.scale.ordinal().rangeRoundBands([calendarHeatmap.settings.label_padding,calendarHeatmap.settings.height]).domain(r.map(function(a){return moment(a).weekday()})),l=[a],d=d3.scale.ordinal().rangeRoundBands([calendarHeatmap.settings.label_padding,calendarHeatmap.settings.width],.01).domain(l.map(function(a){return a.week()}));calendarHeatmap.items.selectAll(".item-block-week").remove();var o=calendarHeatmap.items.selectAll(".item-block-week").data(t).enter().append("g").attr("class","item item-block-week").attr("width",function(){return(calendarHeatmap.settings.width-calendarHeatmap.settings.label_padding)/l.length-5*calendarHeatmap.settings.gutter}).attr("height",function(){return Math.min(i.rangeBand(),calendarHeatmap.settings.max_block_height)}).attr("transform",function(a){return"translate("+d(moment(a.date).week())+","+(i(moment(a.date).weekday())+i.rangeBand()/1.75-15)+")"}).attr("total",function(a){return a.total}).attr("date",function(a){return a.date}).attr("offset",0).on("click",function(a){calendarHeatmap.in_transition||0!==a.total&&(calendarHeatmap.in_transition=!0,calendarHeatmap.selected=a,calendarHeatmap.hideTooltip(),calendarHeatmap.removeWeekOverview(),calendarHeatmap.overview="day",calendarHeatmap.drawChart())}),s=(calendarHeatmap.settings.width-calendarHeatmap.settings.label_padding)/l.length-5*calendarHeatmap.settings.gutter,m=d3.scale.linear().rangeRound([0,s]);o.selectAll(".item-block-rect").data(function(a){return a.summary}).enter().append("rect").attr("class","item item-block-rect").attr("x",function(a){var e=parseInt(d3.select(this.parentNode).attr("total")),t=parseInt(d3.select(this.parentNode).attr("offset"));return m.domain([0,e]),d3.select(this.parentNode).attr("offset",t+m(a.value)),t}).attr("width",function(a){var e=parseInt(d3.select(this.parentNode).attr("total"));return m.domain([0,e]),Math.max(m(a.value)-calendarHeatmap.settings.item_gutter,1)}).attr("height",function(){return Math.min(i.rangeBand(),calendarHeatmap.settings.max_block_height)}).attr("fill",function(a){var e=d3.scale.linear().range(["#ffffff",calendarHeatmap.color||"#ff4500"]).domain([-.15*n,n]);return e(a.value)||"#ff4500"}).style("opacity",0).on("mouseover",function(a){if(!calendarHeatmap.in_transition){var e=new Date(d3.select(this.parentNode).attr("date")),t="";t+='<div class="header"><strong>'+a.name+"</strong></div><br>",t+="<div><strong>"+(a.value?calendarHeatmap.formatTime(a.value):"No time")+" tracked</strong></div>",t+="<div>on "+moment(e).format("dddd, MMM Do YYYY")+"</div>";var n=parseInt(d3.select(this.parentNode).attr("total"));m.domain([0,n]);for(var r=parseInt(d3.select(this).attr("x"))+m(a.value)/4+calendarHeatmap.settings.tooltip_width/4;calendarHeatmap.settings.width-r<calendarHeatmap.settings.tooltip_width+3*calendarHeatmap.settings.tooltip_padding;)r-=10;var l=i(moment(e).weekday())+1.5*calendarHeatmap.settings.tooltip_padding;calendarHeatmap.tooltip.html(t).style("left",r+"px").style("top",l+"px").transition().duration(calendarHeatmap.settings.transition_duration/2).ease("ease-in").style("opacity",1)}}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.hideTooltip()}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*calendarHeatmap.settings.transition_duration}).duration(function(){return calendarHeatmap.settings.transition_duration}).ease("ease-in").style("opacity",1).call(function(a,e){a.empty()&&e();var t=0;a.each(function(){++t}).each("end",function(){--t||e.apply(this,arguments)})},function(){calendarHeatmap.in_transition=!1}),calendarHeatmap.labels.selectAll(".label-week").remove(),calendarHeatmap.labels.selectAll(".label-week").data(l).enter().append("text").attr("class","label label-week").attr("font-size",function(){return Math.floor(calendarHeatmap.settings.label_padding/3)+"px"}).text(function(a){return"Week "+a.week()}).attr("x",function(a){return d(a.week())}).attr("y",calendarHeatmap.settings.label_padding/2).on("mouseenter",function(a){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-block-week").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").style("opacity",function(e){return moment(e.date).week()===a.week()?1:.1})}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-block-week").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").style("opacity",1)}),calendarHeatmap.labels.selectAll(".label-day").remove(),calendarHeatmap.labels.selectAll(".label-day").data(r).enter().append("text").attr("class","label label-day").attr("x",calendarHeatmap.settings.label_padding/3).attr("y",function(a,e){return i(e)+i.rangeBand()/1.75}).style("text-anchor","left").attr("font-size",function(){return Math.floor(calendarHeatmap.settings.label_padding/3)+"px"}).text(function(a){return moment(a).format("dddd")[0]}).on("mouseenter",function(a){if(!calendarHeatmap.in_transition){var e=moment(a);calendarHeatmap.items.selectAll(".item-block-week").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").style("opacity",function(a){return moment(a.date).day()===e.day()?1:.1})}}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-block-week").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").style("opacity",1)}),calendarHeatmap.drawButton()},drawDayOverview:function(){calendarHeatmap.history[calendarHeatmap.history.length-1]!==calendarHeatmap.overview&&calendarHeatmap.history.push(calendarHeatmap.overview),Object.keys(calendarHeatmap.selected).length||(calendarHeatmap.selected=calendarHeatmap.data[calendarHeatmap.data.length-1]);var a=calendarHeatmap.selected.summary.map(function(a){return a.name}),e=d3.scale.ordinal().rangeRoundBands([calendarHeatmap.settings.label_padding,calendarHeatmap.settings.height]).domain(a),t=d3.time.scale().range([2*calendarHeatmap.settings.label_padding,calendarHeatmap.settings.width]).domain([moment(calendarHeatmap.selected.date).startOf("day"),moment(calendarHeatmap.selected.date).endOf("day")]);calendarHeatmap.items.selectAll(".item-block").remove(),calendarHeatmap.items.selectAll(".item-block").data(calendarHeatmap.selected.details).enter().append("rect").attr("class","item item-block").attr("x",function(a){return t(moment(a.date))}).attr("y",function(a){return e(a.name)+e.rangeBand()/2-15}).attr("width",function(a){var e=t(d3.time.second.offset(moment(a.date),a.value));return Math.max(e-t(moment(a.date)),1)}).attr("height",function(){return Math.min(e.rangeBand(),calendarHeatmap.settings.max_block_height)}).attr("fill",function(){return calendarHeatmap.color||"#ff4500"}).style("opacity",0).on("mouseover",function(a){if(!calendarHeatmap.in_transition){var n="";n+='<div class="header"><strong>'+a.name+"</strong><div><br>",n+="<div><strong>"+(a.value?calendarHeatmap.formatTime(a.value):"No time")+" tracked</strong></div>",n+="<div>on "+moment(a.date).format("dddd, MMM Do YYYY HH:mm")+"</div>";for(var r=100*a.value/86400+t(moment(a.date));calendarHeatmap.settings.width-r<calendarHeatmap.settings.tooltip_width+3*calendarHeatmap.settings.tooltip_padding;)r-=10;var i=e(a.name)+e.rangeBand()/2+calendarHeatmap.settings.tooltip_padding/2;calendarHeatmap.tooltip.html(n).style("left",r+"px").style("top",i+"px").transition().duration(calendarHeatmap.settings.transition_duration/2).ease("ease-in").style("opacity",1)}}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.hideTooltip()}).on("click",function(a){calendarHeatmap.handler&&"function"==typeof calendarHeatmap.handler&&calendarHeatmap.handler(a)}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*calendarHeatmap.settings.transition_duration}).duration(function(){return calendarHeatmap.settings.transition_duration}).ease("ease-in").style("opacity",.5).call(function(a,e){a.empty()&&e();var t=0;a.each(function(){++t}).each("end",function(){--t||e.apply(this,arguments)})},function(){calendarHeatmap.in_transition=!1});var n=d3.time.hours(moment(calendarHeatmap.selected.date).startOf("day"),moment(calendarHeatmap.selected.date).endOf("day")),r=d3.time.scale().range([2*calendarHeatmap.settings.label_padding,calendarHeatmap.settings.width]).domain([0,n.length]);calendarHeatmap.labels.selectAll(".label-time").remove(),calendarHeatmap.labels.selectAll(".label-time").data(n).enter().append("text").attr("class","label label-time").attr("font-size",function(){return Math.floor(calendarHeatmap.settings.label_padding/3)+"px"}).text(function(a){return moment(a).format("HH:mm")}).attr("x",function(a,e){return r(e)}).attr("y",calendarHeatmap.settings.label_padding/2).on("mouseenter",function(a){if(!calendarHeatmap.in_transition){var e=t(moment(a));calendarHeatmap.items.selectAll(".item-block").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").style("opacity",function(a){var n=t(moment(a.date)),r=t(moment(a.date).add(a.value,"seconds"));return e>=n&&e<=r?1:.1})}}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-block").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").style("opacity",.5)}),calendarHeatmap.labels.selectAll(".label-project").remove(),calendarHeatmap.labels.selectAll(".label-project").data(a).enter().append("text").attr("class","label label-project").attr("x",calendarHeatmap.settings.gutter).attr("y",function(a){return e(a)+e.rangeBand()/2}).attr("min-height",function(){return e.rangeBand()}).style("text-anchor","left").attr("font-size",function(){return Math.floor(calendarHeatmap.settings.label_padding/3)+"px"}).text(function(a){return a}).each(function(){for(var a=d3.select(this),e=a.node().getComputedTextLength(),t=a.text();e>1.5*calendarHeatmap.settings.label_padding&&t.length>0;)t=t.slice(0,-1),a.text(t+"..."),e=a.node().getComputedTextLength()}).on("mouseenter",function(a){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-block").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").style("opacity",function(e){return e.name===a?1:.1})}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-block").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").style("opacity",.5)}),calendarHeatmap.drawButton()},drawButton:function(){calendarHeatmap.buttons.selectAll(".button").remove();var a=calendarHeatmap.buttons.append("g").attr("class","button button-back").style("opacity",0).on("click",function(){ | ||
calendarHeatmap.in_transition||(calendarHeatmap.in_transition=!0,"year"===calendarHeatmap.overview?calendarHeatmap.removeYearOverview():"month"===calendarHeatmap.overview?calendarHeatmap.removeMonthOverview():"week"===calendarHeatmap.overview?calendarHeatmap.removeWeekOverview():"day"===calendarHeatmap.overview&&calendarHeatmap.removeDayOverview(),calendarHeatmap.history.pop(),calendarHeatmap.overview=calendarHeatmap.history.pop(),calendarHeatmap.drawChart())});a.append("circle").attr("cx",calendarHeatmap.settings.label_padding/2.25).attr("cy",calendarHeatmap.settings.label_padding/2.5).attr("r",calendarHeatmap.settings.item_size/2),a.append("text").attr("x",calendarHeatmap.settings.label_padding/2.25).attr("y",calendarHeatmap.settings.label_padding/2.5).attr("dy",function(){return Math.floor(calendarHeatmap.settings.width/100)/3}).attr("font-size",function(){return Math.floor(calendarHeatmap.settings.label_padding/3)+"px"}).html("←"),a.transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").style("opacity",1)},removeGlobalOverview:function(){calendarHeatmap.items.selectAll(".item-block-year").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-out").style("opacity",0).remove(),calendarHeatmap.labels.selectAll(".label-year").remove()},removeYearOverview:function(){calendarHeatmap.items.selectAll(".item-circle").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease").style("opacity",0).remove(),calendarHeatmap.labels.selectAll(".label-day").remove(),calendarHeatmap.labels.selectAll(".label-month").remove(),calendarHeatmap.hideBackButton()},removeMonthOverview:function(){calendarHeatmap.items.selectAll(".item-block-month").selectAll(".item-block-rect").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").style("opacity",0).attr("x",function(a,e){return e%2===0?-calendarHeatmap.settings.width/3:calendarHeatmap.settings.width/3}).remove(),calendarHeatmap.labels.selectAll(".label-day").remove(),calendarHeatmap.labels.selectAll(".label-week").remove(),calendarHeatmap.hideBackButton()},removeWeekOverview:function(){calendarHeatmap.items.selectAll(".item-block-week").selectAll(".item-block-rect").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").style("opacity",0).attr("x",function(a,e){return e%2===0?-calendarHeatmap.settings.width/3:calendarHeatmap.settings.width/3}).remove(),calendarHeatmap.labels.selectAll(".label-day").remove(),calendarHeatmap.labels.selectAll(".label-week").remove(),calendarHeatmap.hideBackButton()},removeDayOverview:function(){calendarHeatmap.items.selectAll(".item-block").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease-in").style("opacity",0).attr("x",function(a,e){return e%2===0?-calendarHeatmap.settings.width/3:calendarHeatmap.settings.width/3}).remove(),calendarHeatmap.labels.selectAll(".label-time").remove(),calendarHeatmap.labels.selectAll(".label-project").remove(),calendarHeatmap.hideBackButton()},hideTooltip:function(){calendarHeatmap.tooltip.transition().duration(calendarHeatmap.settings.transition_duration/2).ease("ease-in").style("opacity",0)},hideBackButton:function(){calendarHeatmap.buttons.selectAll(".button").transition().duration(calendarHeatmap.settings.transition_duration).ease("ease").style("opacity",0).remove()},formatTime:function(a){var e=Math.floor(a/3600),t=Math.floor((a-3600*e)/60),n="";return e>0&&(n+=1===e?"1 hour ":e+" hours "),t>0&&(n+=1===t?"1 minute":t+" minutes"),0===e&&0===t&&(n=Math.round(a)+" seconds"),n}}; | ||
"use strict";var calendarHeatmap={settings:{gutter:5,item_gutter:1,width:1e3,height:200,item_size:10,label_padding:40,max_block_height:20,transition_duration:500,tooltip_width:250,tooltip_padding:15},init:function(a,e,t,n){calendarHeatmap.data=a,calendarHeatmap.color=e||"#ff4500",calendarHeatmap.overview=t||"global",calendarHeatmap.history=["global"],calendarHeatmap.selected={},calendarHeatmap.handler=n,calendarHeatmap.in_transition=!1,calendarHeatmap.createElements(),calendarHeatmap.parseData(),calendarHeatmap.drawChart()},createElements:function(){var a=document.createElement("div");a.className="calendar-heatmap",document.body.appendChild(a);var e=d3.select(a).append("svg").attr("class","svg");calendarHeatmap.items=e.append("g"),calendarHeatmap.labels=e.append("g"),calendarHeatmap.buttons=e.append("g"),calendarHeatmap.tooltip=d3.select(a).append("div").attr("class","heatmap-tooltip").style("opacity",0);var t=function(){var t=Math.round((moment()-moment().subtract(1,"year").startOf("week"))/864e5),n=Math.trunc(t/7)+1;calendarHeatmap.settings.width=a.offsetWidth<1e3?1e3:a.offsetWidth,calendarHeatmap.settings.item_size=(calendarHeatmap.settings.width-calendarHeatmap.settings.label_padding)/n-calendarHeatmap.settings.gutter,calendarHeatmap.settings.height=calendarHeatmap.settings.label_padding+7*(calendarHeatmap.settings.item_size+calendarHeatmap.settings.gutter),e.attr("width",calendarHeatmap.settings.width).attr("height",calendarHeatmap.settings.height),calendarHeatmap.data&&calendarHeatmap.data[0].summary&&calendarHeatmap.drawChart()};t(),window.onresize=function(a){t()}},parseData:function(){calendarHeatmap.data&&(calendarHeatmap.data[0].summary||calendarHeatmap.data.map(function(a){var e=a.details.reduce(function(a,e){return a[e.name]?a[e.name].value+=e.value:a[e.name]={value:e.value},a},{}),t=Object.keys(e).map(function(a){return{name:a,value:e[a].value}});return a.summary=t.sort(function(a,e){return e.value-a.value}),a}))},drawChart:function(){"global"===calendarHeatmap.overview?calendarHeatmap.drawGlobalOverview():"year"===calendarHeatmap.overview?calendarHeatmap.drawYearOverview():"month"===calendarHeatmap.overview?calendarHeatmap.drawMonthOverview():"week"===calendarHeatmap.overview?calendarHeatmap.drawWeekOverview():"day"===calendarHeatmap.overview&&calendarHeatmap.drawDayOverview()},drawGlobalOverview:function(){calendarHeatmap.history[calendarHeatmap.history.length-1]!==calendarHeatmap.overview&&calendarHeatmap.history.push(calendarHeatmap.overview);var a=moment(calendarHeatmap.data[0].date).startOf("year"),e=moment(calendarHeatmap.data[calendarHeatmap.data.length-1].date).endOf("year"),t=d3.timeYears(a,e).map(function(a){var e=moment(a);return{date:e,total:calendarHeatmap.data.reduce(function(a,t){return moment(t.date).year()===e.year()&&(a+=t.total),a},0),summary:function(){var a=calendarHeatmap.data.reduce(function(a,t){if(moment(t.date).year()===e.year())for(var n=0;n<t.summary.length;n++)a[t.summary[n].name]?a[t.summary[n].name].value+=t.summary[n].value:a[t.summary[n].name]={value:t.summary[n].value};return a},{});return Object.keys(a).map(function(e){return{name:e,value:a[e].value}}).sort(function(a,e){return e.value-a.value})}()}}),n=d3.max(t,function(a){return a.total}),r=d3.timeYears(a,e).map(function(a){return moment(a)}),i=d3.scaleBand().rangeRound([0,calendarHeatmap.settings.width]).padding([.05]).domain(r.map(function(a){return a.year()}));calendarHeatmap.items.selectAll(".item-block-year").remove();calendarHeatmap.items.selectAll(".item-block-year").data(t).enter().append("rect").attr("class","item item-block-year").attr("width",function(){return(calendarHeatmap.settings.width-calendarHeatmap.settings.label_padding)/r.length-5*calendarHeatmap.settings.gutter}).attr("height",function(){return calendarHeatmap.settings.height-calendarHeatmap.settings.label_padding}).attr("transform",function(a){return"translate("+i(a.date.year())+","+2*calendarHeatmap.settings.tooltip_padding+")"}).attr("fill",function(a){return d3.scaleLinear().range(["#ffffff",calendarHeatmap.color||"#ff4500"]).domain([-.15*n,n])(a.total)||"#ff4500"}).on("click",function(a){calendarHeatmap.in_transition||(calendarHeatmap.in_transition=!0,calendarHeatmap.selected=a,calendarHeatmap.hideTooltip(),calendarHeatmap.removeGlobalOverview(),calendarHeatmap.overview="year",calendarHeatmap.drawChart())}).style("opacity",0).on("mouseover",function(a){if(!calendarHeatmap.in_transition){var e="";e+="<div><span><strong>Total time tracked:</strong></span>";var t=parseInt(a.total,10),n=Math.floor(t/86400);n>0&&(e+="<span>"+(1===n?"1 day":n+" days")+"</span></div>");var r=Math.floor((t-86400*n)/3600);r>0&&(e+=n>0?"<div><span></span><span>"+(1===r?"1 hour":r+" hours")+"</span></div>":"<span>"+(1===r?"1 hour":r+" hours")+"</span></div>");var l=Math.floor((t-86400*n-3600*r)/60);if(l>0&&(e+=n>0||r>0?"<div><span></span><span>"+(1===l?"1 minute":l+" minutes")+"</span></div>":"<span>"+(1===l?"1 minute":l+" minutes")+"</span></div>"),e+="<br />",a.summary.length<=5)for(o=0;o<a.summary.length;o++)e+="<div><span><strong>"+a.summary[o].name+"</strong></span>",e+="<span>"+calendarHeatmap.formatTime(a.summary[o].value)+"</span></div>";else{for(o=0;o<5;o++)e+="<div><span><strong>"+a.summary[o].name+"</strong></span>",e+="<span>"+calendarHeatmap.formatTime(a.summary[o].value)+"</span></div>";e+="<br />";for(var d=0,o=5;o<a.summary.length;o++)d=+a.summary[o].value;e+="<div><span><strong>Other:</strong></span>",e+="<span>"+calendarHeatmap.formatTime(d)+"</span></div>"}for(var s=i(a.date.year())+2*calendarHeatmap.settings.tooltip_padding;calendarHeatmap.settings.width-s<calendarHeatmap.settings.tooltip_width+5*calendarHeatmap.settings.tooltip_padding;)s-=10;var m=3*calendarHeatmap.settings.tooltip_padding;calendarHeatmap.tooltip.html(e).style("left",s+"px").style("top",m+"px").transition().duration(calendarHeatmap.settings.transition_duration/2).ease(d3.easeLinear).style("opacity",1)}}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.hideTooltip()}).transition().delay(function(a,e){return calendarHeatmap.settings.transition_duration*(e+1)/10}).duration(function(){return calendarHeatmap.settings.transition_duration}).ease(d3.easeLinear).style("opacity",1).call(function(a,e){a.empty()&&e();var t=0;a.each(function(){++t}).on("end",function(){--t||e.apply(this,arguments)})},function(){calendarHeatmap.in_transition=!1});calendarHeatmap.labels.selectAll(".label-year").remove(),calendarHeatmap.labels.selectAll(".label-year").data(r).enter().append("text").attr("class","label label-year").attr("font-size",function(){return Math.floor(calendarHeatmap.settings.label_padding/3)+"px"}).text(function(a){return a.year()}).attr("x",function(a){return i(a.year())}).attr("y",calendarHeatmap.settings.label_padding/2).on("mouseenter",function(a){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-block-year").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",function(e){return moment(e.date).year()===a.year()?1:.1})}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-block-year").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",1)}).on("click",function(a){calendarHeatmap.in_transition||(calendarHeatmap.in_transition=!0,calendarHeatmap.selected=a,calendarHeatmap.hideTooltip(),calendarHeatmap.removeGlobalOverview(),calendarHeatmap.overview="year",calendarHeatmap.drawChart())})},drawYearOverview:function(){calendarHeatmap.history[calendarHeatmap.history.length-1]!==calendarHeatmap.overview&&calendarHeatmap.history.push(calendarHeatmap.overview);var a=moment(calendarHeatmap.selected.date).startOf("year"),e=moment(calendarHeatmap.selected.date).endOf("year"),t=calendarHeatmap.data.filter(function(t){return a<=moment(t.date)&&moment(t.date)<e}),n=d3.max(t,function(a){return a.total}),r=d3.scaleLinear().range(["#ffffff",calendarHeatmap.color||"#ff4500"]).domain([-.15*n,n]),i=function(e){var t=moment(e.date),n=Math.round((t-moment(a).startOf("week"))/864e5);return Math.trunc(n/7)*(calendarHeatmap.settings.item_size+calendarHeatmap.settings.gutter)+calendarHeatmap.settings.label_padding},l=function(a){return calendarHeatmap.settings.label_padding+moment(a.date).weekday()*(calendarHeatmap.settings.item_size+calendarHeatmap.settings.gutter)},d=function(a){return n<=0?calendarHeatmap.settings.item_size:.75*calendarHeatmap.settings.item_size+calendarHeatmap.settings.item_size*a.total/n*.25};calendarHeatmap.items.selectAll(".item-circle").remove(),calendarHeatmap.items.selectAll(".item-circle").data(t).enter().append("rect").attr("class","item item-circle").style("opacity",0).attr("x",function(a){return i(a)+(calendarHeatmap.settings.item_size-d(a))/2}).attr("y",function(a){return l(a)+(calendarHeatmap.settings.item_size-d(a))/2}).attr("rx",function(a){return d(a)}).attr("ry",function(a){return d(a)}).attr("width",function(a){return d(a)}).attr("height",function(a){return d(a)}).attr("fill",function(a){return a.total>0?r(a.total):"transparent"}).on("click",function(a){calendarHeatmap.in_transition||0!==a.total&&(calendarHeatmap.in_transition=!0,calendarHeatmap.selected=a,calendarHeatmap.hideTooltip(),calendarHeatmap.removeYearOverview(),calendarHeatmap.overview="day",calendarHeatmap.drawChart())}).on("mouseover",function(a){if(!calendarHeatmap.in_transition){var e=d3.select(this);!function a(){e=e.transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).attr("x",function(a){return i(a)-(1.1*calendarHeatmap.settings.item_size-calendarHeatmap.settings.item_size)/2}).attr("y",function(a){return l(a)-(1.1*calendarHeatmap.settings.item_size-calendarHeatmap.settings.item_size)/2}).attr("width",1.1*calendarHeatmap.settings.item_size).attr("height",1.1*calendarHeatmap.settings.item_size).transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).attr("x",function(a){return i(a)+(calendarHeatmap.settings.item_size-d(a))/2}).attr("y",function(a){return l(a)+(calendarHeatmap.settings.item_size-d(a))/2}).attr("width",function(a){return d(a)}).attr("height",function(a){return d(a)}).on("end",a)}();var t="";t+='<div class="header"><strong>'+(a.total?calendarHeatmap.formatTime(a.total):"No time")+" tracked</strong></div>",t+="<div>on "+moment(a.date).format("dddd, MMM Do YYYY")+"</div><br>";for(var n=0;n<a.summary.length;n++)t+="<div><span><strong>"+a.summary[n].name+"</strong></span>",t+="<span>"+calendarHeatmap.formatTime(a.summary[n].value)+"</span></div>";var r=i(a)+calendarHeatmap.settings.item_size;calendarHeatmap.settings.width-r<calendarHeatmap.settings.tooltip_width+3*calendarHeatmap.settings.tooltip_padding&&(r-=calendarHeatmap.settings.tooltip_width+2*calendarHeatmap.settings.tooltip_padding);var o=l(a)+calendarHeatmap.settings.item_size;calendarHeatmap.tooltip.html(t).style("left",r+"px").style("top",o+"px").transition().duration(calendarHeatmap.settings.transition_duration/2).ease(d3.easeLinear).style("opacity",1)}}).on("mouseout",function(){calendarHeatmap.in_transition||(d3.select(this).transition().duration(calendarHeatmap.settings.transition_duration/2).ease(d3.easeLinear).attr("x",function(a){return i(a)+(calendarHeatmap.settings.item_size-d(a))/2}).attr("y",function(a){return l(a)+(calendarHeatmap.settings.item_size-d(a))/2}).attr("width",function(a){return d(a)}).attr("height",function(a){return d(a)}),calendarHeatmap.hideTooltip())}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*calendarHeatmap.settings.transition_duration}).duration(function(){return calendarHeatmap.settings.transition_duration}).ease(d3.easeLinear).style("opacity",1).call(function(a,e){a.empty()&&e();var t=0;a.each(function(){++t}).on("end",function(){--t||e.apply(this,arguments)})},function(){calendarHeatmap.in_transition=!1});var o=d3.timeMonths(a,e),s=d3.scaleLinear().range([0,calendarHeatmap.settings.width]).domain([0,o.length]);calendarHeatmap.labels.selectAll(".label-month").remove(),calendarHeatmap.labels.selectAll(".label-month").data(o).enter().append("text").attr("class","label label-month").attr("font-size",function(){return Math.floor(calendarHeatmap.settings.label_padding/3)+"px"}).text(function(a){return a.toLocaleDateString("en-us",{month:"short"})}).attr("x",function(a,e){return s(e)+(s(e)-s(e-1))/2}).attr("y",calendarHeatmap.settings.label_padding/2).on("mouseenter",function(a){if(!calendarHeatmap.in_transition){var e=moment(a);calendarHeatmap.items.selectAll(".item-circle").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",function(a){return moment(a.date).isSame(e,"month")?1:.1})}}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-circle").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",1)}).on("click",function(a){calendarHeatmap.in_transition||calendarHeatmap.data.filter(function(e){return moment(a).startOf("month")<=moment(e.date)&&moment(e.date)<moment(a).endOf("month")}).length&&(calendarHeatmap.selected={date:a},calendarHeatmap.in_transition=!0,calendarHeatmap.hideTooltip(),calendarHeatmap.removeYearOverview(),calendarHeatmap.overview="month",calendarHeatmap.drawChart())});var m=d3.timeDays(moment().startOf("week"),moment().endOf("week")),c=d3.scaleBand().rangeRound([calendarHeatmap.settings.label_padding,calendarHeatmap.settings.height]).domain(m.map(function(a){return moment(a).weekday()}));calendarHeatmap.labels.selectAll(".label-day").remove(),calendarHeatmap.labels.selectAll(".label-day").data(m).enter().append("text").attr("class","label label-day").attr("x",calendarHeatmap.settings.label_padding/3).attr("y",function(a,e){return c(e)+c.bandwidth()/1.75}).style("text-anchor","left").attr("font-size",function(){return Math.floor(calendarHeatmap.settings.label_padding/3)+"px"}).text(function(a){return moment(a).format("dddd")[0]}).on("mouseenter",function(a){if(!calendarHeatmap.in_transition){var e=moment(a);calendarHeatmap.items.selectAll(".item-circle").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",function(a){return moment(a.date).day()===e.day()?1:.1})}}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-circle").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",1)}),calendarHeatmap.drawButton()},drawMonthOverview:function(){calendarHeatmap.history[calendarHeatmap.history.length-1]!==calendarHeatmap.overview&&calendarHeatmap.history.push(calendarHeatmap.overview);for(var a=moment(calendarHeatmap.selected.date).startOf("month"),e=moment(calendarHeatmap.selected.date).endOf("month"),t=calendarHeatmap.data.filter(function(t){return a<=moment(t.date)&&moment(t.date)<e}),n=d3.max(t,function(a){return d3.max(a.summary,function(a){return a.value})}),r=d3.timeDays(moment().startOf("week"),moment().endOf("week")),i=d3.scaleBand().rangeRound([calendarHeatmap.settings.label_padding,calendarHeatmap.settings.height]).domain(r.map(function(a){return moment(a).weekday()})),l=[a.clone()];a.week()!==e.week();)l.push(a.add(1,"week").clone());var d=d3.scaleBand().rangeRound([calendarHeatmap.settings.label_padding,calendarHeatmap.settings.width]).padding([.05]).domain(l.map(function(a){return a.week()}));calendarHeatmap.items.selectAll(".item-block-month").remove();var o=calendarHeatmap.items.selectAll(".item-block-month").data(t).enter().append("g").attr("class","item item-block-month").attr("width",function(){return(calendarHeatmap.settings.width-calendarHeatmap.settings.label_padding)/l.length-5*calendarHeatmap.settings.gutter}).attr("height",function(){return Math.min(i.bandwidth(),calendarHeatmap.settings.max_block_height)}).attr("transform",function(a){return"translate("+d(moment(a.date).week())+","+(i(moment(a.date).weekday())+i.bandwidth()/1.75-15)+")"}).attr("total",function(a){return a.total}).attr("date",function(a){return a.date}).attr("offset",0).on("click",function(a){calendarHeatmap.in_transition||0!==a.total&&(calendarHeatmap.in_transition=!0,calendarHeatmap.selected=a,calendarHeatmap.hideTooltip(),calendarHeatmap.removeMonthOverview(),calendarHeatmap.overview="day",calendarHeatmap.drawChart())}),s=(calendarHeatmap.settings.width-calendarHeatmap.settings.label_padding)/l.length-5*calendarHeatmap.settings.gutter,m=d3.scaleLinear().rangeRound([0,s]);o.selectAll(".item-block-rect").data(function(a){return a.summary}).enter().append("rect").attr("class","item item-block-rect").attr("x",function(a){var e=parseInt(d3.select(this.parentNode).attr("total")),t=parseInt(d3.select(this.parentNode).attr("offset"));return m.domain([0,e]),d3.select(this.parentNode).attr("offset",t+m(a.value)),t}).attr("width",function(a){var e=parseInt(d3.select(this.parentNode).attr("total"));return m.domain([0,e]),Math.max(m(a.value)-calendarHeatmap.settings.item_gutter,1)}).attr("height",function(){return Math.min(i.bandwidth(),calendarHeatmap.settings.max_block_height)}).attr("fill",function(a){return d3.scaleLinear().range(["#ffffff",calendarHeatmap.color||"#ff4500"]).domain([-.15*n,n])(a.value)||"#ff4500"}).style("opacity",0).on("mouseover",function(a){if(!calendarHeatmap.in_transition){var e=new Date(d3.select(this.parentNode).attr("date")),t="";t+='<div class="header"><strong>'+a.name+"</strong></div><br>",t+="<div><strong>"+(a.value?calendarHeatmap.formatTime(a.value):"No time")+" tracked</strong></div>",t+="<div>on "+moment(e).format("dddd, MMM Do YYYY")+"</div>";for(var n=d(moment(e).week())+calendarHeatmap.settings.tooltip_padding;calendarHeatmap.settings.width-n<calendarHeatmap.settings.tooltip_width+3*calendarHeatmap.settings.tooltip_padding;)n-=10;var r=i(moment(e).weekday())+2*calendarHeatmap.settings.tooltip_padding;calendarHeatmap.tooltip.html(t).style("left",n+"px").style("top",r+"px").transition().duration(calendarHeatmap.settings.transition_duration/2).ease(d3.easeLinear).style("opacity",1)}}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.hideTooltip()}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*calendarHeatmap.settings.transition_duration}).duration(function(){return calendarHeatmap.settings.transition_duration}).ease(d3.easeLinear).style("opacity",1).call(function(a,e){a.empty()&&e();var t=0;a.each(function(){++t}).on("end",function(){--t||e.apply(this,arguments)})},function(){calendarHeatmap.in_transition=!1}),calendarHeatmap.labels.selectAll(".label-week").remove(),calendarHeatmap.labels.selectAll(".label-week").data(l).enter().append("text").attr("class","label label-week").attr("font-size",function(){return Math.floor(calendarHeatmap.settings.label_padding/3)+"px"}).text(function(a){return"Week "+a.week()}).attr("x",function(a){return d(a.week())}).attr("y",calendarHeatmap.settings.label_padding/2).on("mouseenter",function(a){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-block-month").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",function(e){return moment(e.date).week()===a.week()?1:.1})}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-block-month").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",1)}).on("click",function(a){calendarHeatmap.in_transition||calendarHeatmap.data.filter(function(e){return a.startOf("week")<=moment(e.date)&&moment(e.date)<a.endOf("week")}).length&&(calendarHeatmap.in_transition=!0,calendarHeatmap.selected={date:a},calendarHeatmap.hideTooltip(),calendarHeatmap.removeMonthOverview(),calendarHeatmap.overview="week",calendarHeatmap.drawChart())}),calendarHeatmap.labels.selectAll(".label-day").remove(),calendarHeatmap.labels.selectAll(".label-day").data(r).enter().append("text").attr("class","label label-day").attr("x",calendarHeatmap.settings.label_padding/3).attr("y",function(a,e){return i(e)+i.bandwidth()/1.75}).style("text-anchor","left").attr("font-size",function(){return Math.floor(calendarHeatmap.settings.label_padding/3)+"px"}).text(function(a){return moment(a).format("dddd")[0]}).on("mouseenter",function(a){if(!calendarHeatmap.in_transition){var e=moment(a);calendarHeatmap.items.selectAll(".item-block-month").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",function(a){return moment(a.date).day()===e.day()?1:.1})}}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-block-month").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",1)}),calendarHeatmap.drawButton()},drawWeekOverview:function(){calendarHeatmap.history[calendarHeatmap.history.length-1]!==calendarHeatmap.overview&&calendarHeatmap.history.push(calendarHeatmap.overview);var a=moment(calendarHeatmap.selected.date).startOf("week"),e=moment(calendarHeatmap.selected.date).endOf("week"),t=calendarHeatmap.data.filter(function(t){return a<=moment(t.date)&&moment(t.date)<e}),n=d3.max(t,function(a){return d3.max(a.summary,function(a){return a.value})}),r=d3.timeDays(moment().startOf("week"),moment().endOf("week")),i=d3.scaleBand().rangeRound([calendarHeatmap.settings.label_padding,calendarHeatmap.settings.height]).domain(r.map(function(a){return moment(a).weekday()})),l=[a],d=d3.scaleBand().rangeRound([calendarHeatmap.settings.label_padding,calendarHeatmap.settings.width]).padding([.01]).domain(l.map(function(a){return a.week()}));calendarHeatmap.items.selectAll(".item-block-week").remove();var o=calendarHeatmap.items.selectAll(".item-block-week").data(t).enter().append("g").attr("class","item item-block-week").attr("width",function(){return(calendarHeatmap.settings.width-calendarHeatmap.settings.label_padding)/l.length-5*calendarHeatmap.settings.gutter}).attr("height",function(){return Math.min(i.bandwidth(),calendarHeatmap.settings.max_block_height)}).attr("transform",function(a){return"translate("+d(moment(a.date).week())+","+(i(moment(a.date).weekday())+i.bandwidth()/1.75-15)+")"}).attr("total",function(a){return a.total}).attr("date",function(a){return a.date}).attr("offset",0).on("click",function(a){calendarHeatmap.in_transition||0!==a.total&&(calendarHeatmap.in_transition=!0,calendarHeatmap.selected=a,calendarHeatmap.hideTooltip(),calendarHeatmap.removeWeekOverview(),calendarHeatmap.overview="day",calendarHeatmap.drawChart())}),s=(calendarHeatmap.settings.width-calendarHeatmap.settings.label_padding)/l.length-5*calendarHeatmap.settings.gutter,m=d3.scaleLinear().rangeRound([0,s]);o.selectAll(".item-block-rect").data(function(a){return a.summary}).enter().append("rect").attr("class","item item-block-rect").attr("x",function(a){var e=parseInt(d3.select(this.parentNode).attr("total")),t=parseInt(d3.select(this.parentNode).attr("offset"));return m.domain([0,e]),d3.select(this.parentNode).attr("offset",t+m(a.value)),t}).attr("width",function(a){var e=parseInt(d3.select(this.parentNode).attr("total"));return m.domain([0,e]),Math.max(m(a.value)-calendarHeatmap.settings.item_gutter,1)}).attr("height",function(){return Math.min(i.bandwidth(),calendarHeatmap.settings.max_block_height)}).attr("fill",function(a){return d3.scaleLinear().range(["#ffffff",calendarHeatmap.color||"#ff4500"]).domain([-.15*n,n])(a.value)||"#ff4500"}).style("opacity",0).on("mouseover",function(a){if(!calendarHeatmap.in_transition){var e=new Date(d3.select(this.parentNode).attr("date")),t="";t+='<div class="header"><strong>'+a.name+"</strong></div><br>",t+="<div><strong>"+(a.value?calendarHeatmap.formatTime(a.value):"No time")+" tracked</strong></div>",t+="<div>on "+moment(e).format("dddd, MMM Do YYYY")+"</div>";var n=parseInt(d3.select(this.parentNode).attr("total"));m.domain([0,n]);for(var r=parseInt(d3.select(this).attr("x"))+m(a.value)/4+calendarHeatmap.settings.tooltip_width/4;calendarHeatmap.settings.width-r<calendarHeatmap.settings.tooltip_width+3*calendarHeatmap.settings.tooltip_padding;)r-=10;var l=i(moment(e).weekday())+1.5*calendarHeatmap.settings.tooltip_padding;calendarHeatmap.tooltip.html(t).style("left",r+"px").style("top",l+"px").transition().duration(calendarHeatmap.settings.transition_duration/2).ease(d3.easeLinear).style("opacity",1)}}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.hideTooltip()}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*calendarHeatmap.settings.transition_duration}).duration(function(){return calendarHeatmap.settings.transition_duration}).ease(d3.easeLinear).style("opacity",1).call(function(a,e){a.empty()&&e();var t=0;a.each(function(){++t}).on("end",function(){--t||e.apply(this,arguments)})},function(){calendarHeatmap.in_transition=!1}),calendarHeatmap.labels.selectAll(".label-week").remove(),calendarHeatmap.labels.selectAll(".label-week").data(l).enter().append("text").attr("class","label label-week").attr("font-size",function(){return Math.floor(calendarHeatmap.settings.label_padding/3)+"px"}).text(function(a){return"Week "+a.week()}).attr("x",function(a){return d(a.week())}).attr("y",calendarHeatmap.settings.label_padding/2).on("mouseenter",function(a){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-block-week").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",function(e){return moment(e.date).week()===a.week()?1:.1})}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-block-week").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",1)}),calendarHeatmap.labels.selectAll(".label-day").remove(),calendarHeatmap.labels.selectAll(".label-day").data(r).enter().append("text").attr("class","label label-day").attr("x",calendarHeatmap.settings.label_padding/3).attr("y",function(a,e){return i(e)+i.bandwidth()/1.75}).style("text-anchor","left").attr("font-size",function(){return Math.floor(calendarHeatmap.settings.label_padding/3)+"px"}).text(function(a){return moment(a).format("dddd")[0]}).on("mouseenter",function(a){if(!calendarHeatmap.in_transition){var e=moment(a);calendarHeatmap.items.selectAll(".item-block-week").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",function(a){return moment(a.date).day()===e.day()?1:.1})}}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-block-week").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",1)}),calendarHeatmap.drawButton()},drawDayOverview:function(){calendarHeatmap.history[calendarHeatmap.history.length-1]!==calendarHeatmap.overview&&calendarHeatmap.history.push(calendarHeatmap.overview),Object.keys(calendarHeatmap.selected).length||(calendarHeatmap.selected=calendarHeatmap.data[calendarHeatmap.data.length-1]);var a=calendarHeatmap.selected.summary.map(function(a){return a.name}),e=d3.scaleBand().rangeRound([calendarHeatmap.settings.label_padding,calendarHeatmap.settings.height]).domain(a),t=d3.scaleTime().range([2*calendarHeatmap.settings.label_padding,calendarHeatmap.settings.width]).domain([moment(calendarHeatmap.selected.date).startOf("day"),moment(calendarHeatmap.selected.date).endOf("day")]);calendarHeatmap.items.selectAll(".item-block").remove(),calendarHeatmap.items.selectAll(".item-block").data(calendarHeatmap.selected.details).enter().append("rect").attr("class","item item-block").attr("x",function(a){return t(moment(a.date))}).attr("y",function(a){return e(a.name)+e.bandwidth()/2-15}).attr("width",function(a){var e=t(d3.timeSecond.offset(moment(a.date),a.value));return Math.max(e-t(moment(a.date)),1)}).attr("height",function(){return Math.min(e.bandwidth(),calendarHeatmap.settings.max_block_height)}).attr("fill",function(){return calendarHeatmap.color||"#ff4500"}).style("opacity",0).on("mouseover",function(a){if(!calendarHeatmap.in_transition){var n="";n+='<div class="header"><strong>'+a.name+"</strong><div><br>",n+="<div><strong>"+(a.value?calendarHeatmap.formatTime(a.value):"No time")+" tracked</strong></div>",n+="<div>on "+moment(a.date).format("dddd, MMM Do YYYY HH:mm")+"</div>";for(var r=100*a.value/86400+t(moment(a.date));calendarHeatmap.settings.width-r<calendarHeatmap.settings.tooltip_width+3*calendarHeatmap.settings.tooltip_padding;)r-=10;var i=e(a.name)+e.bandwidth()/2+calendarHeatmap.settings.tooltip_padding/2;calendarHeatmap.tooltip.html(n).style("left",r+"px").style("top",i+"px").transition().duration(calendarHeatmap.settings.transition_duration/2).ease(d3.easeLinear).style("opacity",1)}}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.hideTooltip()}).on("click",function(a){calendarHeatmap.handler&&"function"==typeof calendarHeatmap.handler&&calendarHeatmap.handler(a)}).transition().delay(function(){return(Math.cos(Math.PI*Math.random())+1)*calendarHeatmap.settings.transition_duration}).duration(function(){return calendarHeatmap.settings.transition_duration}).ease(d3.easeLinear).style("opacity",.5).call(function(a,e){a.empty()&&e();var t=0;a.each(function(){++t}).on("end",function(){--t||e.apply(this,arguments)})},function(){calendarHeatmap.in_transition=!1});var n=d3.timeHours(moment(calendarHeatmap.selected.date).startOf("day"),moment(calendarHeatmap.selected.date).endOf("day")),r=d3.scaleTime().range([2*calendarHeatmap.settings.label_padding,calendarHeatmap.settings.width]).domain([0,n.length]);calendarHeatmap.labels.selectAll(".label-time").remove(),calendarHeatmap.labels.selectAll(".label-time").data(n).enter().append("text").attr("class","label label-time").attr("font-size",function(){return Math.floor(calendarHeatmap.settings.label_padding/3)+"px"}).text(function(a){return moment(a).format("HH:mm")}).attr("x",function(a,e){return r(e)}).attr("y",calendarHeatmap.settings.label_padding/2).on("mouseenter",function(a){if(!calendarHeatmap.in_transition){var e=t(moment(a));calendarHeatmap.items.selectAll(".item-block").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",function(a){var n=t(moment(a.date)),r=t(moment(a.date).add(a.value,"seconds"));return e>=n&&e<=r?1:.1})}}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-block").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",.5)}),calendarHeatmap.labels.selectAll(".label-project").remove(),calendarHeatmap.labels.selectAll(".label-project").data(a).enter().append("text").attr("class","label label-project").attr("x",calendarHeatmap.settings.gutter).attr("y",function(a){return e(a)+e.bandwidth()/2}).attr("min-height",function(){return e.bandwidth()}).style("text-anchor","left").attr("font-size",function(){return Math.floor(calendarHeatmap.settings.label_padding/3)+"px"}).text(function(a){return a}).each(function(){for(var a=d3.select(this),e=a.node().getComputedTextLength(),t=a.text();e>1.5*calendarHeatmap.settings.label_padding&&t.length>0;)t=t.slice(0,-1),a.text(t+"..."),e=a.node().getComputedTextLength()}).on("mouseenter",function(a){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-block").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",function(e){return e.name===a?1:.1})}).on("mouseout",function(){calendarHeatmap.in_transition||calendarHeatmap.items.selectAll(".item-block").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",.5)}),calendarHeatmap.drawButton()},drawButton:function(){calendarHeatmap.buttons.selectAll(".button").remove();var a=calendarHeatmap.buttons.append("g").attr("class","button button-back").style("opacity",0).on("click",function(){calendarHeatmap.in_transition||(calendarHeatmap.in_transition=!0,"year"===calendarHeatmap.overview?calendarHeatmap.removeYearOverview():"month"===calendarHeatmap.overview?calendarHeatmap.removeMonthOverview():"week"===calendarHeatmap.overview?calendarHeatmap.removeWeekOverview():"day"===calendarHeatmap.overview&&calendarHeatmap.removeDayOverview(),calendarHeatmap.history.pop(),calendarHeatmap.overview=calendarHeatmap.history.pop(),calendarHeatmap.drawChart())});a.append("circle").attr("cx",calendarHeatmap.settings.label_padding/2.25).attr("cy",calendarHeatmap.settings.label_padding/2.5).attr("r",calendarHeatmap.settings.item_size/2),a.append("text").attr("x",calendarHeatmap.settings.label_padding/2.25).attr("y",calendarHeatmap.settings.label_padding/2.5).attr("dy",function(){return Math.floor(calendarHeatmap.settings.width/100)/3}).attr("font-size",function(){return Math.floor(calendarHeatmap.settings.label_padding/3)+"px"}).html("←"),a.transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",1)},removeGlobalOverview:function(){calendarHeatmap.items.selectAll(".item-block-year").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",0).remove(),calendarHeatmap.labels.selectAll(".label-year").remove()},removeYearOverview:function(){calendarHeatmap.items.selectAll(".item-circle").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",0).remove(),calendarHeatmap.labels.selectAll(".label-day").remove(),calendarHeatmap.labels.selectAll(".label-month").remove(),calendarHeatmap.hideBackButton()},removeMonthOverview:function(){calendarHeatmap.items.selectAll(".item-block-month").selectAll(".item-block-rect").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",0).attr("x",function(a,e){return e%2==0?-calendarHeatmap.settings.width/3:calendarHeatmap.settings.width/3}).remove(),calendarHeatmap.labels.selectAll(".label-day").remove(),calendarHeatmap.labels.selectAll(".label-week").remove(),calendarHeatmap.hideBackButton()},removeWeekOverview:function(){calendarHeatmap.items.selectAll(".item-block-week").selectAll(".item-block-rect").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",0).attr("x",function(a,e){return e%2==0?-calendarHeatmap.settings.width/3:calendarHeatmap.settings.width/3}).remove(),calendarHeatmap.labels.selectAll(".label-day").remove(),calendarHeatmap.labels.selectAll(".label-week").remove(),calendarHeatmap.hideBackButton()},removeDayOverview:function(){calendarHeatmap.items.selectAll(".item-block").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",0).attr("x",function(a,e){return e%2==0?-calendarHeatmap.settings.width/3:calendarHeatmap.settings.width/3}).remove(),calendarHeatmap.labels.selectAll(".label-time").remove(),calendarHeatmap.labels.selectAll(".label-project").remove(),calendarHeatmap.hideBackButton()},hideTooltip:function(){calendarHeatmap.tooltip.transition().duration(calendarHeatmap.settings.transition_duration/2).ease(d3.easeLinear).style("opacity",0)},hideBackButton:function(){calendarHeatmap.buttons.selectAll(".button").transition().duration(calendarHeatmap.settings.transition_duration).ease(d3.easeLinear).style("opacity",0).remove()},formatTime:function(a){var e=Math.floor(a/3600),t=Math.floor((a-3600*e)/60),n="";return e>0&&(n+=1===e?"1 hour ":e+" hours "),t>0&&(n+=1===t?"1 minute":t+" minutes"),0===e&&0===t&&(n=Math.round(a)+" seconds"),n}}; |
{ | ||
"name": "calendar-heatmap-graph", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "d3.js calendar heatmap graph.", | ||
@@ -20,4 +20,4 @@ "homepage": "https://github.com/g1eb/calendar-heatmap#readme", | ||
"dependencies": { | ||
"d3": "^3.5.16", | ||
"moment": "^2.13.0" | ||
"d3": "^4.10.2", | ||
"moment": "^2.18.1" | ||
}, | ||
@@ -24,0 +24,0 @@ "devDependencies": { |
@@ -24,3 +24,3 @@ 'use strict'; | ||
*/ | ||
init: function (data, color, overview, handler) { | ||
init: function(data, color, overview, handler) { | ||
@@ -58,3 +58,3 @@ // Set calendar data | ||
*/ | ||
createElements: function () { | ||
createElements: function() { | ||
// Create main html container for the calendar | ||
@@ -80,3 +80,3 @@ var container = document.createElement('div'); | ||
// Calculate dimensions based on available width | ||
var calcDimensions = function () { | ||
var calcDimensions = function() { | ||
@@ -90,5 +90,6 @@ var dayIndex = Math.round((moment() - moment().subtract(1, 'year').startOf('week')) / 86400000); | ||
calendarHeatmap.settings.height = calendarHeatmap.settings.label_padding + 7 * (calendarHeatmap.settings.item_size + calendarHeatmap.settings.gutter); | ||
svg.attr({'width': calendarHeatmap.settings.width, 'height': calendarHeatmap.settings.height}); | ||
svg.attr('width', calendarHeatmap.settings.width) | ||
.attr('height', calendarHeatmap.settings.height); | ||
if ( !!calendarHeatmap.data && !!calendarHeatmap.data[0].summary ) { | ||
if (!!calendarHeatmap.data && !!calendarHeatmap.data[0].summary) { | ||
calendarHeatmap.drawChart(); | ||
@@ -108,10 +109,10 @@ } | ||
*/ | ||
parseData: function () { | ||
if ( !calendarHeatmap.data ) { return; } | ||
parseData: function() { | ||
if (!calendarHeatmap.data) { return; } | ||
// Get daily summary if that was not provided | ||
if ( !calendarHeatmap.data[0].summary ) { | ||
calendarHeatmap.data.map(function (d) { | ||
var summary = d.details.reduce( function(uniques, project) { | ||
if ( !uniques[project.name] ) { | ||
if (!calendarHeatmap.data[0].summary) { | ||
calendarHeatmap.data.map(function(d) { | ||
var summary = d.details.reduce(function(uniques, project) { | ||
if (!uniques[project.name]) { | ||
uniques[project.name] = { | ||
@@ -125,3 +126,3 @@ 'value': project.value | ||
}, {}); | ||
var unsorted_summary = Object.keys(summary).map(function (key) { | ||
var unsorted_summary = Object.keys(summary).map(function(key) { | ||
return { | ||
@@ -132,3 +133,3 @@ 'name': key, | ||
}); | ||
d.summary = unsorted_summary.sort(function (a, b) { | ||
d.summary = unsorted_summary.sort(function(a, b) { | ||
return b.value - a.value; | ||
@@ -145,12 +146,12 @@ }); | ||
*/ | ||
drawChart: function () { | ||
if ( calendarHeatmap.overview === 'global' ) { | ||
drawChart: function() { | ||
if (calendarHeatmap.overview === 'global') { | ||
calendarHeatmap.drawGlobalOverview(); | ||
} else if ( calendarHeatmap.overview === 'year' ) { | ||
} else if (calendarHeatmap.overview === 'year') { | ||
calendarHeatmap.drawYearOverview(); | ||
} else if ( calendarHeatmap.overview === 'month' ) { | ||
} else if (calendarHeatmap.overview === 'month') { | ||
calendarHeatmap.drawMonthOverview(); | ||
} else if ( calendarHeatmap.overview === 'week' ) { | ||
} else if (calendarHeatmap.overview === 'week') { | ||
calendarHeatmap.drawWeekOverview(); | ||
} else if ( calendarHeatmap.overview === 'day' ) { | ||
} else if (calendarHeatmap.overview === 'day') { | ||
calendarHeatmap.drawDayOverview(); | ||
@@ -164,5 +165,5 @@ } | ||
*/ | ||
drawGlobalOverview: function () { | ||
drawGlobalOverview: function() { | ||
// Add current overview to the history | ||
if ( calendarHeatmap.history[calendarHeatmap.history.length-1] !== calendarHeatmap.overview ) { | ||
if (calendarHeatmap.history[calendarHeatmap.history.length - 1] !== calendarHeatmap.overview) { | ||
calendarHeatmap.history.push(calendarHeatmap.overview); | ||
@@ -173,11 +174,11 @@ } | ||
var start = moment(calendarHeatmap.data[0].date).startOf('year'); | ||
var end = moment(calendarHeatmap.data[calendarHeatmap.data.length-1].date).endOf('year'); | ||
var end = moment(calendarHeatmap.data[calendarHeatmap.data.length - 1].date).endOf('year'); | ||
// Define array of years and total values | ||
var year_data = d3.time.years(start, end).map(function (d) { | ||
var year_data = d3.timeYears(start, end).map(function(d) { | ||
var date = moment(d); | ||
return { | ||
'date': date, | ||
'total': calendarHeatmap.data.reduce(function (prev, current) { | ||
if ( moment(current.date).year() === date.year() ) { | ||
'total': calendarHeatmap.data.reduce(function(prev, current) { | ||
if (moment(current.date).year() === date.year()) { | ||
prev += current.total; | ||
@@ -187,7 +188,7 @@ } | ||
}, 0), | ||
'summary': function () { | ||
var summary = calendarHeatmap.data.reduce(function (summary, d) { | ||
if ( moment(d.date).year() === date.year() ) { | ||
for ( var i = 0; i < d.summary.length; i++ ) { | ||
if ( !summary[d.summary[i].name] ) { | ||
'summary': function() { | ||
var summary = calendarHeatmap.data.reduce(function(summary, d) { | ||
if (moment(d.date).year() === date.year()) { | ||
for (var i = 0; i < d.summary.length; i++) { | ||
if (!summary[d.summary[i].name]) { | ||
summary[d.summary[i].name] = { | ||
@@ -203,3 +204,3 @@ 'value': d.summary[i].value, | ||
}, {}); | ||
var unsorted_summary = Object.keys(summary).map(function (key) { | ||
var unsorted_summary = Object.keys(summary).map(function(key) { | ||
return { | ||
@@ -210,3 +211,3 @@ 'name': key, | ||
}); | ||
return unsorted_summary.sort(function (a, b) { | ||
return unsorted_summary.sort(function(a, b) { | ||
return b.value - a.value; | ||
@@ -219,3 +220,3 @@ }); | ||
// Calculate max value of all the years in the dataset | ||
var max_value = d3.max(year_data, function (d) { | ||
var max_value = d3.max(year_data, function(d) { | ||
return d.total; | ||
@@ -225,7 +226,8 @@ }); | ||
// Define year labels and axis | ||
var year_labels = d3.time.years(start, end).map(function (d) { | ||
var year_labels = d3.timeYears(start, end).map(function(d) { | ||
return moment(d); | ||
}); | ||
var yearScale = d3.scale.ordinal() | ||
.rangeRoundBands([0, calendarHeatmap.settings.width], 0.05) | ||
var yearScale = d3.scaleBand() | ||
.rangeRound([0, calendarHeatmap.settings.width]) | ||
.padding([0.05]) | ||
.domain(year_labels.map(function(d) { | ||
@@ -242,13 +244,13 @@ return d.year(); | ||
.attr('class', 'item item-block-year') | ||
.attr('width', function () { | ||
.attr('width', function() { | ||
return (calendarHeatmap.settings.width - calendarHeatmap.settings.label_padding) / year_labels.length - calendarHeatmap.settings.gutter * 5; | ||
}) | ||
.attr('height', function () { | ||
.attr('height', function() { | ||
return calendarHeatmap.settings.height - calendarHeatmap.settings.label_padding; | ||
}) | ||
.attr('transform', function (d) { | ||
.attr('transform', function(d) { | ||
return 'translate(' + yearScale(d.date.year()) + ',' + calendarHeatmap.settings.tooltip_padding * 2 + ')'; | ||
}) | ||
.attr('fill', function (d) { | ||
var color = d3.scale.linear() | ||
.attr('fill', function(d) { | ||
var color = d3.scaleLinear() | ||
.range(['#ffffff', calendarHeatmap.color || '#ff4500']) | ||
@@ -258,4 +260,4 @@ .domain([-0.15 * max_value, max_value]); | ||
}) | ||
.on('click', function (d) { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('click', function(d) { | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -280,3 +282,3 @@ // Set in_transition flag | ||
.on('mouseover', function(d) { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -289,8 +291,8 @@ // Construct tooltip | ||
var days = Math.floor(sec / 86400); | ||
if ( days > 0 ) { | ||
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 ) { | ||
if (hours > 0) { | ||
if (days > 0) { | ||
tooltip_html += '<div><span></span><span>' + (hours === 1 ? '1 hour' : hours + ' hours') + '</span></div>'; | ||
@@ -302,4 +304,4 @@ } else { | ||
var minutes = Math.floor((sec - (days * 86400) - (hours * 3600)) / 60); | ||
if ( minutes > 0 ) { | ||
if ( days > 0 || hours > 0 ) { | ||
if (minutes > 0) { | ||
if (days > 0 || hours > 0) { | ||
tooltip_html += '<div><span></span><span>' + (minutes === 1 ? '1 minute' : minutes + ' minutes') + '</span></div>'; | ||
@@ -313,4 +315,4 @@ } else { | ||
// Add summary to the tooltip | ||
if ( d.summary.length <= 5 ) { | ||
for ( var i = 0; i < d.summary.length; i++ ) { | ||
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>'; | ||
@@ -320,3 +322,3 @@ tooltip_html += '<span>' + calendarHeatmap.formatTime(d.summary[i].value) + '</span></div>'; | ||
} else { | ||
for ( var i = 0; i < 5; i++ ) { | ||
for (var i = 0; i < 5; i++) { | ||
tooltip_html += '<div><span><strong>' + d.summary[i].name + '</strong></span>'; | ||
@@ -328,4 +330,4 @@ tooltip_html += '<span>' + calendarHeatmap.formatTime(d.summary[i].value) + '</span></div>'; | ||
var other_projects_sum = 0; | ||
for ( var i = 5; i < d.summary.length; i++ ) { | ||
other_projects_sum =+ d.summary[i].value; | ||
for (var i = 5; i < d.summary.length; i++) { | ||
other_projects_sum = +d.summary[i].value; | ||
}; | ||
@@ -338,3 +340,3 @@ tooltip_html += '<div><span><strong>Other:</strong></span>'; | ||
var x = yearScale(d.date.year()) + calendarHeatmap.settings.tooltip_padding * 2; | ||
while ( calendarHeatmap.settings.width - x < (calendarHeatmap.settings.tooltip_width + calendarHeatmap.settings.tooltip_padding * 5) ) { | ||
while (calendarHeatmap.settings.width - x < (calendarHeatmap.settings.tooltip_width + calendarHeatmap.settings.tooltip_padding * 5)) { | ||
x -= 10; | ||
@@ -349,34 +351,34 @@ } | ||
.transition() | ||
.duration(calendarHeatmap.settings.transition_duration / 2) | ||
.ease('ease-in') | ||
.style('opacity', 1); | ||
.duration(calendarHeatmap.settings.transition_duration / 2) | ||
.ease(d3.easeLinear) | ||
.style('opacity', 1); | ||
}) | ||
.on('mouseout', function () { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseout', function() { | ||
if (calendarHeatmap.in_transition) { return; } | ||
calendarHeatmap.hideTooltip(); | ||
}) | ||
.transition() | ||
.delay(function (d, i) { | ||
return calendarHeatmap.settings.transition_duration * (i + 1) / 10; | ||
}) | ||
.duration(function () { | ||
return calendarHeatmap.settings.transition_duration; | ||
}) | ||
.ease('ease-in') | ||
.style('opacity', 1) | ||
.call(function (transition, callback) { | ||
if ( transition.empty() ) { | ||
callback(); | ||
} | ||
var n = 0; | ||
transition | ||
.each(function() { ++n; }) | ||
.each('end', function() { | ||
if ( !--n ) { | ||
callback.apply(this, arguments); | ||
} | ||
}); | ||
}, function() { | ||
calendarHeatmap.in_transition = false; | ||
.delay(function(d, i) { | ||
return calendarHeatmap.settings.transition_duration * (i + 1) / 10; | ||
}) | ||
.duration(function() { | ||
return calendarHeatmap.settings.transition_duration; | ||
}) | ||
.ease(d3.easeLinear) | ||
.style('opacity', 1) | ||
.call(function(transition, callback) { | ||
if (transition.empty()) { | ||
callback(); | ||
} | ||
var n = 0; | ||
transition | ||
.each(function() {++n; }) | ||
.on('end', function() { | ||
if (!--n) { | ||
callback.apply(this, arguments); | ||
} | ||
}); | ||
}, function() { | ||
calendarHeatmap.in_transition = false; | ||
}); | ||
@@ -390,14 +392,14 @@ // Add year labels | ||
.attr('class', 'label label-year') | ||
.attr('font-size', function () { | ||
.attr('font-size', function() { | ||
return Math.floor(calendarHeatmap.settings.label_padding / 3) + 'px'; | ||
}) | ||
.text(function (d) { | ||
.text(function(d) { | ||
return d.year(); | ||
}) | ||
.attr('x', function (d) { | ||
.attr('x', function(d) { | ||
return yearScale(d.year()); | ||
}) | ||
.attr('y', calendarHeatmap.settings.label_padding / 2) | ||
.on('mouseenter', function (year_label) { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseenter', function(year_label) { | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -407,9 +409,9 @@ calendarHeatmap.items.selectAll('.item-block-year') | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.style('opacity', function (d) { | ||
return ( moment(d.date).year() === year_label.year() ) ? 1 : 0.1; | ||
.ease(d3.easeLinear) | ||
.style('opacity', function(d) { | ||
return (moment(d.date).year() === year_label.year()) ? 1 : 0.1; | ||
}); | ||
}) | ||
.on('mouseout', function () { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseout', function() { | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -419,7 +421,7 @@ calendarHeatmap.items.selectAll('.item-block-year') | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.ease(d3.easeLinear) | ||
.style('opacity', 1); | ||
}) | ||
.on('click', function (d) { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('click', function(d) { | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -448,5 +450,5 @@ // Set in_transition flag | ||
*/ | ||
drawYearOverview: function () { | ||
drawYearOverview: function() { | ||
// Add current overview to the history | ||
if ( calendarHeatmap.history[calendarHeatmap.history.length-1] !== calendarHeatmap.overview ) { | ||
if (calendarHeatmap.history[calendarHeatmap.history.length - 1] !== calendarHeatmap.overview) { | ||
calendarHeatmap.history.push(calendarHeatmap.overview); | ||
@@ -460,3 +462,3 @@ } | ||
// Filter data down to the selected year | ||
var year_data = calendarHeatmap.data.filter(function (d) { | ||
var year_data = calendarHeatmap.data.filter(function(d) { | ||
return start_of_year <= moment(d.date) && moment(d.date) < end_of_year; | ||
@@ -466,11 +468,11 @@ }); | ||
// Calculate max value of the year data | ||
var max_value = d3.max(year_data, function (d) { | ||
var max_value = d3.max(year_data, function(d) { | ||
return d.total; | ||
}); | ||
var color = d3.scale.linear() | ||
var color = d3.scaleLinear() | ||
.range(['#ffffff', calendarHeatmap.color || '#ff4500']) | ||
.domain([-0.15 * max_value, max_value]); | ||
var calcItemX = function (d) { | ||
var calcItemX = function(d) { | ||
var date = moment(d.date); | ||
@@ -481,7 +483,7 @@ var dayIndex = Math.round((date - moment(start_of_year).startOf('week')) / 86400000); | ||
}; | ||
var calcItemY = function (d) { | ||
var calcItemY = function(d) { | ||
return calendarHeatmap.settings.label_padding + moment(d.date).weekday() * (calendarHeatmap.settings.item_size + calendarHeatmap.settings.gutter); | ||
}; | ||
var calcItemSize = function (d) { | ||
if ( max_value <= 0 ) { return calendarHeatmap.settings.item_size; } | ||
var calcItemSize = function(d) { | ||
if (max_value <= 0) { return calendarHeatmap.settings.item_size; } | ||
return calendarHeatmap.settings.item_size * 0.75 + (calendarHeatmap.settings.item_size * d.total / max_value) * 0.25; | ||
@@ -497,28 +499,28 @@ }; | ||
.style('opacity', 0) | ||
.attr('x', function (d) { | ||
.attr('x', function(d) { | ||
return calcItemX(d) + (calendarHeatmap.settings.item_size - calcItemSize(d)) / 2; | ||
}) | ||
.attr('y', function (d) { | ||
.attr('y', function(d) { | ||
return calcItemY(d) + (calendarHeatmap.settings.item_size - calcItemSize(d)) / 2; | ||
}) | ||
.attr('rx', function (d) { | ||
.attr('rx', function(d) { | ||
return calcItemSize(d); | ||
}) | ||
.attr('ry', function (d) { | ||
.attr('ry', function(d) { | ||
return calcItemSize(d); | ||
}) | ||
.attr('width', function (d) { | ||
.attr('width', function(d) { | ||
return calcItemSize(d); | ||
}) | ||
.attr('height', function (d) { | ||
.attr('height', function(d) { | ||
return calcItemSize(d); | ||
}) | ||
.attr('fill', function (d) { | ||
return ( d.total > 0 ) ? color(d.total) : 'transparent'; | ||
.attr('fill', function(d) { | ||
return (d.total > 0) ? color(d.total) : 'transparent'; | ||
}) | ||
.on('click', function (d) { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('click', function(d) { | ||
if (calendarHeatmap.in_transition) { return; } | ||
// Don't transition if there is no data to show | ||
if ( d.total === 0 ) { return; } | ||
if (d.total === 0) { return; } | ||
@@ -540,4 +542,4 @@ calendarHeatmap.in_transition = true; | ||
}) | ||
.on('mouseover', function (d) { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseover', function(d) { | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -549,7 +551,7 @@ // Pulsating animation | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.attr('x', function (d) { | ||
.ease(d3.easeLinear) | ||
.attr('x', function(d) { | ||
return calcItemX(d) - (calendarHeatmap.settings.item_size * 1.1 - calendarHeatmap.settings.item_size) / 2; | ||
}) | ||
.attr('y', function (d) { | ||
.attr('y', function(d) { | ||
return calcItemY(d) - (calendarHeatmap.settings.item_size * 1.1 - calendarHeatmap.settings.item_size) / 2; | ||
@@ -561,16 +563,16 @@ }) | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.attr('x', function (d) { | ||
.ease(d3.easeLinear) | ||
.attr('x', function(d) { | ||
return calcItemX(d) + (calendarHeatmap.settings.item_size - calcItemSize(d)) / 2; | ||
}) | ||
.attr('y', function (d) { | ||
.attr('y', function(d) { | ||
return calcItemY(d) + (calendarHeatmap.settings.item_size - calcItemSize(d)) / 2; | ||
}) | ||
.attr('width', function (d) { | ||
.attr('width', function(d) { | ||
return calcItemSize(d); | ||
}) | ||
.attr('height', function (d) { | ||
.attr('height', function(d) { | ||
return calcItemSize(d); | ||
}) | ||
.each('end', repeat); | ||
.on('end', repeat); | ||
})(); | ||
@@ -584,3 +586,3 @@ | ||
// Add summary to the tooltip | ||
for ( var i = 0; i < d.summary.length; i++ ) { | ||
for (var i = 0; i < d.summary.length; i++) { | ||
tooltip_html += '<div><span><strong>' + d.summary[i].name + '</strong></span>'; | ||
@@ -592,3 +594,3 @@ tooltip_html += '<span>' + calendarHeatmap.formatTime(d.summary[i].value) + '</span></div>'; | ||
var x = calcItemX(d) + calendarHeatmap.settings.item_size; | ||
if ( calendarHeatmap.settings.width - x < (calendarHeatmap.settings.tooltip_width + calendarHeatmap.settings.tooltip_padding * 3) ) { | ||
if (calendarHeatmap.settings.width - x < (calendarHeatmap.settings.tooltip_width + calendarHeatmap.settings.tooltip_padding * 3)) { | ||
x -= calendarHeatmap.settings.tooltip_width + calendarHeatmap.settings.tooltip_padding * 2; | ||
@@ -603,8 +605,8 @@ } | ||
.transition() | ||
.duration(calendarHeatmap.settings.transition_duration / 2) | ||
.ease('ease-in') | ||
.style('opacity', 1); | ||
.duration(calendarHeatmap.settings.transition_duration / 2) | ||
.ease(d3.easeLinear) | ||
.style('opacity', 1); | ||
}) | ||
.on('mouseout', function () { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseout', function() { | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -614,13 +616,13 @@ // Set circle radius back to what it's supposed to be | ||
.duration(calendarHeatmap.settings.transition_duration / 2) | ||
.ease('ease-in') | ||
.attr('x', function (d) { | ||
.ease(d3.easeLinear) | ||
.attr('x', function(d) { | ||
return calcItemX(d) + (calendarHeatmap.settings.item_size - calcItemSize(d)) / 2; | ||
}) | ||
.attr('y', function (d) { | ||
.attr('y', function(d) { | ||
return calcItemY(d) + (calendarHeatmap.settings.item_size - calcItemSize(d)) / 2; | ||
}) | ||
.attr('width', function (d) { | ||
.attr('width', function(d) { | ||
return calcItemSize(d); | ||
}) | ||
.attr('height', function (d) { | ||
.attr('height', function(d) { | ||
return calcItemSize(d); | ||
@@ -633,29 +635,29 @@ }); | ||
.transition() | ||
.delay( function () { | ||
return (Math.cos(Math.PI * Math.random()) + 1) * calendarHeatmap.settings.transition_duration; | ||
}) | ||
.duration(function () { | ||
return calendarHeatmap.settings.transition_duration; | ||
}) | ||
.ease('ease-in') | ||
.style('opacity', 1) | ||
.call(function (transition, callback) { | ||
if ( transition.empty() ) { | ||
callback(); | ||
} | ||
var n = 0; | ||
transition | ||
.each(function() { ++n; }) | ||
.each('end', function() { | ||
if ( !--n ) { | ||
callback.apply(this, arguments); | ||
} | ||
}); | ||
}, function() { | ||
calendarHeatmap.in_transition = false; | ||
.delay(function() { | ||
return (Math.cos(Math.PI * Math.random()) + 1) * calendarHeatmap.settings.transition_duration; | ||
}) | ||
.duration(function() { | ||
return calendarHeatmap.settings.transition_duration; | ||
}) | ||
.ease(d3.easeLinear) | ||
.style('opacity', 1) | ||
.call(function(transition, callback) { | ||
if (transition.empty()) { | ||
callback(); | ||
} | ||
var n = 0; | ||
transition | ||
.each(function() {++n; }) | ||
.on('end', function() { | ||
if (!--n) { | ||
callback.apply(this, arguments); | ||
} | ||
}); | ||
}, function() { | ||
calendarHeatmap.in_transition = false; | ||
}); | ||
// Add month labels | ||
var month_labels = d3.time.months(start_of_year, end_of_year); | ||
var monthScale = d3.scale.linear() | ||
var month_labels = d3.timeMonths(start_of_year, end_of_year); | ||
var monthScale = d3.scaleLinear() | ||
.range([0, calendarHeatmap.settings.width]) | ||
@@ -669,14 +671,14 @@ .domain([0, month_labels.length]); | ||
.attr('class', 'label label-month') | ||
.attr('font-size', function () { | ||
.attr('font-size', function() { | ||
return Math.floor(calendarHeatmap.settings.label_padding / 3) + 'px'; | ||
}) | ||
.text(function (d) { | ||
return d.toLocaleDateString('en-us', {month: 'short'}); | ||
.text(function(d) { | ||
return d.toLocaleDateString('en-us', { month: 'short' }); | ||
}) | ||
.attr('x', function (d, i) { | ||
return monthScale(i) + (monthScale(i) - monthScale(i-1)) / 2; | ||
.attr('x', function(d, i) { | ||
return monthScale(i) + (monthScale(i) - monthScale(i - 1)) / 2; | ||
}) | ||
.attr('y', calendarHeatmap.settings.label_padding / 2) | ||
.on('mouseenter', function (d) { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseenter', function(d) { | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -687,9 +689,9 @@ var selected_month = moment(d); | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.style('opacity', function (d) { | ||
.ease(d3.easeLinear) | ||
.style('opacity', function(d) { | ||
return moment(d.date).isSame(selected_month, 'month') ? 1 : 0.1; | ||
}); | ||
}) | ||
.on('mouseout', function () { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseout', function() { | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -699,10 +701,10 @@ calendarHeatmap.items.selectAll('.item-circle') | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.ease(d3.easeLinear) | ||
.style('opacity', 1); | ||
}) | ||
.on('click', function (d) { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('click', function(d) { | ||
if (calendarHeatmap.in_transition) { return; } | ||
// Check month data | ||
var month_data = calendarHeatmap.data.filter(function (e) { | ||
var month_data = calendarHeatmap.data.filter(function(e) { | ||
return moment(d).startOf('month') <= moment(e.date) && moment(e.date) < moment(d).endOf('month'); | ||
@@ -712,6 +714,6 @@ }); | ||
// Don't transition if there is no data to show | ||
if ( !month_data.length ) { return; } | ||
if (!month_data.length) { return; } | ||
// Set selected month to the one clicked on | ||
calendarHeatmap.selected = {date: d}; | ||
calendarHeatmap.selected = { date: d }; | ||
@@ -732,6 +734,6 @@ calendarHeatmap.in_transition = true; | ||
// Add day labels | ||
var day_labels = d3.time.days(moment().startOf('week'), moment().endOf('week')); | ||
var dayScale = d3.scale.ordinal() | ||
.rangeRoundBands([calendarHeatmap.settings.label_padding, calendarHeatmap.settings.height]) | ||
.domain(day_labels.map(function (d) { | ||
var day_labels = d3.timeDays(moment().startOf('week'), moment().endOf('week')); | ||
var dayScale = d3.scaleBand() | ||
.rangeRound([calendarHeatmap.settings.label_padding, calendarHeatmap.settings.height]) | ||
.domain(day_labels.map(function(d) { | ||
return moment(d).weekday(); | ||
@@ -746,14 +748,14 @@ })); | ||
.attr('x', calendarHeatmap.settings.label_padding / 3) | ||
.attr('y', function (d, i) { | ||
return dayScale(i) + dayScale.rangeBand() / 1.75; | ||
.attr('y', function(d, i) { | ||
return dayScale(i) + dayScale.bandwidth() / 1.75; | ||
}) | ||
.style('text-anchor', 'left') | ||
.attr('font-size', function () { | ||
.attr('font-size', function() { | ||
return Math.floor(calendarHeatmap.settings.label_padding / 3) + 'px'; | ||
}) | ||
.text(function (d) { | ||
.text(function(d) { | ||
return moment(d).format('dddd')[0]; | ||
}) | ||
.on('mouseenter', function (d) { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseenter', function(d) { | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -764,9 +766,9 @@ var selected_day = moment(d); | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.style('opacity', function (d) { | ||
.ease(d3.easeLinear) | ||
.style('opacity', function(d) { | ||
return (moment(d.date).day() === selected_day.day()) ? 1 : 0.1; | ||
}); | ||
}) | ||
.on('mouseout', function () { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseout', function() { | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -776,3 +778,3 @@ calendarHeatmap.items.selectAll('.item-circle') | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.ease(d3.easeLinear) | ||
.style('opacity', 1); | ||
@@ -789,5 +791,5 @@ }); | ||
*/ | ||
drawMonthOverview: function () { | ||
drawMonthOverview: function() { | ||
// Add current overview to the history | ||
if ( calendarHeatmap.history[calendarHeatmap.history.length-1] !== calendarHeatmap.overview ) { | ||
if (calendarHeatmap.history[calendarHeatmap.history.length - 1] !== calendarHeatmap.overview) { | ||
calendarHeatmap.history.push(calendarHeatmap.overview); | ||
@@ -801,7 +803,7 @@ } | ||
// Filter data down to the selected month | ||
var month_data = calendarHeatmap.data.filter(function (d) { | ||
var month_data = calendarHeatmap.data.filter(function(d) { | ||
return start_of_month <= moment(d.date) && moment(d.date) < end_of_month; | ||
}); | ||
var max_value = d3.max(month_data, function (d) { | ||
return d3.max(d.summary, function (d) { | ||
var max_value = d3.max(month_data, function(d) { | ||
return d3.max(d.summary, function(d) { | ||
return d.value; | ||
@@ -812,6 +814,6 @@ }); | ||
// Define day labels and axis | ||
var day_labels = d3.time.days(moment().startOf('week'), moment().endOf('week')); | ||
var dayScale = d3.scale.ordinal() | ||
.rangeRoundBands([calendarHeatmap.settings.label_padding, calendarHeatmap.settings.height]) | ||
.domain(day_labels.map(function (d) { | ||
var day_labels = d3.timeDays(moment().startOf('week'), moment().endOf('week')); | ||
var dayScale = d3.scaleBand() | ||
.rangeRound([calendarHeatmap.settings.label_padding, calendarHeatmap.settings.height]) | ||
.domain(day_labels.map(function(d) { | ||
return moment(d).weekday(); | ||
@@ -822,7 +824,8 @@ })); | ||
var week_labels = [start_of_month.clone()]; | ||
while ( start_of_month.week() !== end_of_month.week() ) { | ||
while (start_of_month.week() !== end_of_month.week()) { | ||
week_labels.push(start_of_month.add(1, 'week').clone()); | ||
} | ||
var weekScale = d3.scale.ordinal() | ||
.rangeRoundBands([calendarHeatmap.settings.label_padding, calendarHeatmap.settings.width], 0.05) | ||
var weekScale = d3.scaleBand() | ||
.rangeRound([calendarHeatmap.settings.label_padding, calendarHeatmap.settings.width]) | ||
.padding([0.05]) | ||
.domain(week_labels.map(function(weekday) { | ||
@@ -839,23 +842,23 @@ return weekday.week(); | ||
.attr('class', 'item item-block-month') | ||
.attr('width', function () { | ||
.attr('width', function() { | ||
return (calendarHeatmap.settings.width - calendarHeatmap.settings.label_padding) / week_labels.length - calendarHeatmap.settings.gutter * 5; | ||
}) | ||
.attr('height', function () { | ||
return Math.min(dayScale.rangeBand(), calendarHeatmap.settings.max_block_height); | ||
.attr('height', function() { | ||
return Math.min(dayScale.bandwidth(), calendarHeatmap.settings.max_block_height); | ||
}) | ||
.attr('transform', function (d) { | ||
return 'translate(' + weekScale(moment(d.date).week()) + ',' + ((dayScale(moment(d.date).weekday()) + dayScale.rangeBand() / 1.75) - 15)+ ')'; | ||
.attr('transform', function(d) { | ||
return 'translate(' + weekScale(moment(d.date).week()) + ',' + ((dayScale(moment(d.date).weekday()) + dayScale.bandwidth() / 1.75) - 15) + ')'; | ||
}) | ||
.attr('total', function (d) { | ||
.attr('total', function(d) { | ||
return d.total; | ||
}) | ||
.attr('date', function (d) { | ||
.attr('date', function(d) { | ||
return d.date; | ||
}) | ||
.attr('offset', 0) | ||
.on('click', function (d) { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('click', function(d) { | ||
if (calendarHeatmap.in_transition) { return; } | ||
// Don't transition if there is no data to show | ||
if ( d.total === 0 ) { return; } | ||
if (d.total === 0) { return; } | ||
@@ -879,7 +882,7 @@ calendarHeatmap.in_transition = true; | ||
var item_width = (calendarHeatmap.settings.width - calendarHeatmap.settings.label_padding) / week_labels.length - calendarHeatmap.settings.gutter * 5; | ||
var itemScale = d3.scale.linear() | ||
var itemScale = d3.scaleLinear() | ||
.rangeRound([0, item_width]); | ||
item_block.selectAll('.item-block-rect') | ||
.data(function (d) { | ||
.data(function(d) { | ||
return d.summary; | ||
@@ -890,3 +893,3 @@ }) | ||
.attr('class', 'item item-block-rect') | ||
.attr('x', function (d) { | ||
.attr('x', function(d) { | ||
var total = parseInt(d3.select(this.parentNode).attr('total')); | ||
@@ -898,3 +901,3 @@ var offset = parseInt(d3.select(this.parentNode).attr('offset')); | ||
}) | ||
.attr('width', function (d) { | ||
.attr('width', function(d) { | ||
var total = parseInt(d3.select(this.parentNode).attr('total')); | ||
@@ -904,7 +907,7 @@ itemScale.domain([0, total]); | ||
}) | ||
.attr('height', function () { | ||
return Math.min(dayScale.rangeBand(), calendarHeatmap.settings.max_block_height); | ||
.attr('height', function() { | ||
return Math.min(dayScale.bandwidth(), calendarHeatmap.settings.max_block_height); | ||
}) | ||
.attr('fill', function (d) { | ||
var color = d3.scale.linear() | ||
.attr('fill', function(d) { | ||
var color = d3.scaleLinear() | ||
.range(['#ffffff', calendarHeatmap.color || '#ff4500']) | ||
@@ -916,3 +919,3 @@ .domain([-0.15 * max_value, max_value]); | ||
.on('mouseover', function(d) { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -930,3 +933,3 @@ // Get date from the parent node | ||
var x = weekScale(moment(date).week()) + calendarHeatmap.settings.tooltip_padding; | ||
while ( calendarHeatmap.settings.width - x < (calendarHeatmap.settings.tooltip_width + calendarHeatmap.settings.tooltip_padding * 3) ) { | ||
while (calendarHeatmap.settings.width - x < (calendarHeatmap.settings.tooltip_width + calendarHeatmap.settings.tooltip_padding * 3)) { | ||
x -= 10; | ||
@@ -941,34 +944,34 @@ } | ||
.transition() | ||
.duration(calendarHeatmap.settings.transition_duration / 2) | ||
.ease('ease-in') | ||
.style('opacity', 1); | ||
.duration(calendarHeatmap.settings.transition_duration / 2) | ||
.ease(d3.easeLinear) | ||
.style('opacity', 1); | ||
}) | ||
.on('mouseout', function () { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseout', function() { | ||
if (calendarHeatmap.in_transition) { return; } | ||
calendarHeatmap.hideTooltip(); | ||
}) | ||
.transition() | ||
.delay(function () { | ||
return (Math.cos(Math.PI * Math.random()) + 1) * calendarHeatmap.settings.transition_duration; | ||
}) | ||
.duration(function () { | ||
return calendarHeatmap.settings.transition_duration; | ||
}) | ||
.ease('ease-in') | ||
.style('opacity', 1) | ||
.call(function (transition, callback) { | ||
if ( transition.empty() ) { | ||
callback(); | ||
} | ||
var n = 0; | ||
transition | ||
.each(function() { ++n; }) | ||
.each('end', function() { | ||
if ( !--n ) { | ||
callback.apply(this, arguments); | ||
} | ||
}); | ||
}, function() { | ||
calendarHeatmap.in_transition = false; | ||
.delay(function() { | ||
return (Math.cos(Math.PI * Math.random()) + 1) * calendarHeatmap.settings.transition_duration; | ||
}) | ||
.duration(function() { | ||
return calendarHeatmap.settings.transition_duration; | ||
}) | ||
.ease(d3.easeLinear) | ||
.style('opacity', 1) | ||
.call(function(transition, callback) { | ||
if (transition.empty()) { | ||
callback(); | ||
} | ||
var n = 0; | ||
transition | ||
.each(function() {++n; }) | ||
.on('end', function() { | ||
if (!--n) { | ||
callback.apply(this, arguments); | ||
} | ||
}); | ||
}, function() { | ||
calendarHeatmap.in_transition = false; | ||
}); | ||
@@ -982,14 +985,14 @@ // Add week labels | ||
.attr('class', 'label label-week') | ||
.attr('font-size', function () { | ||
.attr('font-size', function() { | ||
return Math.floor(calendarHeatmap.settings.label_padding / 3) + 'px'; | ||
}) | ||
.text(function (d) { | ||
.text(function(d) { | ||
return 'Week ' + d.week(); | ||
}) | ||
.attr('x', function (d) { | ||
.attr('x', function(d) { | ||
return weekScale(d.week()); | ||
}) | ||
.attr('y', calendarHeatmap.settings.label_padding / 2) | ||
.on('mouseenter', function (weekday) { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseenter', function(weekday) { | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -999,9 +1002,9 @@ calendarHeatmap.items.selectAll('.item-block-month') | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.style('opacity', function (d) { | ||
return ( moment(d.date).week() === weekday.week() ) ? 1 : 0.1; | ||
.ease(d3.easeLinear) | ||
.style('opacity', function(d) { | ||
return (moment(d.date).week() === weekday.week()) ? 1 : 0.1; | ||
}); | ||
}) | ||
.on('mouseout', function () { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseout', function() { | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -1011,10 +1014,10 @@ calendarHeatmap.items.selectAll('.item-block-month') | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.ease(d3.easeLinear) | ||
.style('opacity', 1); | ||
}) | ||
.on('click', function (d) { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('click', function(d) { | ||
if (calendarHeatmap.in_transition) { return; } | ||
// Check week data | ||
var week_data = calendarHeatmap.data.filter(function (e) { | ||
var week_data = calendarHeatmap.data.filter(function(e) { | ||
return d.startOf('week') <= moment(e.date) && moment(e.date) < d.endOf('week'); | ||
@@ -1024,3 +1027,3 @@ }); | ||
// Don't transition if there is no data to show | ||
if ( !week_data.length ) { return; } | ||
if (!week_data.length) { return; } | ||
@@ -1051,14 +1054,14 @@ calendarHeatmap.in_transition = true; | ||
.attr('x', calendarHeatmap.settings.label_padding / 3) | ||
.attr('y', function (d, i) { | ||
return dayScale(i) + dayScale.rangeBand() / 1.75; | ||
.attr('y', function(d, i) { | ||
return dayScale(i) + dayScale.bandwidth() / 1.75; | ||
}) | ||
.style('text-anchor', 'left') | ||
.attr('font-size', function () { | ||
.attr('font-size', function() { | ||
return Math.floor(calendarHeatmap.settings.label_padding / 3) + 'px'; | ||
}) | ||
.text(function (d) { | ||
.text(function(d) { | ||
return moment(d).format('dddd')[0]; | ||
}) | ||
.on('mouseenter', function (d) { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseenter', function(d) { | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -1069,9 +1072,9 @@ var selected_day = moment(d); | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.style('opacity', function (d) { | ||
.ease(d3.easeLinear) | ||
.style('opacity', function(d) { | ||
return (moment(d.date).day() === selected_day.day()) ? 1 : 0.1; | ||
}); | ||
}) | ||
.on('mouseout', function () { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseout', function() { | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -1081,3 +1084,3 @@ calendarHeatmap.items.selectAll('.item-block-month') | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.ease(d3.easeLinear) | ||
.style('opacity', 1); | ||
@@ -1094,5 +1097,5 @@ }); | ||
*/ | ||
drawWeekOverview: function () { | ||
drawWeekOverview: function() { | ||
// Add current overview to the history | ||
if ( calendarHeatmap.history[calendarHeatmap.history.length-1] !== calendarHeatmap.overview ) { | ||
if (calendarHeatmap.history[calendarHeatmap.history.length - 1] !== calendarHeatmap.overview) { | ||
calendarHeatmap.history.push(calendarHeatmap.overview); | ||
@@ -1106,7 +1109,7 @@ } | ||
// Filter data down to the selected week | ||
var week_data = calendarHeatmap.data.filter(function (d) { | ||
var week_data = calendarHeatmap.data.filter(function(d) { | ||
return start_of_week <= moment(d.date) && moment(d.date) < end_of_week; | ||
}); | ||
var max_value = d3.max(week_data, function (d) { | ||
return d3.max(d.summary, function (d) { | ||
var max_value = d3.max(week_data, function(d) { | ||
return d3.max(d.summary, function(d) { | ||
return d.value; | ||
@@ -1117,6 +1120,6 @@ }); | ||
// Define day labels and axis | ||
var day_labels = d3.time.days(moment().startOf('week'), moment().endOf('week')); | ||
var dayScale = d3.scale.ordinal() | ||
.rangeRoundBands([calendarHeatmap.settings.label_padding, calendarHeatmap.settings.height]) | ||
.domain(day_labels.map(function (d) { | ||
var day_labels = d3.timeDays(moment().startOf('week'), moment().endOf('week')); | ||
var dayScale = d3.scaleBand() | ||
.rangeRound([calendarHeatmap.settings.label_padding, calendarHeatmap.settings.height]) | ||
.domain(day_labels.map(function(d) { | ||
return moment(d).weekday(); | ||
@@ -1127,5 +1130,6 @@ })); | ||
var week_labels = [start_of_week]; | ||
var weekScale = d3.scale.ordinal() | ||
.rangeRoundBands([calendarHeatmap.settings.label_padding, calendarHeatmap.settings.width], 0.01) | ||
.domain(week_labels.map(function (weekday) { | ||
var weekScale = d3.scaleBand() | ||
.rangeRound([calendarHeatmap.settings.label_padding, calendarHeatmap.settings.width]) | ||
.padding([0.01]) | ||
.domain(week_labels.map(function(weekday) { | ||
return weekday.week(); | ||
@@ -1141,23 +1145,23 @@ })); | ||
.attr('class', 'item item-block-week') | ||
.attr('width', function () { | ||
.attr('width', function() { | ||
return (calendarHeatmap.settings.width - calendarHeatmap.settings.label_padding) / week_labels.length - calendarHeatmap.settings.gutter * 5; | ||
}) | ||
.attr('height', function () { | ||
return Math.min(dayScale.rangeBand(), calendarHeatmap.settings.max_block_height); | ||
.attr('height', function() { | ||
return Math.min(dayScale.bandwidth(), calendarHeatmap.settings.max_block_height); | ||
}) | ||
.attr('transform', function (d) { | ||
return 'translate(' + weekScale(moment(d.date).week()) + ',' + ((dayScale(moment(d.date).weekday()) + dayScale.rangeBand() / 1.75) - 15)+ ')'; | ||
.attr('transform', function(d) { | ||
return 'translate(' + weekScale(moment(d.date).week()) + ',' + ((dayScale(moment(d.date).weekday()) + dayScale.bandwidth() / 1.75) - 15) + ')'; | ||
}) | ||
.attr('total', function (d) { | ||
.attr('total', function(d) { | ||
return d.total; | ||
}) | ||
.attr('date', function (d) { | ||
.attr('date', function(d) { | ||
return d.date; | ||
}) | ||
.attr('offset', 0) | ||
.on('click', function (d) { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('click', function(d) { | ||
if (calendarHeatmap.in_transition) { return; } | ||
// Don't transition if there is no data to show | ||
if ( d.total === 0 ) { return; } | ||
if (d.total === 0) { return; } | ||
@@ -1181,7 +1185,7 @@ calendarHeatmap.in_transition = true; | ||
var item_width = (calendarHeatmap.settings.width - calendarHeatmap.settings.label_padding) / week_labels.length - calendarHeatmap.settings.gutter * 5; | ||
var itemScale = d3.scale.linear() | ||
var itemScale = d3.scaleLinear() | ||
.rangeRound([0, item_width]); | ||
item_block.selectAll('.item-block-rect') | ||
.data(function (d) { | ||
.data(function(d) { | ||
return d.summary; | ||
@@ -1192,3 +1196,3 @@ }) | ||
.attr('class', 'item item-block-rect') | ||
.attr('x', function (d) { | ||
.attr('x', function(d) { | ||
var total = parseInt(d3.select(this.parentNode).attr('total')); | ||
@@ -1200,3 +1204,3 @@ var offset = parseInt(d3.select(this.parentNode).attr('offset')); | ||
}) | ||
.attr('width', function (d) { | ||
.attr('width', function(d) { | ||
var total = parseInt(d3.select(this.parentNode).attr('total')); | ||
@@ -1206,7 +1210,7 @@ itemScale.domain([0, total]); | ||
}) | ||
.attr('height', function () { | ||
return Math.min(dayScale.rangeBand(), calendarHeatmap.settings.max_block_height); | ||
.attr('height', function() { | ||
return Math.min(dayScale.bandwidth(), calendarHeatmap.settings.max_block_height); | ||
}) | ||
.attr('fill', function (d) { | ||
var color = d3.scale.linear() | ||
.attr('fill', function(d) { | ||
var color = d3.scaleLinear() | ||
.range(['#ffffff', calendarHeatmap.color || '#ff4500']) | ||
@@ -1218,3 +1222,3 @@ .domain([-0.15 * max_value, max_value]); | ||
.on('mouseover', function(d) { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -1234,3 +1238,3 @@ // Get date from the parent node | ||
var x = parseInt(d3.select(this).attr('x')) + itemScale(d.value) / 4 + calendarHeatmap.settings.tooltip_width / 4; | ||
while ( calendarHeatmap.settings.width - x < (calendarHeatmap.settings.tooltip_width + calendarHeatmap.settings.tooltip_padding * 3) ) { | ||
while (calendarHeatmap.settings.width - x < (calendarHeatmap.settings.tooltip_width + calendarHeatmap.settings.tooltip_padding * 3)) { | ||
x -= 10; | ||
@@ -1245,34 +1249,34 @@ } | ||
.transition() | ||
.duration(calendarHeatmap.settings.transition_duration / 2) | ||
.ease('ease-in') | ||
.style('opacity', 1); | ||
.duration(calendarHeatmap.settings.transition_duration / 2) | ||
.ease(d3.easeLinear) | ||
.style('opacity', 1); | ||
}) | ||
.on('mouseout', function () { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseout', function() { | ||
if (calendarHeatmap.in_transition) { return; } | ||
calendarHeatmap.hideTooltip(); | ||
}) | ||
.transition() | ||
.delay(function () { | ||
return (Math.cos(Math.PI * Math.random()) + 1) * calendarHeatmap.settings.transition_duration; | ||
}) | ||
.duration(function () { | ||
return calendarHeatmap.settings.transition_duration; | ||
}) | ||
.ease('ease-in') | ||
.style('opacity', 1) | ||
.call(function (transition, callback) { | ||
if ( transition.empty() ) { | ||
callback(); | ||
} | ||
var n = 0; | ||
transition | ||
.each(function() { ++n; }) | ||
.each('end', function() { | ||
if ( !--n ) { | ||
callback.apply(this, arguments); | ||
} | ||
}); | ||
}, function() { | ||
calendarHeatmap.in_transition = false; | ||
.delay(function() { | ||
return (Math.cos(Math.PI * Math.random()) + 1) * calendarHeatmap.settings.transition_duration; | ||
}) | ||
.duration(function() { | ||
return calendarHeatmap.settings.transition_duration; | ||
}) | ||
.ease(d3.easeLinear) | ||
.style('opacity', 1) | ||
.call(function(transition, callback) { | ||
if (transition.empty()) { | ||
callback(); | ||
} | ||
var n = 0; | ||
transition | ||
.each(function() {++n; }) | ||
.on('end', function() { | ||
if (!--n) { | ||
callback.apply(this, arguments); | ||
} | ||
}); | ||
}, function() { | ||
calendarHeatmap.in_transition = false; | ||
}); | ||
@@ -1286,14 +1290,14 @@ // Add week labels | ||
.attr('class', 'label label-week') | ||
.attr('font-size', function () { | ||
.attr('font-size', function() { | ||
return Math.floor(calendarHeatmap.settings.label_padding / 3) + 'px'; | ||
}) | ||
.text(function (d) { | ||
.text(function(d) { | ||
return 'Week ' + d.week(); | ||
}) | ||
.attr('x', function (d) { | ||
.attr('x', function(d) { | ||
return weekScale(d.week()); | ||
}) | ||
.attr('y', calendarHeatmap.settings.label_padding / 2) | ||
.on('mouseenter', function (weekday) { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseenter', function(weekday) { | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -1303,9 +1307,9 @@ calendarHeatmap.items.selectAll('.item-block-week') | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.style('opacity', function (d) { | ||
return ( moment(d.date).week() === weekday.week() ) ? 1 : 0.1; | ||
.ease(d3.easeLinear) | ||
.style('opacity', function(d) { | ||
return (moment(d.date).week() === weekday.week()) ? 1 : 0.1; | ||
}); | ||
}) | ||
.on('mouseout', function () { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseout', function() { | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -1315,3 +1319,3 @@ calendarHeatmap.items.selectAll('.item-block-week') | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.ease(d3.easeLinear) | ||
.style('opacity', 1); | ||
@@ -1328,14 +1332,14 @@ }); | ||
.attr('x', calendarHeatmap.settings.label_padding / 3) | ||
.attr('y', function (d, i) { | ||
return dayScale(i) + dayScale.rangeBand() / 1.75; | ||
.attr('y', function(d, i) { | ||
return dayScale(i) + dayScale.bandwidth() / 1.75; | ||
}) | ||
.style('text-anchor', 'left') | ||
.attr('font-size', function () { | ||
.attr('font-size', function() { | ||
return Math.floor(calendarHeatmap.settings.label_padding / 3) + 'px'; | ||
}) | ||
.text(function (d) { | ||
.text(function(d) { | ||
return moment(d).format('dddd')[0]; | ||
}) | ||
.on('mouseenter', function (d) { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseenter', function(d) { | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -1346,9 +1350,9 @@ var selected_day = moment(d); | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.style('opacity', function (d) { | ||
.ease(d3.easeLinear) | ||
.style('opacity', function(d) { | ||
return (moment(d.date).day() === selected_day.day()) ? 1 : 0.1; | ||
}); | ||
}) | ||
.on('mouseout', function () { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseout', function() { | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -1358,3 +1362,3 @@ calendarHeatmap.items.selectAll('.item-block-week') | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.ease(d3.easeLinear) | ||
.style('opacity', 1); | ||
@@ -1371,5 +1375,5 @@ }); | ||
*/ | ||
drawDayOverview: function () { | ||
drawDayOverview: function() { | ||
// Add current overview to the history | ||
if ( calendarHeatmap.history[calendarHeatmap.history.length-1] !== calendarHeatmap.overview ) { | ||
if (calendarHeatmap.history[calendarHeatmap.history.length - 1] !== calendarHeatmap.overview) { | ||
calendarHeatmap.history.push(calendarHeatmap.overview); | ||
@@ -1379,15 +1383,15 @@ } | ||
// Initialize selected date to today if it was not set | ||
if ( !Object.keys(calendarHeatmap.selected).length ) { | ||
calendarHeatmap.selected = calendarHeatmap.data[calendarHeatmap.data.length - 1]; | ||
if (!Object.keys(calendarHeatmap.selected).length) { | ||
calendarHeatmap.selected = calendarHeatmap.data[calendarHeatmap.data.length - 1]; | ||
} | ||
var project_labels = calendarHeatmap.selected.summary.map(function (project) { | ||
var project_labels = calendarHeatmap.selected.summary.map(function(project) { | ||
return project.name; | ||
}); | ||
var projectScale = d3.scale.ordinal() | ||
.rangeRoundBands([calendarHeatmap.settings.label_padding, calendarHeatmap.settings.height]) | ||
var projectScale = d3.scaleBand() | ||
.rangeRound([calendarHeatmap.settings.label_padding, calendarHeatmap.settings.height]) | ||
.domain(project_labels); | ||
var itemScale = d3.time.scale() | ||
.range([calendarHeatmap.settings.label_padding*2, calendarHeatmap.settings.width]) | ||
var itemScale = d3.scaleTime() | ||
.range([calendarHeatmap.settings.label_padding * 2, calendarHeatmap.settings.width]) | ||
.domain([moment(calendarHeatmap.selected.date).startOf('day'), moment(calendarHeatmap.selected.date).endOf('day')]); | ||
@@ -1400,16 +1404,16 @@ calendarHeatmap.items.selectAll('.item-block').remove(); | ||
.attr('class', 'item item-block') | ||
.attr('x', function (d) { | ||
.attr('x', function(d) { | ||
return itemScale(moment(d.date)); | ||
}) | ||
.attr('y', function (d) { | ||
return (projectScale(d.name) + projectScale.rangeBand() / 2) - 15; | ||
.attr('y', function(d) { | ||
return (projectScale(d.name) + projectScale.bandwidth() / 2) - 15; | ||
}) | ||
.attr('width', function (d) { | ||
var end = itemScale(d3.time.second.offset(moment(d.date), d.value)); | ||
.attr('width', function(d) { | ||
var end = itemScale(d3.timeSecond.offset(moment(d.date), d.value)); | ||
return Math.max((end - itemScale(moment(d.date))), 1); | ||
}) | ||
.attr('height', function () { | ||
return Math.min(projectScale.rangeBand(), calendarHeatmap.settings.max_block_height); | ||
.attr('height', function() { | ||
return Math.min(projectScale.bandwidth(), calendarHeatmap.settings.max_block_height); | ||
}) | ||
.attr('fill', function () { | ||
.attr('fill', function() { | ||
return calendarHeatmap.color || '#ff4500'; | ||
@@ -1419,3 +1423,3 @@ }) | ||
.on('mouseover', function(d) { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -1430,6 +1434,6 @@ // Construct tooltip | ||
var x = d.value * 100 / (60 * 60 * 24) + itemScale(moment(d.date)); | ||
while ( calendarHeatmap.settings.width - x < (calendarHeatmap.settings.tooltip_width + calendarHeatmap.settings.tooltip_padding * 3) ) { | ||
while (calendarHeatmap.settings.width - x < (calendarHeatmap.settings.tooltip_width + calendarHeatmap.settings.tooltip_padding * 3)) { | ||
x -= 10; | ||
} | ||
var y = projectScale(d.name) + projectScale.rangeBand() / 2 + calendarHeatmap.settings.tooltip_padding / 2; | ||
var y = projectScale(d.name) + projectScale.bandwidth() / 2 + calendarHeatmap.settings.tooltip_padding / 2; | ||
@@ -1441,12 +1445,12 @@ // Show tooltip | ||
.transition() | ||
.duration(calendarHeatmap.settings.transition_duration / 2) | ||
.ease('ease-in') | ||
.style('opacity', 1); | ||
.duration(calendarHeatmap.settings.transition_duration / 2) | ||
.ease(d3.easeLinear) | ||
.style('opacity', 1); | ||
}) | ||
.on('mouseout', function () { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseout', function() { | ||
if (calendarHeatmap.in_transition) { return; } | ||
calendarHeatmap.hideTooltip(); | ||
}) | ||
.on('click', function (d) { | ||
if ( !!calendarHeatmap.handler && typeof calendarHeatmap.handler == 'function' ) { | ||
.on('click', function(d) { | ||
if (!!calendarHeatmap.handler && typeof calendarHeatmap.handler == 'function') { | ||
calendarHeatmap.handler(d); | ||
@@ -1456,33 +1460,33 @@ } | ||
.transition() | ||
.delay(function () { | ||
return (Math.cos(Math.PI * Math.random()) + 1) * calendarHeatmap.settings.transition_duration; | ||
}) | ||
.duration(function () { | ||
return calendarHeatmap.settings.transition_duration; | ||
}) | ||
.ease('ease-in') | ||
.style('opacity', 0.5) | ||
.call(function (transition, callback) { | ||
if ( transition.empty() ) { | ||
callback(); | ||
} | ||
var n = 0; | ||
transition | ||
.each(function() { ++n; }) | ||
.each('end', function() { | ||
if ( !--n ) { | ||
callback.apply(this, arguments); | ||
} | ||
}); | ||
}, function() { | ||
calendarHeatmap.in_transition = false; | ||
.delay(function() { | ||
return (Math.cos(Math.PI * Math.random()) + 1) * calendarHeatmap.settings.transition_duration; | ||
}) | ||
.duration(function() { | ||
return calendarHeatmap.settings.transition_duration; | ||
}) | ||
.ease(d3.easeLinear) | ||
.style('opacity', 0.5) | ||
.call(function(transition, callback) { | ||
if (transition.empty()) { | ||
callback(); | ||
} | ||
var n = 0; | ||
transition | ||
.each(function() {++n; }) | ||
.on('end', function() { | ||
if (!--n) { | ||
callback.apply(this, arguments); | ||
} | ||
}); | ||
}, function() { | ||
calendarHeatmap.in_transition = false; | ||
}); | ||
// Add time labels | ||
var timeLabels = d3.time.hours( | ||
var timeLabels = d3.timeHours( | ||
moment(calendarHeatmap.selected.date).startOf('day'), | ||
moment(calendarHeatmap.selected.date).endOf('day') | ||
); | ||
var timeScale = d3.time.scale() | ||
.range([calendarHeatmap.settings.label_padding*2, calendarHeatmap.settings.width]) | ||
var timeScale = d3.scaleTime() | ||
.range([calendarHeatmap.settings.label_padding * 2, calendarHeatmap.settings.width]) | ||
.domain([0, timeLabels.length]); | ||
@@ -1495,14 +1499,14 @@ calendarHeatmap.labels.selectAll('.label-time').remove(); | ||
.attr('class', 'label label-time') | ||
.attr('font-size', function () { | ||
.attr('font-size', function() { | ||
return Math.floor(calendarHeatmap.settings.label_padding / 3) + 'px'; | ||
}) | ||
.text(function (d) { | ||
.text(function(d) { | ||
return moment(d).format('HH:mm'); | ||
}) | ||
.attr('x', function (d, i) { | ||
.attr('x', function(d, i) { | ||
return timeScale(i); | ||
}) | ||
.attr('y', calendarHeatmap.settings.label_padding / 2) | ||
.on('mouseenter', function (d) { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseenter', function(d) { | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -1513,11 +1517,11 @@ var selected = itemScale(moment(d)); | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.style('opacity', function (d) { | ||
.ease(d3.easeLinear) | ||
.style('opacity', function(d) { | ||
var start = itemScale(moment(d.date)); | ||
var end = itemScale(moment(d.date).add(d.value, 'seconds')); | ||
return ( selected >= start && selected <= end ) ? 1 : 0.1; | ||
return (selected >= start && selected <= end) ? 1 : 0.1; | ||
}); | ||
}) | ||
.on('mouseout', function () { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseout', function() { | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -1527,3 +1531,3 @@ calendarHeatmap.items.selectAll('.item-block') | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.ease(d3.easeLinear) | ||
.style('opacity', 0.5); | ||
@@ -1540,16 +1544,16 @@ }); | ||
.attr('x', calendarHeatmap.settings.gutter) | ||
.attr('y', function (d) { | ||
return projectScale(d) + projectScale.rangeBand() / 2; | ||
.attr('y', function(d) { | ||
return projectScale(d) + projectScale.bandwidth() / 2; | ||
}) | ||
.attr('min-height', function () { | ||
return projectScale.rangeBand(); | ||
.attr('min-height', function() { | ||
return projectScale.bandwidth(); | ||
}) | ||
.style('text-anchor', 'left') | ||
.attr('font-size', function () { | ||
.attr('font-size', function() { | ||
return Math.floor(calendarHeatmap.settings.label_padding / 3) + 'px'; | ||
}) | ||
.text(function (d) { | ||
.text(function(d) { | ||
return d; | ||
}) | ||
.each(function () { | ||
.each(function() { | ||
var obj = d3.select(this), | ||
@@ -1564,4 +1568,4 @@ text_length = obj.node().getComputedTextLength(), | ||
}) | ||
.on('mouseenter', function (project) { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseenter', function(project) { | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -1571,9 +1575,9 @@ calendarHeatmap.items.selectAll('.item-block') | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.style('opacity', function (d) { | ||
.ease(d3.easeLinear) | ||
.style('opacity', function(d) { | ||
return (d.name === project) ? 1 : 0.1; | ||
}); | ||
}) | ||
.on('mouseout', function () { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('mouseout', function() { | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -1583,3 +1587,3 @@ calendarHeatmap.items.selectAll('.item-block') | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.ease(d3.easeLinear) | ||
.style('opacity', 0.5); | ||
@@ -1596,3 +1600,3 @@ }); | ||
*/ | ||
drawButton: function () { | ||
drawButton: function() { | ||
calendarHeatmap.buttons.selectAll('.button').remove(); | ||
@@ -1602,4 +1606,4 @@ var button = calendarHeatmap.buttons.append('g') | ||
.style('opacity', 0) | ||
.on('click', function () { | ||
if ( calendarHeatmap.in_transition ) { return; } | ||
.on('click', function() { | ||
if (calendarHeatmap.in_transition) { return; } | ||
@@ -1610,9 +1614,9 @@ // Set transition boolean | ||
// Clean the canvas from whichever overview type was on | ||
if ( calendarHeatmap.overview === 'year' ) { | ||
if (calendarHeatmap.overview === 'year') { | ||
calendarHeatmap.removeYearOverview(); | ||
} else if ( calendarHeatmap.overview === 'month' ) { | ||
} else if (calendarHeatmap.overview === 'month') { | ||
calendarHeatmap.removeMonthOverview(); | ||
} else if ( calendarHeatmap.overview === 'week' ) { | ||
} else if (calendarHeatmap.overview === 'week') { | ||
calendarHeatmap.removeWeekOverview(); | ||
} else if ( calendarHeatmap.overview === 'day' ) { | ||
} else if (calendarHeatmap.overview === 'day') { | ||
calendarHeatmap.removeDayOverview(); | ||
@@ -1633,6 +1637,6 @@ } | ||
.attr('y', calendarHeatmap.settings.label_padding / 2.5) | ||
.attr('dy', function () { | ||
.attr('dy', function() { | ||
return Math.floor(calendarHeatmap.settings.width / 100) / 3; | ||
}) | ||
.attr('font-size', function () { | ||
.attr('font-size', function() { | ||
return Math.floor(calendarHeatmap.settings.label_padding / 3) + 'px'; | ||
@@ -1643,3 +1647,3 @@ }) | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.ease(d3.easeLinear) | ||
.style('opacity', 1); | ||
@@ -1652,7 +1656,7 @@ }, | ||
*/ | ||
removeGlobalOverview: function () { | ||
removeGlobalOverview: function() { | ||
calendarHeatmap.items.selectAll('.item-block-year') | ||
.transition() | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-out') | ||
.ease(d3.easeLinear) | ||
.style('opacity', 0) | ||
@@ -1667,7 +1671,7 @@ .remove(); | ||
*/ | ||
removeYearOverview: function () { | ||
removeYearOverview: function() { | ||
calendarHeatmap.items.selectAll('.item-circle') | ||
.transition() | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease') | ||
.ease(d3.easeLinear) | ||
.style('opacity', 0) | ||
@@ -1684,10 +1688,10 @@ .remove(); | ||
*/ | ||
removeMonthOverview: function () { | ||
removeMonthOverview: function() { | ||
calendarHeatmap.items.selectAll('.item-block-month').selectAll('.item-block-rect') | ||
.transition() | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.ease(d3.easeLinear) | ||
.style('opacity', 0) | ||
.attr('x', function (d, i) { | ||
return ( i % 2 === 0) ? - calendarHeatmap.settings.width/3 : calendarHeatmap.settings.width/3; | ||
.attr('x', function(d, i) { | ||
return (i % 2 === 0) ? -calendarHeatmap.settings.width / 3 : calendarHeatmap.settings.width / 3; | ||
}) | ||
@@ -1704,10 +1708,10 @@ .remove(); | ||
*/ | ||
removeWeekOverview: function () { | ||
removeWeekOverview: function() { | ||
calendarHeatmap.items.selectAll('.item-block-week').selectAll('.item-block-rect') | ||
.transition() | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.ease(d3.easeLinear) | ||
.style('opacity', 0) | ||
.attr('x', function (d, i) { | ||
return ( i % 2 === 0) ? - calendarHeatmap.settings.width/3 : calendarHeatmap.settings.width/3; | ||
.attr('x', function(d, i) { | ||
return (i % 2 === 0) ? -calendarHeatmap.settings.width / 3 : calendarHeatmap.settings.width / 3; | ||
}) | ||
@@ -1724,10 +1728,10 @@ .remove(); | ||
*/ | ||
removeDayOverview: function () { | ||
removeDayOverview: function() { | ||
calendarHeatmap.items.selectAll('.item-block') | ||
.transition() | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease-in') | ||
.ease(d3.easeLinear) | ||
.style('opacity', 0) | ||
.attr('x', function (d, i) { | ||
return ( i % 2 === 0) ? - calendarHeatmap.settings.width/3 : calendarHeatmap.settings.width/3; | ||
.attr('x', function(d, i) { | ||
return (i % 2 === 0) ? -calendarHeatmap.settings.width / 3 : calendarHeatmap.settings.width / 3; | ||
}) | ||
@@ -1744,6 +1748,6 @@ .remove(); | ||
*/ | ||
hideTooltip: function () { | ||
hideTooltip: function() { | ||
calendarHeatmap.tooltip.transition() | ||
.duration(calendarHeatmap.settings.transition_duration / 2) | ||
.ease('ease-in') | ||
.ease(d3.easeLinear) | ||
.style('opacity', 0); | ||
@@ -1756,7 +1760,7 @@ }, | ||
*/ | ||
hideBackButton: function () { | ||
hideBackButton: function() { | ||
calendarHeatmap.buttons.selectAll('.button') | ||
.transition() | ||
.duration(calendarHeatmap.settings.transition_duration) | ||
.ease('ease') | ||
.ease(d3.easeLinear) | ||
.style('opacity', 0) | ||
@@ -1771,13 +1775,13 @@ .remove(); | ||
*/ | ||
formatTime: function (seconds) { | ||
formatTime: function(seconds) { | ||
var hours = Math.floor(seconds / 3600); | ||
var minutes = Math.floor((seconds - (hours * 3600)) / 60); | ||
var time = ''; | ||
if ( hours > 0 ) { | ||
if (hours > 0) { | ||
time += hours === 1 ? '1 hour ' : hours + ' hours '; | ||
} | ||
if ( minutes > 0 ) { | ||
if (minutes > 0) { | ||
time += minutes === 1 ? '1 minute' : minutes + ' minutes'; | ||
} | ||
if ( hours === 0 && minutes === 0 ) { | ||
if (hours === 0 && minutes === 0) { | ||
time = Math.round(seconds) + ' seconds'; | ||
@@ -1788,2 +1792,2 @@ } | ||
}; | ||
}; |
Sorry, the diff of this file is not supported yet
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
778241
1603
+ Addedcommander@2.20.3(transitive)
+ Addedd3@4.13.0(transitive)
+ Addedd3-array@1.2.1(transitive)
+ Addedd3-axis@1.0.8(transitive)
+ Addedd3-brush@1.0.4(transitive)
+ Addedd3-chord@1.0.4(transitive)
+ Addedd3-collection@1.0.4(transitive)
+ Addedd3-color@1.0.3(transitive)
+ Addedd3-dispatch@1.0.3(transitive)
+ Addedd3-drag@1.2.1(transitive)
+ Addedd3-dsv@1.0.8(transitive)
+ Addedd3-ease@1.0.3(transitive)
+ Addedd3-force@1.1.0(transitive)
+ Addedd3-format@1.2.2(transitive)
+ Addedd3-geo@1.9.1(transitive)
+ Addedd3-hierarchy@1.1.5(transitive)
+ Addedd3-interpolate@1.1.6(transitive)
+ Addedd3-path@1.0.5(transitive)
+ Addedd3-polygon@1.0.3(transitive)
+ Addedd3-quadtree@1.0.3(transitive)
+ Addedd3-queue@3.0.7(transitive)
+ Addedd3-random@1.1.0(transitive)
+ Addedd3-request@1.0.6(transitive)
+ Addedd3-scale@1.0.7(transitive)
+ Addedd3-selection@1.3.0(transitive)
+ Addedd3-shape@1.2.0(transitive)
+ Addedd3-time@1.0.8(transitive)
+ Addedd3-time-format@2.1.1(transitive)
+ Addedd3-timer@1.0.7(transitive)
+ Addedd3-transition@1.1.1(transitive)
+ Addedd3-voronoi@1.1.2(transitive)
+ Addedd3-zoom@1.7.1(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedrw@1.3.3(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedxmlhttprequest@1.8.0(transitive)
- Removedd3@3.5.17(transitive)
Updatedd3@^4.10.2
Updatedmoment@^2.18.1