forked from x-way/cal-heatmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cal-heatmap.min.js
8 lines (8 loc) · 45.5 KB
/
cal-heatmap.min.js
1
2
3
4
5
6
7
8
/*! cal-heatmap v3.6.2 (Sun Mar 13 2022 17:37:51)
* ---------------------------------------------
* Cal-Heatmap is a javascript module to create calendar heatmap to visualize time series data
* https://github.com/wa0x6e/cal-heatmap
* Licensed under the MIT license
* Copyright 2014 Wan Qi Chen
*/
var d3="function"==typeof require?require("d3"):window.d3,CalHeatMap=function(){"use strict";var t,e,m=this;for(t in this.allowedDataType=["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:this.allowedDataType[0],dataPostPayload:null,dataRequestHeaders:null,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",tooltip:!1,onClick:null,afterLoad:null,afterLoadNextDomain:null,afterLoadPreviousDomain:null,onComplete:null,afterLoadData:function(t){return t},afterUpdate:null,onMaxDomainReached:null,onMinDomainReached:null},this._domainType={min:{name:"minute",level:10,maxItemNumber:60,defaultRowNumber:10,defaultColumnNumber:6,row:function(t){return m.getSubDomainRowNumber(t)},column:function(t){return m.getSubDomainColumnNumber(t)},position:{x:function(t){return Math.floor(t.getMinutes()/m._domainType.min.row(t))},y:function(t){return t.getMinutes()%m._domainType.min.row(t)}},format:{date:"%H:%M, %A %B %-e, %Y",legend:"",connector:"at"},extractUnit:function(t){return new Date(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes()).getTime()}},hour:{name:"hour",level:20,maxItemNumber:function(t){switch(m.options.domain){case"day":return 24;case"week":return 168;case"month":return 24*(m.options.domainDynamicDimension?m.getDayCountInMonth(t):31)}},defaultRowNumber:6,defaultColumnNumber:function(t){switch(m.options.domain){case"day":return 4;case"week":return 28;case"month":return m.options.domainDynamicDimension?m.getDayCountInMonth(t):31}},row:function(t){return m.getSubDomainRowNumber(t)},column:function(t){return m.getSubDomainColumnNumber(t)},position:{x:function(t){return"month"===m.options.domain?0<m.options.colLimit||0<m.options.rowLimit?Math.floor((t.getHours()+24*(t.getDate()-1))/m._domainType.hour.row(t)):Math.floor(t.getHours()/m._domainType.hour.row(t))+4*(t.getDate()-1):"week"===m.options.domain?0<m.options.colLimit||0<m.options.rowLimit?Math.floor((t.getHours()+24*m.getWeekDay(t))/m._domainType.hour.row(t)):Math.floor(t.getHours()/m._domainType.hour.row(t))+4*m.getWeekDay(t):Math.floor(t.getHours()/m._domainType.hour.row(t))},y:function(t){var e=t.getHours();if(0<m.options.colLimit||0<m.options.rowLimit)switch(m.options.domain){case"month":e+=24*(t.getDate()-1);break;case"week":e+=24*m.getWeekDay(t)}return Math.floor(e%m._domainType.hour.row(t))}},format:{date:"%Hh, %A %B %-e, %Y",legend:"%H:00",connector:"at"},extractUnit:function(t){return new Date(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours()).getTime()}},day:{name:"day",level:30,maxItemNumber:function(t){switch(m.options.domain){case"week":return 7;case"month":return m.options.domainDynamicDimension?m.getDayCountInMonth(t):31;case"year":return m.options.domainDynamicDimension?m.getDayCountInYear(t):366}},defaultColumnNumber:function(t){switch(t=new Date(t),m.options.domain){case"week":return 1;case"month":return m.options.domainDynamicDimension&&!m.options.verticalOrientation?m.getWeekNumber(new Date(t.getFullYear(),t.getMonth()+1,0))-m.getWeekNumber(t)+1:6;case"year":return m.options.domainDynamicDimension?m.getWeekNumber(new Date(t.getFullYear(),11,31))-m.getWeekNumber(new Date(t.getFullYear(),0))+1:54}},defaultRowNumber:7,row:function(t){return m.getSubDomainRowNumber(t)},column:function(t){return m.getSubDomainColumnNumber(t)},position:{x:function(t){switch(m.options.domain){case"week":return Math.floor(m.getWeekDay(t)/m._domainType.day.row(t));case"month":return 0<m.options.colLimit||0<m.options.rowLimit?Math.floor((t.getDate()-1)/m._domainType.day.row(t)):m.getWeekNumber(t)-m.getWeekNumber(new Date(t.getFullYear(),t.getMonth()));case"year":return 0<m.options.colLimit||0<m.options.rowLimit?Math.floor((m.getDayOfYear(t)-1)/m._domainType.day.row(t)):m.getWeekNumber(t)}},y:function(t){var e=m.getWeekDay(t);if(0<m.options.colLimit||0<m.options.rowLimit)switch(m.options.domain){case"year":e=m.getDayOfYear(t)-1;break;case"week":e=m.getWeekDay(t);break;case"month":e=t.getDate()-1}return Math.floor(e%m._domainType.day.row(t))}},format:{date:"%A %B %-e, %Y",legend:"%e %b",connector:"on"},extractUnit:function(t){return new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime()}},week:{name:"week",level:40,maxItemNumber:54,defaultColumnNumber:function(t){switch(t=new Date(t),m.options.domain){case"year":return m._domainType.week.maxItemNumber;case"month":return m.options.domainDynamicDimension?m.getWeekNumber(new Date(t.getFullYear(),t.getMonth()+1,0))-m.getWeekNumber(t):5}},defaultRowNumber:1,row:function(t){return m.getSubDomainRowNumber(t)},column:function(t){return m.getSubDomainColumnNumber(t)},position:{x:function(t){switch(m.options.domain){case"year":return Math.floor(m.getWeekNumber(t)/m._domainType.week.row(t));case"month":return Math.floor(m.getMonthWeekNumber(t)/m._domainType.week.row(t))}},y:function(t){return m.getWeekNumber(t)%m._domainType.week.row(t)}},format:{date:"%B Week #%W",legend:"%B Week #%W",connector:"in"},extractUnit:function(t){var t=new Date(t.getFullYear(),t.getMonth(),t.getDate()),e=t.getDay()-(m.options.weekStartOnMonday?1:0);return e<0&&(e=6),t.setDate(t.getDate()-e),t.getTime()}},month:{name:"month",level:50,maxItemNumber:12,defaultColumnNumber:12,defaultRowNumber:1,row:function(){return m.getSubDomainRowNumber()},column:function(){return m.getSubDomainColumnNumber()},position:{x:function(t){return Math.floor(t.getMonth()/m._domainType.month.row(t))},y:function(t){return t.getMonth()%m._domainType.month.row(t)}},format:{date:"%B %Y",legend:"%B",connector:"in"},extractUnit:function(t){return new Date(t.getFullYear(),t.getMonth()).getTime()}},year:{name:"year",level:60,row:function(){return m.options.rowLimit||1},column:function(){return m.options.colLimit||1},position:{x:function(){return 1},y:function(){return 1}},format:{date:"%Y",legend:"%Y",connector:"in"},extractUnit:function(t){return new Date(t.getFullYear()).getTime()}}},this._domainType)this._domainType.hasOwnProperty(t)&&(e=this._domainType[t],this._domainType["x_"+t]={name:"x_"+t,level:e.type,maxItemNumber:e.maxItemNumber,defaultRowNumber:e.defaultRowNumber,defaultColumnNumber:e.defaultColumnNumber,row:e.column,column:e.row,position:{x:e.position.y,y:e.position.x},format:e.format,extractUnit:e.extractUnit});function c(t,e){t=m.options.cellSize*m._domainType[m.options.subDomain].column(t)+m.options.cellPadding*m._domainType[m.options.subDomain].column(t);return 2===arguments.length&&!0===e?t+(m.domainHorizontalLabelWidth+m.options.domainGutter+m.options.domainMargin[1]+m.options.domainMargin[3]):t}function h(t,e){t=m.options.cellSize*m._domainType[m.options.subDomain].row(t)+m.options.cellPadding*m._domainType[m.options.subDomain].row(t);return 2===arguments.length&&!0===e&&(t+=m.options.domainGutter+m.domainVerticalLabelHeight+m.options.domainMargin[0]+m.options.domainMargin[2]),t}this.lastInsertedSvg=null,this._completed=!1,this._domains=new 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.tooltip=null,this._maxDomainReached=!1,this._minDomainReached=!1,this.domainPosition=new DomainPosition,this.Legend=null,this.legendScale=null,this.DSTDomain=[],this._init=function(){var t;return m.getDomain(m.options.start).map(function(t){return t.getTime()}).map(function(t){m._domains.set(t,m.getSubDomain(t).map(function(t){return{t:m._domainType[m.options.subDomain].extractUnit(t),v:null}}))}),m.root=d3.select(m.options.itemSelector).append("svg").attr("class","cal-heatmap-container"),m.tooltip=d3.select(m.options.itemSelector).attr("style",function(){var t=d3.select(m.options.itemSelector).attr("style");return(null!==t?t:"")+"position:relative;"}).append("div").attr("class","ch-tooltip"),m.root.attr("x",0).attr("y",0).append("svg").attr("class","graph"),m.Legend=new Legend(m),m.options.paintOnLoad&&(m.verticalDomainLabel="top"===m.options.label.position||"bottom"===m.options.label.position,m.domainVerticalLabelHeight=null===m.options.label.height?Math.max(25,2*m.options.cellSize):m.options.label.height,m.domainHorizontalLabelWidth=0,""===m.options.domainLabelFormat&&null===m.options.label.height&&(m.domainVerticalLabelHeight=0),m.verticalDomainLabel||(m.domainVerticalLabelHeight=0,m.domainHorizontalLabelWidth=m.options.label.width),m.paint(),!1!==m.options.nextSelector&&d3.select(m.options.nextSelector).on("click."+m.options.itemNamespace,function(t){return t.preventDefault(),m.loadNextDomain(1)}),!1!==m.options.previousSelector&&d3.select(m.options.previousSelector).on("click."+m.options.itemNamespace,function(t){return t.preventDefault(),m.loadPreviousDomain(1)}),m.Legend.redraw(m.graphDim.width-m.options.domainGutter-m.options.cellPadding),m.afterLoad(),t=m.getDomainKeys(),m.options.loadOnInit?m.getDatas(m.options.data,new Date(t[0]),m.getSubDomain(t[t.length-1]).pop(),function(){m.fill(),m.onComplete()}):m.onComplete(),m.checkIfMinDomainIsReached(t[0]),m.checkIfMaxDomainIsReached(m.getNextDomain().getTime())),!0},this.paint=function(a){var o=m.options,t=(0===arguments.length&&(a=!1),m.root.select(".graph").selectAll(".graph-domain").data(function(){var t=m.getDomainKeys();return a===m.NAVIGATE_LEFT?t.reverse():t},function(t){return t})),r=0,s=0,e=t.enter().append("svg").attr("width",function(t){return c(t,!0)}).attr("height",function(t){return h(t,!0)}).attr("x",function(t){return o.verticalOrientation?(m.graphDim.width=Math.max(m.graphDim.width,c(t,!0)),0):n(t,m.graphDim,"width",c(t,!0))}).attr("y",function(t){return o.verticalOrientation?n(t,m.graphDim,"height",h(t,!0)):(m.graphDim.height=Math.max(m.graphDim.height,h(t,!0)),0)}).attr("class",function(t){var e="graph-domain",n=new Date(t);switch(o.domain){case"hour":e+=" h_"+n.getHours();case"day":e+=" d_"+n.getDate()+" dy_"+n.getDay();case"week":e+=" w_"+m.getWeekNumber(n);case"month":e+=" m_"+(n.getMonth()+1);case"year":e+=" y_"+n.getFullYear()}return e});function n(t,e,n,i){var o=0;switch(a){case!1:return o=e[n],e[n]+=i,m.domainPosition.setPosition(t,o),o;case m.NAVIGATE_RIGHT:return m.domainPosition.setPosition(t,e[n]),r=i,s=m.domainPosition.getPositionFromIndex(1),m.domainPosition.shiftRightBy(s),e[n];case m.NAVIGATE_LEFT:return r=-(o=-i),s=e[n]-m.domainPosition.getLast(),m.domainPosition.setPosition(t,o),m.domainPosition.shiftLeftBy(r),o}}(m.lastInsertedSvg=e).append("rect").attr("width",function(t){return c(t,!0)-o.domainGutter-o.cellPadding}).attr("height",function(t){return h(t,!0)-o.domainGutter-o.cellPadding}).attr("class","domain-background");var i=e.append("svg").attr("x",function(){return"left"===o.label.position?m.domainHorizontalLabelWidth+o.domainMargin[3]:o.domainMargin[3]}).attr("y",function(){return"top"===o.label.position?m.domainVerticalLabelHeight+o.domainMargin[0]:o.domainMargin[0]}).attr("class","graph-subdomain-group").selectAll("g").data(function(t){return m._domains.get(t)}).enter().append("g");i.append("rect").attr("class",function(t){return"graph-rect"+m.getHighlightClassName(t.t)+(null!==o.onClick?" hover_cursor":"")}).attr("width",o.cellSize).attr("height",o.cellSize).attr("x",function(t){return m.positionSubDomainX(t.t)}).attr("y",function(t){return m.positionSubDomainY(t.t)}).on("click",function(t,e){if(null!==o.onClick)return m.onClick(new Date(e.t),e.v)}).call(function(t){0<o.cellRadius&&t.attr("rx",o.cellRadius).attr("ry",o.cellRadius),null!==m.legendScale&&null!==o.legendColors&&o.legendColors.hasOwnProperty("base")&&t.attr("fill",o.legendColors.base),o.tooltip&&(t.on("mouseover",function(t,e){var n=this.parentNode.parentNode,i=(m.tooltip.html(m.getSubDomainTitle(e)).attr("style","display: block;"),m.positionSubDomainX(e.t)-m.tooltip.node().offsetWidth/2+o.cellSize/2),e=m.positionSubDomainY(e.t)-m.tooltip.node().offsetHeight-o.cellSize/2;i+=parseInt(n.getAttribute("x"),10),e+=parseInt(n.getAttribute("y"),10),i+=parseInt(m.root.select(".graph").attr("x"),10),e+=parseInt(m.root.select(".graph").attr("y"),10),i+=parseInt(n.parentNode.getAttribute("x"),10),e+=parseInt(n.parentNode.getAttribute("y"),10),m.tooltip.attr("style","display: block; left: "+i+"px; top: "+e+"px;")}),t.on("mouseout",function(){m.tooltip.attr("style","display:none").html("")}))}),o.tooltip||i.append("title").text(function(t){return m.formatDate(new Date(t.t),o.subDomainDateFormat)}),""!==o.domainLabelFormat&&e.append("text").attr("class","graph-label").attr("y",function(t){var e=o.domainMargin[0];switch(o.label.position){case"top":e+=m.domainVerticalLabelHeight/2;break;case"bottom":e+=h(t)+m.domainVerticalLabelHeight/2}return e+o.label.offset.y*("right"===o.label.rotate&&"right"===o.label.position||"left"===o.label.rotate&&"left"===o.label.position?-1:1)}).attr("x",function(t){var e=o.domainMargin[3];switch(o.label.position){case"right":e+=c(t);break;case"bottom":case"top":e+=c(t)/2}return"right"===o.label.align?e+m.domainHorizontalLabelWidth-o.label.offset.x*("right"===o.label.rotate?-1:1):e+o.label.offset.x}).attr("text-anchor",function(){switch(o.label.align){case"start":case"left":return"start";case"end":case"right":return"end";default:return"middle"}}).attr("dominant-baseline",function(){return m.verticalDomainLabel?"middle":"top"}).text(function(t){return m.formatDate(new Date(t),o.domainLabelFormat)}).call(function(t){switch(o.label.rotate){case"right":t.attr("transform",function(t){var e="rotate(90), ";switch(o.label.position){case"right":e+="translate(-"+c(t)+" , -"+c(t)+")";break;case"left":e+="translate(0, -"+m.domainHorizontalLabelWidth+")"}return e});break;case"left":t.attr("transform",function(t){var e="rotate(270), ";switch(o.label.position){case"right":e+="translate(-"+(c(t)+m.domainHorizontalLabelWidth)+" , "+c(t)+")";break;case"left":e+="translate(-"+m.domainHorizontalLabelWidth+" , "+m.domainHorizontalLabelWidth+")"}return e})}}),null!==o.subDomainTextFormat&&i.append("text").attr("class",function(t){return"subdomain-text"+m.getHighlightClassName(t.t)}).attr("x",function(t){return m.positionSubDomainX(t.t)+o.cellSize/2}).attr("y",function(t){return m.positionSubDomainY(t.t)+o.cellSize/2}).attr("text-anchor","middle").attr("dominant-baseline","central").text(function(t){return m.formatDate(new Date(t.t),o.subDomainTextFormat)}),t=m.root.select(".graph").selectAll(".graph-domain").data(function(){var t=m.getDomainKeys();return a===m.NAVIGATE_LEFT?t.reverse():t},function(t){return t}),!1!==a&&t.transition().duration(o.animationDuration).attr("x",function(t){return o.verticalOrientation?0:m.domainPosition.getPosition(t)}).attr("y",function(t){return o.verticalOrientation?m.domainPosition.getPosition(t):0});var l=m.graphDim.width,u=m.graphDim.height;o.verticalOrientation?m.graphDim.height+=r-s:m.graphDim.width+=r-s,t.exit().transition().duration(o.animationDuration).attr("x",function(t){if(o.verticalOrientation)return 0;switch(a){case m.NAVIGATE_LEFT:return Math.min(m.graphDim.width,l);case m.NAVIGATE_RIGHT:return-c(t,!0)}}).attr("y",function(t){if(!o.verticalOrientation)return 0;switch(a){case m.NAVIGATE_LEFT:return Math.min(m.graphDim.height,u);case m.NAVIGATE_RIGHT:return-h(t,!0)}}).remove(),m.resize()}},DomainPosition=(CalHeatMap.prototype={init:function(t){"use strict";var e=this,n=e.options=mergeRecursive(e.options,t);if(!e._domainType.hasOwnProperty(n.domain)||"min"===n.domain||"x_"===n.domain.substring(0,2))throw new Error("The domain '"+n.domain+"' is not valid");if(!e._domainType.hasOwnProperty(n.subDomain)||"year"===n.subDomain)throw new Error("The subDomain '"+n.subDomain+"' is not valid");if(e._domainType[n.domain].level<=e._domainType[n.subDomain].level)throw new Error("'"+n.subDomain+"' is not a valid subDomain to '"+n.domain+"'");if(r(n.itemSelector,!1,"itemSelector"),-1===e.allowedDataType.indexOf(n.dataType))throw new Error("The data type '"+n.dataType+"' is not valid data type");if(d3.select(n.itemSelector).empty())throw new Error("The node '"+n.itemSelector+"' specified in itemSelector does not exist");try{r(n.nextSelector,!0,"nextSelector"),r(n.previousSelector,!0,"previousSelector")}catch(t){return console.log(t.message),!1}t.hasOwnProperty("subDomain")||(this.options.subDomain=function(t){switch(t){case"year":return"month";case"month":case"week":return"day";case"day":return"hour";default:return"min"}}(t.domain)),"string"==typeof n.itemNamespace&&""!==n.itemNamespace||(console.log("itemNamespace can not be empty, falling back to cal-heatmap"),n.itemNamespace="cal-heatmap");var i,o,a=["data","onComplete","onClick","afterLoad","afterLoadData","afterLoadPreviousDomain","afterLoadNextDomain","afterUpdate"];for(i in a)t.hasOwnProperty(a[i])&&(n[a[i]]=t[a[i]]);if(n.subDomainDateFormat="string"==typeof n.subDomainDateFormat||"function"==typeof n.subDomainDateFormat?n.subDomainDateFormat:this._domainType[n.subDomain].format.date,n.domainLabelFormat="string"==typeof n.domainLabelFormat||"function"==typeof n.domainLabelFormat?n.domainLabelFormat:this._domainType[n.domain].format.legend,n.subDomainTextFormat="string"==typeof n.subDomainTextFormat&&""!==n.subDomainTextFormat||"function"==typeof n.subDomainTextFormat?n.subDomainTextFormat:null,n.domainMargin=s(n.domainMargin),n.legendMargin=s(n.legendMargin),n.highlight=e.expandDateSetting(n.highlight),n.itemName=function(t){if("string"==typeof t)return[t,t+(""!==t?"s":"")];if(Array.isArray(t))return 1===t.length?[t[0],t[0]+"s"]:2<t.length?t.slice(0,2):t;return["item","items"]}(n.itemName),n.colLimit=0<(o=n.colLimit)?o:null,n.rowLimit=function(t){if(0<t&&0<n.colLimit)return console.log("colLimit and rowLimit are mutually exclusive, rowLimit will be ignored"),null;return 0<t?t:null}(n.rowLimit),!t.hasOwnProperty("legendMargin"))switch(n.legendVerticalPosition){case"top":n.legendMargin[2]=e.DEFAULT_LEGEND_MARGIN;break;case"bottom":n.legendMargin[0]=e.DEFAULT_LEGEND_MARGIN;break;case"middle":case"center":n.legendMargin["right"===n.legendHorizontalPosition?3:1]=e.DEFAULT_LEGEND_MARGIN}if(!t.hasOwnProperty("label")||t.hasOwnProperty("label")&&!t.label.hasOwnProperty("align")){switch(n.label.position){case"left":n.label.align="right";break;case"right":n.label.align="left";break;default:n.label.align="center"}"left"===n.label.rotate?n.label.align="right":"right"===n.label.rotate&&(n.label.align="left")}function r(t,e,n){if(!(e&&!1===t||t instanceof Element||"string"==typeof t)||""===t)throw new Error("The "+n+" is not valid")}function s(t){switch("number"==typeof t&&(t=[t]),Array.isArray(t)||(console.log("Margin only takes an integer or an array of integers"),t=[0]),t.length){case 1:return[t[0],t[0],t[0],t[0]];case 2:return[t[0],t[1],t[0],t[1]];case 3:return[t[0],t[1],t[2],t[1]];case 4:return t;default:return t.slice(0,4)}}return t.hasOwnProperty("label")&&(!t.hasOwnProperty("label")||t.label.hasOwnProperty("offset"))||"left"!==n.label.position&&"right"!==n.label.position||(n.label.offset={x:10,y:15}),this._init()},expandDateSetting:function(t){"use strict";return(t=Array.isArray(t)?t:[t]).map(function(t){return"now"===t?new Date:t instanceof Date&&t}).filter(function(t){return!1!==t})},fill:function(t){"use strict";var i=this,o=i.options,t=(t=0===arguments.length?i.root.selectAll(".graph-domain"):t).selectAll("svg").selectAll("g").data(function(t){return i._domains.get(t)});t.transition().duration(o.animationDuration).select("rect").attr("class",function(t){var e=i.getHighlightClassName(t.t).trim().split(" "),n=i.dateIsLessThan(t.t,new Date);return null!==i.legendScale&&(null!==t.v||!o.hasOwnProperty("considerMissingDataAsZero")||o.considerMissingDataAsZero||o.legendColors.hasOwnProperty("base"))||e.push("graph-rect"),null!==t.v?e.push(i.Legend.getClass(t.v,null===i.legendScale)):o.considerMissingDataAsZero&&n&&e.push(i.Legend.getClass(0,null===i.legendScale)),null!==o.onClick&&e.push("hover_cursor"),e.join(" ")}).call(function(t){if(null===i.legendScale)return!1;t.attr("fill",function(t){return null===t.v&&o.hasOwnProperty("considerMissingDataAsZero")&&!o.considerMissingDataAsZero&&o.legendColors.hasOwnProperty("base")?o.legendColors.base:null!==o.legendColors&&o.legendColors.hasOwnProperty("empty")&&(0===t.v||null===t.v&&o.hasOwnProperty("considerMissingDataAsZero")&&o.considerMissingDataAsZero)?o.legendColors.empty:t.v<0&&0<o.legend[0]&&null!==o.legendColors&&o.legendColors.hasOwnProperty("overflow")?o.legendColors.overflow:i.legendScale(Math.min(t.v,o.legend[o.legend.length-1]))})}),t.transition().duration(o.animationDuration).select("title").text(function(t){return i.getSubDomainTitle(t)}),t.transition().duration(o.animationDuration).select("text").attr("class",function(t){return"subdomain-text"+i.getHighlightClassName(t.t)}).call(function(t){"function"==typeof o.subDomainTextFormat&&t.text(function(t){return o.subDomainTextFormat(t.t,t.v)})})},formatStringWithObject:function(t,e){"use strict";for(var n in e){var i;e.hasOwnProperty(n)&&(i=new RegExp("\\{"+n+"\\}","gi"),t=t.replace(i,e[n]))}return t},triggerEvent:function(t,e,n){"use strict";return!!(3===arguments.length&&n||null===this.options[t])||("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){"use strict";return this.triggerEvent("onClick",[t,e])},afterLoad:function(){"use strict";return this.triggerEvent("afterLoad")},onComplete:function(){"use strict";var t=this.triggerEvent("onComplete",[],this._completed);return this._completed=!0,t},afterLoadPreviousDomain:function(e){"use strict";var n=this;return this.triggerEvent("afterLoadPreviousDomain",function(){var t=n.getSubDomain(e);return[t.shift(),t.pop()]})},afterLoadNextDomain:function(e){"use strict";var n=this;return this.triggerEvent("afterLoadNextDomain",function(){var t=n.getSubDomain(e);return[t.shift(),t.pop()]})},onMinDomainReached:function(t){"use strict";return this._minDomainReached=t,this.triggerEvent("onMinDomainReached",[t])},onMaxDomainReached:function(t){"use strict";return this._maxDomainReached=t,this.triggerEvent("onMaxDomainReached",[t])},checkIfMinDomainIsReached:function(t,e){"use strict";this.minDomainIsReached(t)&&this.onMinDomainReached(!0),2===arguments.length&&this._maxDomainReached&&!this.maxDomainIsReached(e)&&this.onMaxDomainReached(!1)},checkIfMaxDomainIsReached:function(t,e){"use strict";this.maxDomainIsReached(t)&&this.onMaxDomainReached(!0),2===arguments.length&&this._minDomainReached&&!this.minDomainIsReached(e)&&this.onMinDomainReached(!1)},afterUpdate:function(){"use strict";return this.triggerEvent("afterUpdate")},formatNumber:d3.format(",d"),formatDate:function(t,e){"use strict";return("function"==typeof(e=arguments.length<2?"title":e)?e:d3.timeFormat(e))(t)},getSubDomainTitle:function(t){"use strict";var e;return null!==t.v||this.options.considerMissingDataAsZero?(null===(e=t.v)&&this.options.considerMissingDataAsZero&&(e=0),this.formatStringWithObject(this.options.subDomainTitleFormat.filled,{count:this.formatNumber(e),name:this.options.itemName[1!==e?1:0],connector:this._domainType[this.options.subDomain].format.connector,date:this.formatDate(new Date(t.t),this.options.subDomainDateFormat)})):this.formatStringWithObject(this.options.subDomainTitleFormat.empty,{date:this.formatDate(new Date(t.t),this.options.subDomainDateFormat)})},loadNextDomain:function(t){"use strict";if(this._maxDomainReached||0===t)return!1;t=this.loadNewDomains(this.NAVIGATE_RIGHT,this.getDomain(this.getNextDomain(),t));return this.afterLoadNextDomain(t.end),this.checkIfMaxDomainIsReached(this.getNextDomain().getTime(),t.start),!0},loadPreviousDomain:function(t){"use strict";if(this._minDomainReached||0===t)return!1;t=this.loadNewDomains(this.NAVIGATE_LEFT,this.getDomain(this.getDomainKeys()[0],-t).reverse());return this.afterLoadPreviousDomain(t.start),this.checkIfMinDomainIsReached(t.start,t.end),!0},loadNewDomains:function(t,e){"use strict";var n=this,i=t===this.NAVIGATE_LEFT,o=-1,a=e.length,r=this.getDomainKeys();function s(t){return{t:n._domainType[n.options.subDomain].extractUnit(t),v:null}}for(;++o<a;){if(i&&this.minDomainIsReached(e[o])){e=e.slice(0,o+1);break}if(!i&&this.maxDomainIsReached(e[o])){e=e.slice(0,o);break}}for(o=0,a=(e=e.slice(-this.options.range)).length;o<a;o++)this._domains.set(e[o].getTime(),this.getSubDomain(e[o]).map(s)),this._domains.delete(i?r.pop():r.shift());return r=this.getDomainKeys(),i&&(e=e.reverse()),this.paint(t),this.getDatas(this.options.data,e[0],this.getSubDomain(e[e.length-1]).pop(),function(){n.fill(n.lastInsertedSvg)}),{start:e[i?0:1],end:r[r.length-1]}},maxDomainIsReached:function(t){"use strict";return null!==this.options.maxDate&&this.options.maxDate.getTime()<t},minDomainIsReached:function(t){"use strict";return null!==this.options.minDate&&this.options.minDate.getTime()>=t},getDomainKeys:function(){"use strict";return Array.from(this._domains.keys()).map(function(t){return parseInt(t,10)}).sort(function(t,e){return t-e})},positionSubDomainX:function(t){"use strict";t=this._domainType[this.options.subDomain].position.x(new Date(t));return t*this.options.cellSize+t*this.options.cellPadding},positionSubDomainY:function(t){"use strict";t=this._domainType[this.options.subDomain].position.y(new Date(t));return t*this.options.cellSize+t*this.options.cellPadding},getSubDomainColumnNumber:function(t){"use strict";if(0<this.options.rowLimit)return"function"==typeof(e=this._domainType[this.options.subDomain].maxItemNumber)&&(e=e(t)),Math.ceil(e/this.options.rowLimit);var e=this._domainType[this.options.subDomain].defaultColumnNumber;return"function"==typeof e&&(e=e(t)),this.options.colLimit||e},getSubDomainRowNumber:function(t){"use strict";if(0<this.options.colLimit)return"function"==typeof(e=this._domainType[this.options.subDomain].maxItemNumber)&&(e=e(t)),Math.ceil(e/this.options.colLimit);var e=this._domainType[this.options.subDomain].defaultRowNumber;return"function"==typeof e&&(e=e(t)),this.options.rowLimit||e},getHighlightClassName:function(t){"use strict";if(t=new Date(t),0<this.options.highlight.length)for(var e in this.options.highlight)if(this.dateIsEqual(this.options.highlight[e],t))return this.isNow(this.options.highlight[e])?" highlight-now":" highlight";return""},isNow:function(t){"use strict";return this.dateIsEqual(t,new Date)},dateIsEqual:function(t,e){"use strict";switch(t instanceof Date||(t=new Date(t)),e instanceof Date||(e=new Date(e)),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":return t.getFullYear()===e.getFullYear()&&this.getWeekNumber(t)===this.getWeekNumber(e);case"x_month":case"month":return t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth();default:return!1}},dateIsLessThan:function(t,e){"use strict";function n(t,e){switch(e){case"x_min":case"min":return new Date(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes()).getTime();case"x_hour":case"hour":return new Date(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours()).getTime();case"x_day":case"day":return new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime();case"x_week":case"week":case"x_month":case"month":return new Date(t.getFullYear(),t.getMonth()).getTime();default:return t.getTime()}}return t instanceof Date||(t=new Date(t)),e instanceof Date||(e=new Date(e)),n(t,this.options.subDomain)<n(e,this.options.subDomain)},getDayOfYear:d3.timeFormat("%j"),getWeekNumber:function(t){"use strict";return(!0===this.options.weekStartOnMonday?d3.timeFormat("%W"):d3.timeFormat("%U"))(t)},getMonthWeekNumber:function(t){"use strict";"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){"use strict";"number"==typeof t&&new Date(t)},getDayCountInMonth:function(t){"use strict";return this.getEndOfMonth(t).getDate()},getDayCountInYear:function(t){"use strict";return"number"==typeof t&&(t=new Date(t)),1===new Date(t.getFullYear(),1,29).getMonth()?366:365},getWeekDay:function(t){"use strict";return!1===this.options.weekStartOnMonday?t.getDay():0===t.getDay()?6:t.getDay()-1},getEndOfMonth:function(t){"use strict";return"number"==typeof t&&(t=new Date(t)),new Date(t.getFullYear(),t.getMonth()+1,0)},jumpDate:function(t,e,n){"use strict";var i=new Date(t);switch(n){case"hour":i.setHours(i.getHours()+e);break;case"day":i.setHours(i.getHours()+24*e);break;case"week":i.setHours(i.getHours()+24*e*7);break;case"month":i.setMonth(i.getMonth()+e);break;case"year":i.setFullYear(i.getFullYear()+e)}return new Date(i)},getMinuteDomain:function(t,e){"use strict";var t=new Date(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours()),n=null,n=e instanceof Date?new Date(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours()):new Date(+t+1e3*e*60);return d3.timeMinutes(Math.min(t,n),Math.max(t,n))},getHourDomain:function(t,e){"use strict";for(var t=new Date(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours()),n=null,i=(e instanceof Date?n=new Date(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours()):(n=new Date(t)).setHours(n.getHours()+e),d3.timeHours(Math.min(t,n),Math.max(t,n))),o=0,a=i.length,o=0;o<a;o++)if(0<o&&i[o].getHours()===i[o-1].getHours()){this.DSTDomain.push(i[o].getTime()),i.splice(o,1);break}return"number"==typeof e&&i.length>Math.abs(e)&&i.splice(i.length-1,1),i},getDayDomain:function(t,e){"use strict";var t=new Date(t.getFullYear(),t.getMonth(),t.getDate()),n=null,n=e instanceof Date?new Date(e.getFullYear(),e.getMonth(),e.getDate()):(n=new Date(t),new Date(n.setDate(n.getDate()+parseInt(e,10))));return d3.timeDays(Math.min(t,n),Math.max(t,n))},getWeekDomain:function(t,e){"use strict";!1===this.options.weekStartOnMonday?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())).setDate(n.getDate()-6):n=new Date(t.getFullYear(),t.getMonth(),t.getDate()-t.getDay()+1);var n,t=new Date(n),i=e;return"object"!=typeof e&&(i=new Date(t.setDate(t.getDate()+7*e))),!0===this.options.weekStartOnMonday?d3.timeMondays(Math.min(n,i),Math.max(n,i)):d3.timeSundays(Math.min(n,i),Math.max(n,i))},getMonthDomain:function(t,e){"use strict";var t=new Date(t.getFullYear(),t.getMonth()),n=null,n=e instanceof Date?new Date(e.getFullYear(),e.getMonth()):(n=new Date(t)).setMonth(n.getMonth()+e);return d3.timeMonths(Math.min(t,n),Math.max(t,n))},getYearDomain:function(t,e){"use strict";var n=new Date(t.getFullYear(),0),i=null,i=e instanceof Date?new Date(e.getFullYear(),0):new Date(t.getFullYear()+e,0);return d3.timeYears(Math.min(n,i),Math.max(n,i))},getDomain:function(t,e){"use strict";switch("number"==typeof t&&(t=new Date(t)),arguments.length<2&&(e=this.options.range),this.options.domain){case"hour":var n=this.getHourDomain(t,e);return"number"==typeof e&&n.length<e&&(0<e?n.push(this.getHourDomain(n[n.length-1],2)[1]):n.shift(this.getHourDomain(n[0],-2)[0])),n;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){"use strict";"number"==typeof t&&(t=new Date(t));var e,n,i,o,a=this;switch(this.options.subDomain){case"x_min":case"min":return this.getMinuteDomain(t,function(t){switch(t){case"hour":return 60;case"day":return 1440;case"week":return 10080}}(this.options.domain));case"x_hour":case"hour":return this.getHourDomain(t,function(t,e){switch(e){case"day":return 24;case"week":return 168;case"month":return 24*a.getDayCountInMonth(t)}}(t,this.options.domain));case"x_day":case"day":return this.getDayDomain(t,function(t,e){switch(e){case"year":return a.getDayCountInYear(t);case"month":return a.getDayCountInMonth(t);case"week":return 7}}(t,this.options.domain));case"x_week":case"week":return this.getWeekDomain(t,(e=t,"month"===(n=this.options.domain)?(i=new Date(e.getFullYear(),e.getMonth()+1,0),(i=a.getWeekNumber(i))<(o=a.getWeekNumber(new Date(e.getFullYear(),e.getMonth())))&&(o=0,i++),i-o+1):"year"===n?a.getWeekNumber(new Date(e.getFullYear(),11,31)):void 0));case"x_month":case"month":return this.getMonthDomain(t,12)}},getNextDomain:function(t){"use strict";return 0===arguments.length&&(t=1),this.getDomain(this.jumpDate(this.getDomainKeys().pop(),t,this.options.domain),1)[0]},getPreviousDomain:function(t){"use strict";return 0===arguments.length&&(t=1),this.getDomain(this.jumpDate(this.getDomainKeys().shift(),-t,this.options.domain),1)[0]},getDatas:function(t,e,n,i,o,a){"use strict";function r(t){!1!==o?"function"==typeof o?t=o(t):"function"==typeof s.options.afterLoadData?t=s.options.afterLoadData(t):console.log("Provided callback for afterLoadData is not a function."):"csv"!==s.options.dataType&&"tsv"!==s.options.dataType||(t=this.interpretCSV(t)),s.parseDatas(t,a,e,n),"function"==typeof i&&i()}var s=this;arguments.length<5&&(o=!0),arguments.length<6&&(a=this.APPEND_ON_UPDATE);switch(typeof t){case"string":if(""===t)return r({}),!0;var l=this.parseURI(t,e,n),u={method:"GET"};if(null!==s.options.dataPostPayload&&(u.method="POST"),null!==s.options.dataPostPayload&&(u.body=this.parseURI(s.options.dataPostPayload,e,n)),null!==s.options.dataRequestHeaders){var m,c=new Headers;for(m in s.options.dataRequestHeaders)s.options.dataRequestHeaders.hasOwnProperty(m)&&c.append(m,s.options.dataRequestHeaders[m]);u.headers=c}var h=null;switch(this.options.dataType){case"json":h=d3.json(l,u);break;case"csv":h=d3.csv(l,u);break;case"tsv":h=d3.dsv("\t",l,u);break;case"txt":h=d3.text(l,u)}return h.then(r),!1;case"object":if(t===Object(t))return r(t),!1;default:return r({}),!0}},parseDatas:function(t,e,n,i){"use strict";e===this.RESET_ALL_ON_UPDATE&&this._domains.forEach(function(t){t.forEach(function(t,e,n){n[e].v=null})});function o(t){return t.t}var a,r={};for(a in t){var s,l=new Date(1e3*a),u=this.getDomain(l)[0].getTime();0<=this.DSTDomain.indexOf(u)&&this._domains.has(u-36e5)&&(u-=36e5),!isNaN(a)&&t.hasOwnProperty(a)&&this._domains.has(u)&&+n<=u&&u<+i&&(s=this._domains.get(u),r.hasOwnProperty(u)||(r[u]=s.map(o)),u=r[u].indexOf(this._domainType[this.options.subDomain].extractUnit(l)),e===this.RESET_SINGLE_ON_UPDATE||isNaN(s[u].v)?s[u].v=t[a]:s[u].v+=t[a])}},parseURI:function(t,e,n){"use strict";return t=(t=(t=(t=t.replace(/\{\{t:start\}\}/g,e.getTime()/1e3)).replace(/\{\{t:end\}\}/g,n.getTime()/1e3)).replace(/\{\{d:start\}\}/g,e.toISOString())).replace(/\{\{d:end\}\}/g,n.toISOString())},interpretCSV:function(t){"use strict";for(var e={},n=Object.keys(t[0]),i=0,o=t.length;i<o;i++)e[t[i][n[0]]]=+t[i][n[1]];return e},resize:function(){"use strict";var t=this,e=t.options,n=e.displayLegend?t.Legend.getDim("width")+e.legendMargin[1]+e.legendMargin[3]:0,i=e.displayLegend?t.Legend.getDim("height")+e.legendMargin[0]+e.legendMargin[2]:0,o=t.graphDim.width-e.domainGutter-e.cellPadding,a=t.graphDim.height-e.domainGutter-e.cellPadding;this.root.transition().duration(e.animationDuration).attr("width",function(){return"middle"===e.legendVerticalPosition||"center"===e.legendVerticalPosition?o+n:Math.max(o,n)}).attr("height",function(){return"middle"===e.legendVerticalPosition||"center"===e.legendVerticalPosition?Math.max(a,i):a+i}),this.root.select(".graph").transition().duration(e.animationDuration).attr("y",function(){return"top"===e.legendVerticalPosition?i:0}).attr("x",function(){return"middle"!==e.legendVerticalPosition&&"center"!==e.legendVerticalPosition||"left"!==e.legendHorizontalPosition?0:n})},next:function(t){"use strict";return this.loadNextDomain(t=0===arguments.length?1:t)},previous:function(t){"use strict";return this.loadPreviousDomain(t=0===arguments.length?1:t)},jumpTo:function(t,e){"use strict";arguments.length<2&&(e=!1);var n=this.getDomainKeys(),i=n[0],n=n[n.length-1];return t<i?this.loadPreviousDomain(this.getDomain(i,t).length):e?this.loadNextDomain(this.getDomain(i,t).length):n<t&&this.loadNextDomain(this.getDomain(n,t).length)},rewind:function(){"use strict";this.jumpTo(this.options.start,!0)},update:function(t,e,n){"use strict";0===arguments.length&&(t=this.options.data),arguments.length<2&&(e=!0),arguments.length<3&&(n=this.RESET_ALL_ON_UPDATE);var i=this.getDomainKeys(),o=this;this.getDatas(t,new Date(i[0]),this.getSubDomain(i[i.length-1]).pop(),function(){o.fill(),o.afterUpdate()},e,n)},setLegend:function(){"use strict";var t=this.options.legend.slice(0);1<=arguments.length&&Array.isArray(arguments[0])&&(this.options.legend=arguments[0]),2<=arguments.length&&(Array.isArray(arguments[1])&&2<=arguments[1].length?this.options.legendColors=[arguments[1][0],arguments[1][1]]:this.options.legendColors=arguments[1]),(0<arguments.length&&!arrayEquals(t,this.options.legend)||2<=arguments.length)&&(this.Legend.buildColors(),this.fill()),this.Legend.redraw(this.graphDim.width-this.options.domainGutter-this.options.cellPadding)},removeLegend:function(){"use strict";return!!this.options.displayLegend&&(this.options.displayLegend=!1,this.Legend.remove(),!0)},showLegend:function(){"use strict";return!this.options.displayLegend&&(this.options.displayLegend=!0,this.Legend.redraw(this.graphDim.width-this.options.domainGutter-this.options.cellPadding),!0)},highlight:function(t){"use strict";return 0<(this.options.highlight=this.expandDateSetting(t)).length&&(this.fill(),!0)},destroy:function(t){"use strict";return this.root.transition().duration(this.options.animationDuration).attr("width",0).attr("height",0).remove().each(function(){"function"==typeof t?t():void 0!==t&&console.log("Provided callback for destroy() is not a function.")}),null},getSVG:function(){"use strict";for(var i={".cal-heatmap-container":{},".graph":{},".graph-rect":{},"rect.highlight":{},"rect.now":{},"rect.highlight-now":{},"text.highlight":{},"text.now":{},"text.highlight-now":{},".domain-background":{},".graph-label":{},".subdomain-text":{},".q0":{},".qi":{}},t=1,e=this.options.legend.length+1;t<=e;t++)i[".q"+t]={};function n(t,e,n){-1!==r.indexOf(e)&&(i[t][e]=n)}var o,a=this.root,r=["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"];for(o in i)if(i.hasOwnProperty(o)){s=o;var s=a.select(s).node();if(null!==s)if("getComputedStyle"in window){var l=getComputedStyle(s,null);if(0!==l.length)for(var u=0;u<l.length;u++)n(o,l.item(u),l.getPropertyValue(l.item(u)));else for(var m in l)l.hasOwnProperty(m)&&n(o,m,l[m])}else if("currentStyle"in s){var c,h=s.currentStyle;for(c in h)n(o,c,h[c])}}var g,d='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><style type="text/css"><![CDATA[ ';for(g in i){for(var p in d+=g+" {\n",i[g])d+="\t"+p+":"+i[g][p]+";\n";d+="}\n"}return d=(d+="]]></style>")+(new XMLSerializer).serializeToString(this.root[0][0])+"</svg>"}},function(){"use strict";this.positions=new Map}),Legend=(DomainPosition.prototype.getPosition=function(t){"use strict";return this.positions.get(t)},DomainPosition.prototype.getPositionFromIndex=function(t){"use strict";var e=this.getKeys();return this.positions.get(e[t])},DomainPosition.prototype.getLast=function(){"use strict";var t=this.getKeys();return this.positions.get(t[t.length-1])},DomainPosition.prototype.setPosition=function(t,e){"use strict";this.positions.set(t,e)},DomainPosition.prototype.shiftRightBy=function(n){"use strict";var t=this.positions,i=this,t=(t.forEach(function(t,e){i.positions.set(e,t-n)}),this.getKeys());this.positions.delete(t[0])},DomainPosition.prototype.shiftLeftBy=function(n){"use strict";var t=this.positions,i=this,t=(t.forEach(function(t,e){i.positions.set(e,t+n)}),this.getKeys());this.positions.delete(t[t.length-1])},DomainPosition.prototype.getKeys=function(){"use strict";return Array.from(this.positions.keys()).sort(function(t,e){return parseInt(t,10)-parseInt(e,10)})},function(t){"use strict";this.calendar=t,this.computeDim(),null!==t.options.legendColors&&this.buildColors()});function mergeRecursive(e,n){"use strict";for(var i in n)try{n[i].constructor===Object?e[i]=mergeRecursive(e[i],n[i]):e[i]=n[i]}catch(t){e[i]=n[i]}return e}function arrayEquals(t,e){"use strict";if(!e||!t)return!1;if(t.length!==e.length)return!1;for(var n=0;n<t.length;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}Legend.prototype.computeDim=function(){"use strict";var t=this.calendar.options;this.dim={width:t.legendCellSize*(t.legend.length+1)+t.legendCellPadding*t.legend.length,height:t.legendCellSize}},Legend.prototype.remove=function(){"use strict";this.calendar.root.select(".graph-legend").remove(),this.calendar.resize()},Legend.prototype.redraw=function(t){"use strict";if(!this.calendar.options.displayLegend)return!1;var e=this,n=this.calendar,i=n.root,o=n.options,a=(this.computeDim(),o.legend.slice(0)),r=(a.push(a[a.length-1]+1),n.root.select(".graph-legend"));function s(t){t.attr("width",o.legendCellSize).attr("height",o.legendCellSize).attr("x",function(t,e){return e*(o.legendCellSize+o.legendCellPadding)})}function l(){switch(o.legendHorizontalPosition){case"right":return"center"===o.legendVerticalPosition||"middle"===o.legendVerticalPosition?t+o.legendMargin[3]:t-e.getDim("width")-o.legendMargin[1];case"middle":case"center":return Math.round(t/2-e.getDim("width")/2);default:return o.legendMargin[3]}}function u(){return"bottom"===o.legendVerticalPosition?n.graphDim.height+o.legendMargin[0]-o.domainGutter-o.cellPadding:o.legendMargin[0]}(r=r.empty()?((i="top"===o.legendVerticalPosition?i.insert("svg",".graph"):i.append("svg")).attr("x",l()).attr("y",u()),i.attr("class","graph-legend").attr("height",e.getDim("height")).attr("width",e.getDim("width")).append("g").selectAll().data(a)):(i=r).select("g").selectAll("rect").data(a)).enter().append("rect").call(s).attr("class",function(t){return n.Legend.getClass(t,null===n.legendScale)}).attr("fill-opacity",0).call(function(t){null!==n.legendScale&&null!==o.legendColors&&o.legendColors.hasOwnProperty("base")&&t.attr("fill",o.legendColors.base)}).append("title"),r.exit().transition().duration(o.animationDuration).attr("fill-opacity",0).remove(),r.transition().delay(function(t,e){return o.animationDuration*e/10}).call(s).attr("fill-opacity",1).call(function(t){t.attr("fill",function(t,e){return null===n.legendScale?"":0===e?n.legendScale(t-1):n.legendScale(o.legend[e-1])}),t.attr("class",function(t){return n.Legend.getClass(t,null===n.legendScale)})}),r.select("title").text(function(t,e){return 0===e?n.formatStringWithObject(o.legendTitleFormat.lower,{min:o.legend[e],name:o.itemName[1]}):e===a.length-1?n.formatStringWithObject(o.legendTitleFormat.upper,{max:o.legend[e-1],name:o.itemName[1]}):n.formatStringWithObject(o.legendTitleFormat.inner,{down:o.legend[e-1],up:o.legend[e],name:o.itemName[1]})}),i.transition().duration(o.animationDuration).attr("x",l()).attr("y",u()).attr("width",e.getDim("width")).attr("height",e.getDim("height")),i.select("g").transition().duration(o.animationDuration).attr("transform",function(){return"vertical"===o.legendOrientation?"rotate(90 "+o.legendCellSize/2+" "+o.legendCellSize/2+")":""}),n.resize()},Legend.prototype.getDim=function(t){"use strict";var e="horizontal"===this.calendar.options.legendOrientation;switch(t){case"width":return this.dim[e?"width":"height"];case"height":return this.dim[e?"height":"width"]}},Legend.prototype.buildColors=function(){"use strict";var t=this.calendar.options;if(null===t.legendColors)return this.calendar.legendScale=null,!1;var e=[];if(Array.isArray(t.legendColors))e=t.legendColors;else{if(!t.legendColors.hasOwnProperty("min")||!t.legendColors.hasOwnProperty("max"))return t.legendColors=null,!1;e=[t.legendColors.min,t.legendColors.max]}var n=t.legend.slice(0),i=(0<n[0]?n.unshift(0):n[0]<=0&&n.unshift(n[0]-(n[n.length-1]-n[0])/n.length),d3.scaleLinear().range(e).interpolate(d3.interpolateHcl).domain([d3.min(n),d3.max(n)])),e=n.map(function(t){return i(t)});return this.calendar.legendScale=d3.scaleThreshold().domain(t.legend).range(e),!0},Legend.prototype.getClass=function(t,e){"use strict";if(null===t||isNaN(t))return"";for(var n=[this.calendar.options.legend.length+1],i=0,o=this.calendar.options.legend.length-1;i<=o;i++){if(0<this.calendar.options.legend[0]&&t<0){n=["1","i"];break}if(t<=this.calendar.options.legend[i]){n=[i+1];break}}return 0===t&&n.push(0),n.unshift(""),(n.join(" r")+(e?n.join(" q"):"")).trim()},"function"==typeof define&&define.amd?define(["d3"],function(){"use strict";return CalHeatMap}):"object"==typeof module&&module.exports?module.exports=CalHeatMap:window.CalHeatMap=CalHeatMap;