forked from wa0x6e/cal-heatmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcal-heatmap.min.js
10 lines (10 loc) · 43.1 KB
/
cal-heatmap.min.js
1
2
3
4
5
6
7
8
9
10
/*! cal-heatmap v3.3.1 (Mon Oct 07 2013 21:53:58)
* ---------------------------------------------
* Cal-Heatmap is a javascript module to create calendar heatmap to visualize time series data, a la github contribution graph
* https://github.com/kamisama/cal-heatmap
* Licensed under the MIT license
* Copyright 2013 Wan Qi Chen
*/
function mergeRecursive(t,e){for(var n in e)try{t[n]=e[n].constructor===Object?mergeRecursive(t[n],e[n]):e[n]}catch(o){t[n]=e[n]}return t}function arrayEquals(t,e){if(!e||!t)return!1;if(t.length!==e.length)return!1;for(var n=0;t.length>n;n++)if(t[n]instanceof Array&&e[n]instanceof Array){if(!arrayEquals(t[n],e[n]))return!1}else if(t[n]!==e[n])return!1;return!0}var CalHeatMap=function(){"use strict";function t(){if(o.getDomain(o.options.start).map(function(t){return t.getTime()}).map(function(t){o._domains.set(t,o.getSubDomain(t).map(function(t){return{t:o._domainType[o.options.subDomain].extractUnit(t),v:null}}))}),o.root=d3.select(o.options.itemSelector).append("svg").attr("class","cal-heatmap-container"),o.root.attr("x",0).attr("y",0).append("svg").attr("class","graph"),o.Legend=new Legend(o),o.options.paintOnLoad)if(o.verticalDomainLabel="top"===o.options.label.position||"bottom"===o.options.label.position,o.domainVerticalLabelHeight=null===o.options.label.height?Math.max(25,2*o.options.cellSize):o.options.label.height,o.domainHorizontalLabelWidth=0,""===o.options.domainLabelFormat&&null===o.options.label.height&&(o.domainVerticalLabelHeight=0),o.verticalDomainLabel||(o.domainVerticalLabelHeight=0,o.domainHorizontalLabelWidth=o.options.label.width),"number"==typeof o.options.domainMargin&&(o.options.domainMargin=[o.options.domainMargin,o.options.domainMargin,o.options.domainMargin,o.options.domainMargin]),o.paint(),o.options.nextSelector!==!1&&d3.select(o.options.nextSelector).on("click."+o.options.itemNamespace,function(){return d3.event.preventDefault(),o.loadNextDomain()}),o.options.previousSelector!==!1&&d3.select(o.options.previousSelector).on("click."+o.options.itemNamespace,function(){return d3.event.preventDefault(),o.loadPreviousDomain()}),o.options.displayLegend&&o.Legend.redraw(o.graphDim.width-o.options.domainGutter-o.options.cellPadding),null!==o.options.afterLoad&&o.afterLoad(),o.options.loadOnInit){var t=o.getDomainKeys();o.getDatas(o.options.data,new Date(t[0]),o.getSubDomain(t[t.length-1]).pop(),function(){o.fill(),o.onComplete()})}else o.onComplete();return!0}function e(t,e){var n=o.options.cellSize*o._domainType[o.options.subDomain].column(t)+o.options.cellPadding*o._domainType[o.options.subDomain].column(t);return e!==void 0&&e===!0?n+=o.domainHorizontalLabelWidth+o.options.domainGutter+o.options.domainMargin[1]+o.options.domainMargin[3]:n}function n(t,e){var n=o.options.cellSize*o._domainType[o.options.subDomain].row(t)+o.options.cellPadding*o._domainType[o.options.subDomain].row(t);return e!==void 0&&e===!0&&(n+=o.options.domainGutter+o.domainVerticalLabelHeight+o.options.domainMargin[0]+o.options.domainMargin[2]),n}var o=this,i=["json","csv","tsv","txt"];this.options={itemSelector:"#cal-heatmap",paintOnLoad:!0,range:12,cellSize:10,cellPadding:2,cellRadius:0,domainGutter:2,domainMargin:[0,0,0,0],domain:"hour",subDomain:"min",colLimit:null,rowLimit:null,weekStartOnMonday:!0,start:new Date,minDate:null,maxDate:null,data:"",dataType:i[0],considerMissingDataAsZero:!1,loadOnInit:!0,verticalOrientation:!1,domainDynamicDimension:!0,label:{position:"bottom",align:"center",offset:{x:0,y:0},rotate:null,width:100,height:null},legend:[10,20,30,40],displayLegend:!0,legendCellSize:10,legendCellPadding:2,legendMargin:[0,0,0,0],legendVerticalPosition:"bottom",legendHorizontalPosition:"left",legendOrientation:"horizontal",legendColors:null,highlight:[],itemName:["item","items"],domainLabelFormat:null,subDomainTitleFormat:{empty:"{date}",filled:"{count} {name} {connector} {date}"},subDomainDateFormat:null,subDomainTextFormat:null,legendTitleFormat:{lower:"less than {min} {name}",inner:"between {down} and {up} {name}",upper:"more than {max} {name}"},animationDuration:500,nextSelector:!1,previousSelector:!1,itemNamespace:"cal-heatmap",onClick:null,afterLoad:null,afterLoadNextDomain:null,afterLoadPreviousDomain:null,onComplete:null,afterLoadData:function(t){return t},onMaxDomainReached:null,onMinDomainReached:null},this._domainType={min:{name:"minute",level:10,row:function(){return o.options.colLimit>0?Math.ceil(60/o.options.colLimit):o.options.rowLimit||10},column:function(){return o.options.rowLimit>0?Math.ceil(60/o.options.rowLimit):o.options.colLimit||6},position:{x:function(t){return Math.floor(t.getMinutes()/o._domainType.min.row(t))},y:function(t){return t.getMinutes()%o._domainType.min.row(t)}},format:{date:"%H:%M, %A %B %-e, %Y",legend:"",connector:"at"},extractUnit:function(t){var e=new Date(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes());return e.getTime()}},hour:{name:"hour",level:20,row:function(t){if(o.options.colLimit>0){var e=24;return"week"===o.options.domain?e=168:"month"===o.options.domain&&(e=24*o.getDayCountInMonth(t)),Math.ceil(e/o.options.colLimit)}return o.options.rowLimit||6},column:function(t){if(o.options.colLimit>0)return o.options.colLimit;switch(o.options.domain){case"day":return o.options.rowLimit>0?Math.ceil(24/o.options.rowLimit):4;case"week":return o.options.rowLimit>0?Math.ceil(168/o.options.rowLimit):28;case"month":return o.options.rowLimit>0?Math.ceil(744/o.options.rowLimit):4*(o.options.domainDynamicDimension?o.getEndOfMonth(t).getDate():31)}},position:{x:function(t){return"month"===o.options.domain?o.options.colLimit>0||o.options.rowLimit>0?Math.floor((t.getHours()+24*(t.getDate()-1))/o._domainType.hour.row(t)):Math.floor(t.getHours()/o._domainType.hour.row(t))+4*(t.getDate()-1):"week"===o.options.domain?o.options.colLimit>0||o.options.rowLimit>0?Math.floor((t.getHours()+24*o.getWeekDay(t))/o._domainType.hour.row(t)):Math.floor(t.getHours()/o._domainType.hour.row(t))+4*o.getWeekDay(t):Math.floor(t.getHours()/o._domainType.hour.row(t))},y:function(t){if(o.options.colLimit>0||o.options.rowLimit>0)switch(o.options.domain){case"month":return Math.floor((t.getHours()+24*(t.getDate()-1))%o._domainType.hour.row(t));case"week":return Math.floor((t.getHours()+24*o.getWeekDay(t))%o._domainType.hour.row(t))}return t.getHours()%o._domainType.hour.row(t)}},format:{date:"%Hh, %A %B %-e, %Y",legend:"%H:00",connector:"at"},extractUnit:function(t){var e=new Date(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours());return e.getTime()}},day:{name:"day",level:30,row:function(t){if(o.options.colLimit>0){var e=0;switch(o.options.domain){case"year":e=o.getDayCountInYear(t);break;case"month":e=o.getDayCountInMonth(t);break;case"week":e=7}return Math.ceil(e/o.options.colLimit)}return o.options.rowLimit||7},column:function(t){if(o.options.colLimit>0)return o.options.colLimit;switch(t=new Date(t),o.options.domain){case"year":if(o.options.rowLimit>0){var e=o.options.domainDynamicDimension?o.getDayCountInYear(t):366;return Math.ceil(e/o.options.rowLimit)}return o.options.domainDynamicDimension?o.getWeekNumber(new Date(t.getFullYear(),11,31))-o.getWeekNumber(new Date(t.getFullYear(),0))+1:54;case"month":if(o.options.rowLimit>0){var n=o.options.domainDynamicDimension?new Date(t.getFullYear(),t.getMonth()+1,0).getDate():31;return Math.ceil(n/o.options.rowLimit)}return o.options.verticalOrientation?6:o.options.domainDynamicDimension?o.getWeekNumber(new Date(t.getFullYear(),t.getMonth()+1,0))-o.getWeekNumber(t)+1:6;case"week":return Math.ceil(7/o._domainType.day.row(t))}},position:{x:function(t){switch(o.options.domain){case"week":return Math.floor(o.getWeekDay(t)/o._domainType.day.row(t));case"month":return o.options.colLimit>0||o.options.rowLimit>0?Math.floor((t.getDate()-1)/o._domainType.day.row(t)):o.getWeekNumber(t)-o.getWeekNumber(new Date(t.getFullYear(),t.getMonth()));case"year":return o.options.colLimit>0||o.options.rowLimit>0?Math.floor((o.getDayOfYear(t)-1)/o._domainType.day.row(t)):o.getWeekNumber(t)}},y:function(t){if(o.options.colLimit>0||o.options.rowLimit>0)switch(o.options.domain){case"year":return Math.floor((o.getDayOfYear(t)-1)%o._domainType.day.row(t));case"week":return Math.floor(o.getWeekDay(t)%o._domainType.day.row(t));case"month":return Math.floor((t.getDate()-1)%o._domainType.day.row(t))}return o.getWeekDay(t)%o._domainType.day.row(t)}},format:{date:"%A %B %-e, %Y",legend:"%e %b",connector:"on"},extractUnit:function(t){var e=new Date(t.getFullYear(),t.getMonth(),t.getDate());return e.getTime()}},week:{name:"week",level:40,row:function(){return o.options.colLimit>0?Math.ceil(54/o.options.colLimit):o.options.rowLimit||1},column:function(t){if(o.options.colLimit>0)return o.options.colLimit;switch(t=new Date(t),o.options.domain){case"year":return 54;case"month":return o.getWeekNumber(new Date(t.getFullYear(),t.getMonth()+1,0))-o.getWeekNumber(t);default:return 1}},position:{x:function(t){switch(o.options.domain){case"year":return o.options.colLimit>0||o.options.rowLimit>0?Math.floor(o.getWeekNumber(t)/o._domainType.week.row(t)):o.getWeekNumber(t);case"month":var e=o.getMonthWeekNumber(t);return o.options.colLimit>0||o.options.rowLimit>0?Math.floor((e-1)/o._domainType.week.row(t)):e}},y:function(t){return o.getWeekNumber(t)%o._domainType.week.row(t)}},format:{date:"%B Week #%W",legend:"%B Week #%W",connector:"on"},extractUnit:function(t){var e=new Date(t.getFullYear(),t.getMonth(),t.getDate()),n=e.getDay()-1;return 0>n&&(n=6),e.setDate(e.getDate()-n),e.getTime()}},month:{name:"month",level:50,row:function(){return o.options.colLimit>0?Math.ceil(12/o.options.colLimit):o.options.rowLimit||1},column:function(){return o.options.rowLimit>0?Math.ceil(12/o.options.rowLimit):o.options.colLimit||12},position:{x:function(t){return Math.floor(t.getMonth()/o._domainType.month.row(t))},y:function(t){return t.getMonth()%o._domainType.month.row(t)}},format:{date:"%B %Y",legend:"%B",connector:"on"},extractUnit:function(t){var e=new Date(t.getFullYear(),t.getMonth());return e.getTime()}},year:{name:"year",level:60,row:function(){return o.options.rowLimit||1},column:function(){return o.options.colLimit||1},position:{x:function(){return 1},y:function(){return 1}},format:{date:"%Y",legend:"%Y",connector:"on"},extractUnit:function(t){var e=new Date(t.getFullYear());return e.getTime()}}};for(var a in this._domainType)this._domainType["x_"+a]={},this._domainType["x_"+a].name="x_"+a,this._domainType["x_"+a].level=this._domainType[a].level,this._domainType["x_"+a].row=this._domainType[a].column,this._domainType["x_"+a].column=this._domainType[a].row,this._domainType["x_"+a].position={},this._domainType["x_"+a].position.x=this._domainType[a].position.y,this._domainType["x_"+a].position.y=this._domainType[a].position.x,this._domainType["x_"+a].format=this._domainType[a].format,this._domainType["x_"+a].extractUnit=this._domainType[a].extractUnit;this._domainType.x_day.row=function(t){switch(t=new Date(t),o.options.domain){case"year":return o.options.domainDynamicDimension?o.getWeekNumber(new Date(t.getFullYear(),11,31))-o.getWeekNumber(new Date(t.getFullYear(),0))+1:54;case"month":return o.options.verticalOrientation?o.options.domainDynamicDimension?o.getWeekNumber(new Date(t.getFullYear(),t.getMonth()+1,0))-o.getWeekNumber(t)+1:6:6;case"week":return 1}},this.lastInsertedSvg=null,this._completed=!1,this._domains=d3.map(),this.graphDim={width:0,height:0},this.legendDim={width:0,height:0},this.NAVIGATE_LEFT=1,this.NAVIGATE_RIGHT=2,this.RESET_ALL_ON_UPDATE=0,this.RESET_SINGLE_ON_UPDATE=1,this.APPEND_ON_UPDATE=2,this.DEFAULT_LEGEND_MARGIN=10,this.root=null,this._maxDomainReached=!1,this._minDomainReached=!1,this.domainPosition=new DomainPosition,this.Legend=null,this.legendScale=null,this.paint=function(t){function i(e,n,i,a){var r=0;switch(t){case!1:return r=n[i],n[i]+=a,o.domainPosition.setPosition(e,r),r;case o.NAVIGATE_RIGHT:return o.domainPosition.setPosition(e,n[i]),s=a,l=o.domainPosition.getPositionFromIndex(1),o.domainPosition.shiftRightBy(l),n[i];case o.NAVIGATE_LEFT:return r=-a,s=-r,l=n[i]-o.domainPosition.getLast(),o.domainPosition.setPosition(e,r),o.domainPosition.shiftLeftBy(s),r}}function a(t){switch(o.options.label.rotate){case"right":t.attr("transform",function(t){var n="rotate(90), ";switch(o.options.label.position){case"right":n+="translate(-"+e(t)+" , -"+e(t)+")";break;case"left":n+="translate(0, -"+o.domainHorizontalLabelWidth+")"}return n});break;case"left":t.attr("transform",function(t){var n="rotate(270), ";switch(o.options.label.position){case"right":n+="translate(-"+(e(t)+o.domainHorizontalLabelWidth)+" , "+e(t)+")";break;case"left":n+="translate(-"+o.domainHorizontalLabelWidth+" , "+o.domainHorizontalLabelWidth+")"}return n})}}t===void 0&&(t=!1);var r=o.root.select(".graph").selectAll(".graph-domain").data(function(){var e=o.getDomainKeys();return t===o.NAVIGATE_LEFT?e.reverse():e},function(t){return t}),s=0,l=0,m=r.enter().append("svg").attr("width",function(t){return e(t,!0)}).attr("height",function(t){return n(t,!0)}).attr("x",function(t){return o.options.verticalOrientation?(o.graphDim.width=e(t,!0),0):i(t,o.graphDim,"width",e(t,!0))}).attr("y",function(t){return o.options.verticalOrientation?i(t,o.graphDim,"height",n(t,!0)):(o.graphDim.height=n(t,!0),0)}).attr("class",function(t){var e="graph-domain",n=new Date(t);switch(o.options.domain){case"hour":e+=" h_"+n.getHours();case"day":e+=" d_"+n.getDate()+" dy_"+n.getDay();case"week":e+=" w_"+o.getWeekNumber(n);case"month":e+=" m_"+(n.getMonth()+1);case"year":e+=" y_"+n.getFullYear()}return e});o.lastInsertedSvg=m,m.append("rect").attr("width",function(t){return e(t,!0)-o.options.domainGutter-o.options.cellPadding}).attr("height",function(t){return n(t,!0)-o.options.domainGutter-o.options.cellPadding}).attr("class","domain-background");var u=m.append("svg").attr("x",function(){return"left"===o.options.label.position?o.domainHorizontalLabelWidth+o.options.domainMargin[3]:o.options.domainMargin[3]}).attr("y",function(){return"top"===o.options.label.position?o.domainVerticalLabelHeight+o.options.domainMargin[0]:o.options.domainMargin[0]}).attr("class","graph-subdomain-group"),g=u.selectAll("g").data(function(t){return o._domains.get(t)}).enter().append("g");g.append("rect").attr("class",function(t){return"graph-rect"+o.getHighlightClassName(t.t)+(null!==o.options.onClick?" hover_cursor":"")}).attr("width",o.options.cellSize).attr("height",o.options.cellSize).attr("x",function(t){return o.positionSubDomainX(t.t)}).attr("y",function(t){return o.positionSubDomainY(t.t)}).on("click",function(t){return null!==o.options.onClick?o.onClick(new Date(t.t),t.v):void 0}).call(function(t){o.options.cellRadius>0&&t.attr("rx",o.options.cellRadius).attr("ry",o.options.cellRadius),null!==o.legendScale&&null!==o.options.legendColors&&o.options.legendColors.hasOwnProperty("base")&&t.attr("fill",o.options.legendColors.base)}),g.append("title").text(function(t){return o.formatDate(new Date(t.t),o.options.subDomainDateFormat)}),""!==o.options.domainLabelFormat&&m.append("text").attr("class","graph-label").attr("y",function(t){var e=o.options.domainMargin[0];switch(o.options.label.position){case"top":e+=o.domainVerticalLabelHeight/2;break;case"bottom":e+=n(t)+o.domainVerticalLabelHeight/2}return e+o.options.label.offset.y*("right"===o.options.label.rotate&&"right"===o.options.label.position||"left"===o.options.label.rotate&&"left"===o.options.label.position?-1:1)}).attr("x",function(t){var n=o.options.domainMargin[3];switch(o.options.label.position){case"right":n+=e(t);break;case"bottom":case"top":n+=e(t)/2}return"right"===o.options.label.align?n+o.domainHorizontalLabelWidth-o.options.label.offset.x*("right"===o.options.label.rotate?-1:1):n+o.options.label.offset.x}).attr("text-anchor",function(){switch(o.options.label.align){case"start":case"left":return"start";case"end":case"right":return"end";default:return"middle"}}).attr("dominant-baseline",function(){return o.verticalDomainLabel?"middle":"top"}).text(function(t){return o.formatDate(new Date(t),o.options.domainLabelFormat)}).call(a),null!==o.options.subDomainTextFormat&&g.append("text").attr("class",function(t){return"subdomain-text"+o.getHighlightClassName(t.t)}).attr("x",function(t){return o.positionSubDomainX(t.t)+o.options.cellSize/2}).attr("y",function(t){return o.positionSubDomainY(t.t)+o.options.cellSize/2}).attr("text-anchor","middle").attr("dominant-baseline","central").text(function(t){return o.formatDate(new Date(t.t),o.options.subDomainTextFormat)}),t!==!1&&r.transition().duration(o.options.animationDuration).attr("x",function(t){return o.options.verticalOrientation?0:o.domainPosition.getPosition(t)}).attr("y",function(t){return o.options.verticalOrientation?o.domainPosition.getPosition(t):0});var h=o.graphDim.width,p=o.graphDim.height;o.options.verticalOrientation?o.graphDim.height+=s-l:o.graphDim.width+=s-l,r.exit().transition().duration(o.options.animationDuration).attr("x",function(n){if(o.options.verticalOrientation)return 0;switch(t){case o.NAVIGATE_LEFT:return Math.min(o.graphDim.width,h);case o.NAVIGATE_RIGHT:return-e(n,!0)}}).attr("y",function(e){if(!o.options.verticalOrientation)return 0;switch(t){case o.NAVIGATE_LEFT:return Math.min(o.graphDim.height,p);case o.NAVIGATE_RIGHT:return-n(e,!0)}}).remove(),o.resize()},this.fill=function(t){function e(t){return null===o.legendScale?!1:(t.attr("fill",function(t){return 0===t.v&&null!==o.options.legendColors&&o.options.legendColors.hasOwnProperty("empty")?o.options.legendColors.empty:0>t.v&&o.options.legend[0]>0&&null!==o.options.legendColors&&o.options.legendColors.hasOwnProperty("overflow")?o.options.legendColors.overflow:o.legendScale(Math.min(t.v,o.options.legend[o.options.legend.length-2]))}),void 0)}0===arguments.length&&(t=o.root.selectAll(".graph-domain"));var n=t.selectAll("svg").selectAll("g").data(function(t){return o._domains.get(t)});n.transition().duration(o.options.animationDuration).select("rect").attr("class",function(t){var e=o.getHighlightClassName(t.t);return null===o.legendScale&&(e=" graph-rect"),null!==t.v?e+=" "+o.Legend.getClass(t.v,null===o.legendScale):o.options.considerMissingDataAsZero&&(e+=" "+o.Legend.getClass(0,null===o.legendScale)),null!==o.options.onClick&&(e+=" hover_cursor"),e}).call(e),n.transition().duration(o.options.animationDuration).select("title").text(function(t){if(null!==t.v||o.options.considerMissingDataAsZero){var e=t.v;return null===e&&o.options.considerMissingDataAsZero&&(e=0),o.options.subDomainTitleFormat.filled.format({count:o.formatNumber(e),name:o.options.itemName[1!==e?1:0],connector:o._domainType[o.options.subDomain].format.connector,date:o.formatDate(new Date(t.t),o.options.subDomainDateFormat)})}return o.options.subDomainTitleFormat.empty.format({date:o.formatDate(new Date(t.t),o.options.subDomainDateFormat)})})},this.init=function(e){function n(t){return!(t instanceof Element)&&"string"!=typeof t||""===t}if(o.options=mergeRecursive(o.options,e),!this._domainType.hasOwnProperty(o.options.domain)||"min"===o.options.domain||"x_"===o.options.domain.substring(0,2))return console.log("The domain '"+o.options.domain+"' is not valid"),!1;if(!this._domainType.hasOwnProperty(o.options.subDomain)||"year"===o.options.subDomain)return console.log("The subDomain '"+o.options.subDomain+"' is not valid"),!1;if(this._domainType[o.options.domain].level<=this._domainType[o.options.subDomain].level)return console.log("'"+o.options.subDomain+"' is not a valid subDomain to '"+o.options.domain+"'"),!1;if(!e.hasOwnProperty("subDomain"))switch(o.options.domain){case"year":o.options.subDomain="month";break;case"month":o.options.subDomain="day";break;case"week":o.options.subDomain="day";break;case"day":o.options.subDomain="hour";break;default:o.options.subDomain="min"}if(0>i.indexOf(o.options.dataType))return console.log("The data type '"+o.options.dataType+"' is not valid data type"),!1;if(null===o.options.subDomainDateFormat&&(o.options.subDomainDateFormat=this._domainType[o.options.subDomain].format.date),null===o.options.domainLabelFormat&&(o.options.domainLabelFormat=this._domainType[o.options.domain].format.legend),!e.hasOwnProperty("label")||e.hasOwnProperty("label")&&!e.label.hasOwnProperty("align")){switch(o.options.label.position){case"left":o.options.label.align="right";break;case"right":o.options.label.align="left";break;default:o.options.label.align="center"}"left"===o.options.label.rotate?o.options.label.align="right":"right"===o.options.label.rotate&&(o.options.label.align="left")}if((!e.hasOwnProperty("label")||e.hasOwnProperty("label")&&!e.label.hasOwnProperty("offset"))&&("left"===o.options.label.position||"right"===o.options.label.position)&&(o.options.label.offset={x:10,y:15}),n(o.options.itemSelector))return console.log("The itemSelector is invalid"),!1;if(null===d3.select(o.options.itemSelector)[0][0])return console.log("The node specified in itemSelector does not exists"),!1;if(o.options.nextSelector!==!1&&n(o.options.nextSelector))return console.log("The nextSelector is invalid"),!1;if(o.options.previousSelector!==!1&&n(o.options.previousSelector))return console.log("The previousSelector is invalid"),!1;if(("string"!=typeof o.options.itemNamespace||""===o.options.itemNamespace)&&(console.log("itemNamespace can not be empty, falling back to cal-heatmap"),o.options.itemNamespace="cal-heatmap"),"number"==typeof o.options.domainMargin&&(o.options.domainMargin=[o.options.domainMargin,o.options.domainMargin,o.options.domainMargin,o.options.domainMargin]),e.hasOwnProperty("rowLimit")&&e.hasOwnProperty("colLimit")&&e.rowLimit>0&&e.colLimit>0&&(console.log("colLimit and rowLimit are mutually exclusive, rowLimit will be ignored"),o.options.rowLimit=null),Array.isArray(o.options.domainMargin))switch(o.options.domainMargin.length){case 0:o.options.domainMargin=[0,0,0,0];break;case 1:o.options.domainMargin=[o.options.domainMargin,o.options.domainMargin,o.options.domainMargin,o.options.domainMargin];break;case 2:o.options.domainMargin=[o.options.domainMargin[0],o.options.domainMargin[1],o.options.domainMargin[0],o.options.domainMargin[1]];break;case 3:o.options.domainMargin=[o.options.domainMargin[0],o.options.domainMargin[1],o.options.domainMargin[2],o.options.domainMargin[1]];break;case 4:o.options.domainMargin=o.options.domainMargin;break;default:o.options.domainMargin.splice(4)}"string"==typeof o.options.itemName?o.options.itemName=[o.options.itemName,o.options.itemName+"s"]:Array.isArray(o.options.itemName)&&1===o.options.itemName.length&&(o.options.itemName=[o.options.itemName[0],o.options.itemName[0]+"s"]);var a=["data","onComplete","onClick","afterLoad","afterLoadData","afterLoadPreviousDomain","afterLoadNextDomain"];for(var r in a)e.hasOwnProperty(a[r])&&(o.options[a[r]]=e[a[r]]);if("string"==typeof o.options.highlight)o.options.highlight="now"===o.options.highlight?[new Date]:[];else if(Array.isArray(o.options.highlight)){var s=o.options.highlight.indexOf("now");-1!==s&&(o.options.highlight.splice(s,1),o.options.highlight.push(new Date))}return e.hasOwnProperty("legendMargin")||("top"===o.options.legendVerticalPosition?o.options.legendMargin[0]=o.DEFAULT_LEGEND_MARGIN:"bottom"===o.options.legendVerticalPosition&&(o.options.legendMargin[2]=o.DEFAULT_LEGEND_MARGIN),("middle"===o.options.legendHorizontalPosition||"center"===o.options.legendHorizontalPosition)&&("left"===o.options.legendVerticalPosition?o.options.legendMargin[1]=o.DEFAULT_LEGEND_MARGIN:"right"===o.options.legendVerticalPosition&&(o.options.legendMargin[3]=o.DEFAULT_LEGEND_MARGIN))),t()}};CalHeatMap.prototype={triggerEvent:function(t,e,n){return 3===arguments.length&&n||null===this.options[t]?!0:"function"==typeof this.options[t]?("function"==typeof e&&(e=e()),this.options[t].apply(this,e)):(console.log("Provided callback for "+t+" is not a function."),!1)},onClick:function(t,e){return this.triggerEvent("onClick",[t,e])},afterLoad:function(){return this.triggerEvent("afterLoad")},onComplete:function(){var t=this.triggerEvent("onComplete",[],this._completed);return this._completed=!0,t},afterLoadPreviousDomain:function(t){var e=this;return this.triggerEvent("afterLoadPreviousDomain",function(){var n=e.getSubDomain(t);return[n.shift(),n.pop()]})},afterLoadNextDomain:function(t){var e=this;return this.triggerEvent("afterLoadNextDomain",function(){var n=e.getSubDomain(t);return[n.shift(),n.pop()]})},onMinDomainReached:function(t){return this._minDomainReached=t,this.triggerEvent("onMinDomainReached",[t])},onMaxDomainReached:function(t){return this._maxDomainReached=t,this.triggerEvent("onMaxDomainReached",[t])},formatNumber:d3.format(",g"),formatDate:function(t,e){if(e===void 0&&(e="title"),"function"==typeof e)return e(t);var n=d3.time.format(e);return n(t)},loadNextDomain:function(t){if(this._maxDomainReached||0===t)return!1;0===arguments.length&&(t=1);for(var e=this.getDomain(this.getNextDomain(),t),n=this,o=-1,i=e.length;i>++o;){if(this.maxDomainIsReached(e[o])){e=e.slice(0,o);break}this._domains.set(e[o].getTime(),this.getSubDomain(e[o]).map(function(t){return{t:n._domainType[n.options.subDomain].extractUnit(t),v:null}}))}var a=this.getDomainKeys();return a.slice(0,e.length).forEach(function(t){n._domains.remove(t)}),this.paint(this.NAVIGATE_RIGHT),this.getDatas(this.options.data,e[0],this.getSubDomain(e[e.length-1]).pop(),function(){n.fill(n.lastInsertedSvg)}),this.afterLoadNextDomain(e[e.length-1]),this.maxDomainIsReached(this.getNextDomain().getTime())&&this.onMaxDomainReached(!0),this._minDomainReached&&!this.minDomainIsReached(a[1])&&this.onMinDomainReached(!1),!0},loadPreviousDomain:function(t){if(this._minDomainReached||0===t)return!1;0===arguments.length&&(t=1);for(var e=this.getDomainKeys(),n=this.getDomain(e[0],-t).reverse(),o=this,i=-1,a=n.length;a>++i;)if(this.minDomainIsReached(n[i])){n=n.slice(0,i+1);break}for(i=0,a=n.length;a>i;i++)o._domains.set(n[i].getTime(),o.getSubDomain(n[i]).map(function(t){return{t:o._domainType[o.options.subDomain].extractUnit(t),v:null}}));return e=this.getDomainKeys(),e.slice(-n.length).forEach(function(t){o._domains.remove(t)}),n=n.reverse(),this.paint(this.NAVIGATE_LEFT),this.getDatas(this.options.data,n[0],this.getSubDomain(n[n.length-1]).pop(),function(){o.fill(o.lastInsertedSvg)}),this.afterLoadPreviousDomain(n[0]),this.minDomainIsReached(n[0])&&this.onMinDomainReached(!0),this._maxDomainReached&&!this.maxDomainIsReached(e[e.length-1])&&this.onMaxDomainReached(!1),!0},maxDomainIsReached:function(t){return null!==this.options.maxDate&&t>this.options.maxDate.getTime()},minDomainIsReached:function(t){return null!==this.options.minDate&&this.options.minDate.getTime()>=t},getDomainKeys:function(){return this._domains.keys().map(function(t){return parseInt(t,10)}).sort(function(t,e){return t-e})},positionSubDomainX:function(t){var e=this._domainType[this.options.subDomain].position.x(new Date(t));return e*this.options.cellSize+e*this.options.cellPadding},positionSubDomainY:function(t){var e=this._domainType[this.options.subDomain].position.y(new Date(t));return e*this.options.cellSize+e*this.options.cellPadding},getHighlightClassName:function(t){if(t=new Date(t),this.options.highlight.length>0)for(var e in this.options.highlight)if(this.options.highlight[e]instanceof Date&&this.dateIsEqual(this.options.highlight[e],t))return" highlight"+(this.isNow(this.options.highlight[e])?" now":"");return""},isNow:function(t){return this.dateIsEqual(t,new Date)},dateIsEqual:function(t,e){switch(this.options.subDomain){case"x_min":case"min":return t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate()&&t.getHours()===e.getHours()&&t.getMinutes()===e.getMinutes();case"x_hour":case"hour":return t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate()&&t.getHours()===e.getHours();case"x_day":case"day":return t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate();case"x_week":case"week":case"x_month":case"month":return t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth();default:return!1}},getDayOfYear:d3.time.format("%j"),getWeekNumber:function(t){var e=this.options.weekStartOnMonday===!0?d3.time.format("%W"):d3.time.format("%U");return e(t)},getMonthWeekNumber:function(t){"number"==typeof t&&(t=new Date(t));var e=this.getWeekNumber(new Date(t.getFullYear(),t.getMonth()));return this.getWeekNumber(t)-e-1},getWeekNumberInYear:function(t){"number"==typeof t&&(t=new Date(t))},getDayCountInMonth:function(t){return this.getEndOfMonth(t).getDate()},getDayCountInYear:function(t){return"number"==typeof t&&(t=new Date(t)),0===t.getFullYear()%400?366:365},getWeekDay:function(t){return this.options.weekStartOnMonday===!1?t.getDay():0===t.getDay()?6:t.getDay()-1},getEndOfMonth:function(t){return"number"==typeof t&&(t=new Date(t)),new Date(t.getFullYear(),t.getMonth()+1,0)},jumpDate:function(t,e,n){var o=new Date(t);switch(n){case"hour":o.setHours(o.getHours()+e);break;case"day":o.setHours(o.getHours()+24*e);break;case"week":o.setHours(o.getHours()+7*24*e);break;case"month":o.setMonth(o.getMonth()+e);break;case"year":o.setFullYear(o.getFullYear()+e)}return new Date(o)},getMinuteDomain:function(t,e){var n=new Date(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours()),o=null;return o="object"==typeof e?new Date(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours()):new Date(n.getTime()+6e4*e),d3.time.minutes(Math.min(n,o),Math.max(n,o))},getHourDomain:function(t,e){var n=new Date(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours()),o=null;return o="object"==typeof e?new Date(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours()):new Date(n.getTime()+36e5*e),d3.time.hours(Math.min(n,o),Math.max(n,o))},getDayDomain:function(t,e){var n=new Date(t.getFullYear(),t.getMonth(),t.getDate()),o=null;return"object"==typeof e?o=new Date(e.getFullYear(),e.getMonth(),e.getDate()):(o=new Date(n),o=new Date(o.setDate(o.getDate()+parseInt(e,10)))),d3.time.days(Math.min(n,o),Math.max(n,o))},getWeekDomain:function(t,e){var n;this.options.weekStartOnMonday===!1?n=new Date(t.getFullYear(),t.getMonth(),t.getDate()-t.getDay()):1===t.getDay()?n=new Date(t.getFullYear(),t.getMonth(),t.getDate()):0===t.getDay()?(n=new Date(t.getFullYear(),t.getMonth(),t.getDate()),n.setDate(n.getDate()-6)):n=new Date(t.getFullYear(),t.getMonth(),t.getDate()-t.getDay()+1);var o=new Date(n),i=e;return"object"!=typeof e&&(i=new Date(o.setDate(o.getDate()+7*e))),this.options.weekStartOnMonday===!0?d3.time.mondays(Math.min(n,i),Math.max(n,i)):d3.time.sundays(Math.min(n,i),Math.max(n,i))},getMonthDomain:function(t,e){var n=new Date(t.getFullYear(),t.getMonth()),o=null;return"object"==typeof e?o=new Date(e.getFullYear(),e.getMonth()):(o=new Date(n),o=o.setMonth(o.getMonth()+e)),d3.time.months(Math.min(n,o),Math.max(n,o))},getYearDomain:function(t,e){var n=new Date(t.getFullYear(),0),o=null;return o="object"==typeof e?new Date(e.getFullYear(),0):new Date(t.getFullYear()+e,0),d3.time.years(Math.min(n,o),Math.max(n,o))},getDomain:function(t,e){switch("number"==typeof t&&(t=new Date(t)),2>arguments.length&&(e=this.options.range),this.options.domain){case"hour":return this.getHourDomain(t,e);case"day":return this.getDayDomain(t,e);case"week":return this.getWeekDomain(t,e);case"month":return this.getMonthDomain(t,e);case"year":return this.getYearDomain(t,e)}},getSubDomain:function(t){"number"==typeof t&&(t=new Date(t));var e=this,n=function(t,n){switch(n){case"year":return e.getDayCountInYear(t);case"month":return e.getDayCountInMonth(t);case"week":return 7}},o=function(t,e){switch(e){case"hour":return 60;case"day":return 1440;case"week":return 10080}},i=function(t,n){switch(n){case"day":return 24;case"week":return 168;case"month":return 24*e.getDayCountInMonth(t)}},a=function(t,n){if("month"===n){var o=new Date(t.getFullYear(),t.getMonth()+1,0),i=e.getWeekNumber(o),a=e.getWeekNumber(new Date(t.getFullYear(),t.getMonth()));return a>i&&(a=0,i++),i-a+1}return"year"===n?e.getWeekNumber(new Date(t.getFullYear(),11,31)):void 0};switch(this.options.subDomain){case"x_min":case"min":return this.getMinuteDomain(t,o(t,this.options.domain));case"x_hour":case"hour":return this.getHourDomain(t,i(t,this.options.domain));case"x_day":case"day":return this.getDayDomain(t,n(t,this.options.domain));case"x_week":case"week":return this.getWeekDomain(t,a(t,this.options.domain));
case"x_month":case"month":return this.getMonthDomain(t,12)}},getNextDomain:function(t){return 0===arguments.length&&(t=1),this.getDomain(this.jumpDate(this.getDomainKeys().pop(),t,this.options.domain),1)[0]},getPreviousDomain:function(t){return 0===arguments.length&&(t=1),this.getDomain(this.jumpDate(this.getDomainKeys().shift(),-t,this.options.domain),1)[0]},getDatas:function(t,e,n,o,i,a){var r=this;5>arguments.length&&(i=!0),6>arguments.length&&(a=this.APPEND_ON_UPDATE);var s=function(t){if(i!==!1)if("function"==typeof i)t=i(t);else{if("function"!=typeof r.options.afterLoadData)return console.log("Provided callback for afterLoadData is not a function."),{};t=r.options.afterLoadData(t)}r.parseDatas(t,a,e,n),o()};switch(typeof t){case"string":if(""===t)return s({}),!0;switch(this.options.dataType){case"json":d3.json(this.parseURI(t,e,n),s);break;case"csv":d3.csv(this.parseURI(t,e,n),s);break;case"tsv":d3.tsv(this.parseURI(t,e,n),s);break;case"text":d3.text(this.parseURI(t,e,n),"text/plain",s)}return!1;case"object":if(t===Object(t)&&"[object Array]"!==Object.prototype.toString.call(t))return s(t),!1}return!0},parseDatas:function(t,e,n,o){e===this.RESET_ALL_ON_UPDATE&&this._domains.forEach(function(t,e){e.forEach(function(t,e,n){n[e].v=null})});var i=this._domains.keys(),a=this._domains.get(i[0])[1].t-this._domains.get(i[0])[0].t;for(var r in t)if(!isNaN(r)){var s=new Date(1e3*r),l=this.getDomain(s)[0].getTime();if(this._domains.has(l)&&l>=+n&&+o>l){var m=this._domainType[this.options.subDomain].extractUnit(s),u=this._domains.get(l),g=Math.round((m-l)/a);e===this.RESET_SINGLE_ON_UPDATE?u[g].v=t[r]:isNaN(u[g].v)?u[g].v=t[r]:u[g].v+=t[r]}}},parseURI:function(t,e,n){return t=t.replace(/\{\{t:start\}\}/g,e.getTime()/1e3),t=t.replace(/\{\{t:end\}\}/g,n.getTime()/1e3),t=t.replace(/\{\{d:start\}\}/g,e.toISOString()),t=t.replace(/\{\{d:end\}\}/g,n.toISOString())},resize:function(){var t=this,e=t.options.displayLegend?t.Legend.getDim("width")+t.options.legendMargin[1]+t.options.legendMargin[3]:0,n=t.options.displayLegend?t.Legend.getDim("height")+t.options.legendMargin[0]+t.options.legendMargin[2]:0,o=t.graphDim.width-t.options.domainGutter-t.options.cellPadding,i=t.graphDim.height-t.options.domainGutter-t.options.cellPadding;this.root.transition().duration(t.options.animationDuration).attr("width",function(){return"middle"===t.options.legendVerticalPosition||"center"===t.options.legendVerticalPosition?o+e:Math.max(o,e)}).attr("height",function(){return"middle"===t.options.legendVerticalPosition||"center"===t.options.legendVerticalPosition?Math.max(i,n):i+n}),this.root.select(".graph").transition().duration(t.options.animationDuration).attr("y",function(){return"top"===t.options.legendVerticalPosition?n:0}).attr("x",function(){return"middle"!==t.options.legendVerticalPosition&&"center"!==t.options.legendVerticalPosition||"left"!==t.options.legendHorizontalPosition?0:e})},next:function(t){return 0===arguments.length&&(t=1),this.loadNextDomain(t)},previous:function(t){return 0===arguments.length&&(t=1),this.loadPreviousDomain(t)},jumpTo:function(t,e){2>arguments.length&&(e=!1);var n=this.getDomainKeys(),o=n[0],i=n[n.length-1];return o>t?this.loadPreviousDomain(this.getDomain(o,t).length):e?this.loadNextDomain(this.getDomain(o,t).length):t>i?this.loadNextDomain(this.getDomain(i,t).length):!1},update:function(t,e,n){2>arguments.length&&(e=!0),3>arguments.length&&(n=this.RESET_ALL_ON_UPDATE);var o=this.getDomainKeys(),i=this;this.getDatas(t,new Date(o[0]),this.getSubDomain(o[o.length-1]).pop(),function(){i.fill()},e,n)},setLegend:function(){var t=this.options.legend.slice(0);arguments.length>=1&&Array.isArray(arguments[0])&&(this.options.legend=arguments[0]),arguments.length>=2&&(this.options.legendColors=Array.isArray(arguments[1])&&arguments[1].length>=2?[arguments[1][0],arguments[1][1]]:arguments[1]),(arguments.length>0&&!arrayEquals(t,this.options.legend)||arguments.length>=2)&&(this.Legend.buildColors(),this.fill()),this.options.displayLegend&&this.Legend.redraw(this.graphDim.width-this.options.domainGutter-this.options.cellPadding)},removeLegend:function(){return this.options.displayLegend?(this.options.displayLegend=!1,this.Legend.remove(),!0):!1},showLegend:function(){return this.options.displayLegend?!1:(this.options.displayLegend=!0,this.Legend.redraw(this.graphDim.width-this.options.domainGutter-this.options.cellPadding),!0)},getSVG:function(){for(var t={".graph":{},".graph-rect":{},"rect.highlight":{},"rect.now":{},"text.highlight":{},"text.now":{},".domain-background":{},".graph-label":{},".subdomain-text":{},".qi":{}},e=0,n=this.options.legend.length;n>e;e++)t[".q"+e]={};var o=this.root,i=["stroke","stroke-width","stroke-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-miterlimit","fill","fill-opacity","fill-rule","marker","marker-start","marker-mid","marker-end","alignement-baseline","baseline-shift","dominant-baseline","glyph-orientation-horizontal","glyph-orientation-vertical","kerning","text-anchor","shape-rendering","text-transform","font-family","font","font-size","font-weight"],a=function(e,n,o){-1!==i.indexOf(n)&&(t[e][n]=o)},r=function(t){return o.select(t)[0][0]};for(var s in t){var l=r(s);if(null!==l)if("getComputedStyle"in window){var m=getComputedStyle(l,null);if(0!==m.length)for(var u=0;m.length>u;u++)a(s,m.item(u),m.getPropertyValue(m.item(u)));else for(var g in m)m.hasOwnProperty(g)&&a(s,g,m[g])}else if("currentStyle"in l){var h=l.currentStyle;for(var p in h)a(s,p,h[p])}}var c='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><style type="text/css"><![CDATA[ ';for(var d in t){c+=d+" {\n";for(var f in t[d])c+=" "+f+":"+t[d][f]+";\n";c+="}\n"}return c+="]]></style>",c+=(new XMLSerializer).serializeToString(this.root.selectAll("svg")[0][0]),c+=(new XMLSerializer).serializeToString(this.root.selectAll("svg")[0][1]),c+="</svg>"}};var DomainPosition=function(){this.positions=d3.map()};DomainPosition.prototype.getPosition=function(t){return this.positions.get(t)},DomainPosition.prototype.getPositionFromIndex=function(t){var e=this.getKeys();return this.positions.get(e[t])},DomainPosition.prototype.getLast=function(){var t=this.getKeys();return this.positions.get(t[t.length-1])},DomainPosition.prototype.setPosition=function(t,e){this.positions.set(t,e)},DomainPosition.prototype.shiftRightBy=function(t){this.positions.forEach(function(e,n){this.set(e,n-t)});var e=this.getKeys();this.positions.remove(e[0])},DomainPosition.prototype.shiftLeftBy=function(t){this.positions.forEach(function(e,n){this.set(e,n+t)});var e=this.getKeys();this.positions.remove(e[e.length-1])},DomainPosition.prototype.getKeys=function(){return this.positions.keys().sort(function(t,e){return parseInt(t,10)-parseInt(e,10)})};var Legend=function(t){this.calendar=t,this.computeDim(),null!==t.options.legendColors&&this.buildColors()};Legend.prototype.computeDim=function(){this.dim={width:this.calendar.options.legendCellSize*(this.calendar.options.legend.length+1)+this.calendar.options.legendCellPadding*this.calendar.options.legend.length+1,height:this.calendar.options.legendCellSize+1}},Legend.prototype.remove=function(){this.calendar.root.select(".graph-legend").remove(),this.calendar.resize()},Legend.prototype.redraw=function(t){function e(t){t.attr("width",r.options.legendCellSize).attr("height",r.options.legendCellSize).attr("x",function(t,e){return e*(r.options.legendCellSize+r.options.legendCellPadding)})}function n(){switch(r.options.legendHorizontalPosition){case"right":return"center"===r.options.legendVerticalPosition||"middle"===r.options.legendVerticalPosition?t+r.options.legendMargin[3]:t-a.getDim("width")-r.options.legendMargin[1];case"middle":case"center":return Math.round(t/2-a.getDim("width")/2);default:return r.options.legendMargin[3]}}function o(){switch(r.options.legendVerticalPosition){case"center":case"middle":case"top":return r.options.legendMargin[0];case"bottom":return r.graphDim.height+r.options.legendMargin[0]}}var i,a=this,r=this.calendar,s=r.root;this.computeDim();var l=r.options.legend.slice(0);l.push(l[l.length-1]+1);var m=r.root.select(".graph-legend");null!==m[0][0]?(s=m,i=s.select("g").selectAll("rect").data(l)):(s="top"===r.options.legendVerticalPosition?s.insert("svg",".graph"):s.append("svg"),s.attr("x",n()).attr("y",o()),i=s.attr("class","graph-legend").attr("height",a.getDim("height")).attr("width",a.getDim("width")).append("g").selectAll().data(l)),i.enter().append("rect").call(e).attr("class",function(t){return r.Legend.getClass(t,null===r.legendScale)}).attr("fill-opacity",0).call(function(t){null!==r.legendScale&&null!==r.options.legendColors&&r.options.legendColors.hasOwnProperty("base")&&t.attr("fill",r.options.legendColors.base)}).append("title"),i.exit().transition().duration(r.options.animationDuration).attr("fill-opacity",0).remove(),i.transition().delay(function(t,e){return r.options.animationDuration*e/10}).call(e).attr("fill-opacity",1).call(function(t){t.attr("fill",function(t,e){return null===r.legendScale?"":0===e?r.legendScale(t-1):r.legendScale(r.options.legend[e-1])}),t.attr("class",function(t){return r.Legend.getClass(t,null===r.legendScale)})}),i.select("title").text(function(t,e){return 0===e?r.options.legendTitleFormat.lower.format({min:r.options.legend[e],name:r.options.itemName[1]}):e===l.length-1?r.options.legendTitleFormat.upper.format({max:r.options.legend[e-1],name:r.options.itemName[1]}):r.options.legendTitleFormat.inner.format({down:r.options.legend[e-1],up:r.options.legend[e],name:r.options.itemName[1]})}),s.transition().duration(r.options.animationDuration).attr("x",n()).attr("y",o()).attr("width",a.getDim("width")).attr("height",a.getDim("height")),s.select("g").transition().duration(r.options.animationDuration).attr("transform",function(){return"vertical"===r.options.legendOrientation?"rotate(90 "+r.options.legendCellSize/2+" "+r.options.legendCellSize/2+")":""}),r.resize()},Legend.prototype.getDim=function(t){switch(t){case"width":return this.dim["horizontal"===this.calendar.options.legendOrientation?"width":"height"];case"height":return this.dim["horizontal"===this.calendar.options.legendOrientation?"height":"width"]}},Legend.prototype.buildColors=function(){if(null===this.calendar.options.legendColors)return this.calendar.legendScale=null,!1;var t=[];if(Array.isArray(this.calendar.options.legendColors))t=this.calendar.options.legendColors;else{if(!this.calendar.options.legendColors.hasOwnProperty("min")||!this.calendar.options.legendColors.hasOwnProperty("max"))return this.calendar.options.legendColors=null,!1;t=[this.calendar.options.legendColors.min,this.calendar.options.legendColors.max]}var e=this.calendar.options.legend.slice(0);e[0]>0?e.unshift(0):0>e[0]&&e.unshift(e[0]-(e[e.length-1]-e[0])/e.length);var n=d3.scale.linear().range(t).interpolate(d3.interpolateHcl).domain([d3.min(e),d3.max(e)]),o=e.map(function(t){return n(t)});return this.calendar.legendScale=d3.scale.threshold().domain(this.calendar.options.legend).range(o),!0},Legend.prototype.getClass=function(t,e){if(null===t||isNaN(t))return"";for(var n=[this.calendar.options.legend.length+1],o=0,i=this.calendar.options.legend.length-1;i>=o;o++){if(this.calendar.options.legend[0]>0&&0>t){n=["1","i"];break}if(this.calendar.options.legend[o]>=t){n=[o+1];break}}return 0===t&&n.push(0),n.unshift(""),(n.join(" r")+(e?n.join(" q"):"")).trim()},String.prototype.format=function(){var t=this;for(var e in arguments[0]){var n=RegExp("\\{"+e+"\\}","gi");t=t.replace(n,arguments[0][e])}return t},"function"==typeof define&&define.amd&&define(["d3"],function(){return CalHeatMap});
//@ sourceMappingURL=cal-heatmap.source-map.js