(function(){var t,e=[].indexOf||function(t){for(var e=0,n=this.length;n>e;e++)if(e in this&&this[e]===t)return e;return-1},n=[].slice,r=function(t,e){return function(){return t.apply(e,arguments)}},o={}.hasOwnProperty;(t=function(t){return"object"==typeof exports&&"object"==typeof module?t(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],t):t(jQuery)})(function(t){var a,i,s,u,l,c,p,h,d,f,g,m,v,b,A,y;return i=function(t,e,n){var r,o,a,i;for(t+="",o=t.split("."),a=o[0],i=o.length>1?n+o[1]:"",r=/(\d+)(\d{3})/;r.test(a);)a=a.replace(r,"$1"+e+"$2");return a+i},f=function(e){var n;return n={digitsAfterDecimal:2,scaler:1,thousandsSep:",",decimalSep:".",prefix:"",suffix:"",showZero:!1},e=t.extend(n,e),function(t){var n;return isNaN(t)||!isFinite(t)?"":0!==t||e.showZero?(n=i((e.scaler*t).toFixed(e.digitsAfterDecimal),e.thousandsSep,e.decimalSep),""+e.prefix+n+e.suffix):""}},v=f(),b=f({digitsAfterDecimal:0}),A=f({digitsAfterDecimal:1,scaler:100,suffix:"%"}),s={count:function(t){return null==t&&(t=b),function(){return function(){return{count:0,push:function(){return this.count++},value:function(){return this.count},format:t}}}},countUnique:function(t){return null==t&&(t=b),function(n){var r;return r=n[0],function(){return{uniq:[],push:function(t){var n;return n=t[r],e.call(this.uniq,n)<0?this.uniq.push(t[r]):void 0},value:function(){return this.uniq.length},format:t,numInputs:null!=r?0:1}}}},listUnique:function(t){return function(n){var r;return r=n[0],function(){return{uniq:[],push:function(t){var n;return n=t[r],e.call(this.uniq,n)<0?this.uniq.push(t[r]):void 0},value:function(){return this.uniq.join(t)},format:function(t){return t},numInputs:null!=r?0:1}}}},sum:function(t){return null==t&&(t=v),function(e){var n;return n=e[0],function(){return{sum:0,push:function(t){return isNaN(parseFloat(t[n]))?void 0:this.sum+=parseFloat(t[n])},value:function(){return this.sum},format:t,numInputs:null!=n?0:1}}}},average:function(t){return null==t&&(t=v),function(e){var n;return n=e[0],function(){return{sum:0,len:0,push:function(t){return isNaN(parseFloat(t[n]))?void 0:(this.sum+=parseFloat(t[n]),this.len++)},value:function(){return this.sum/this.len},format:t,numInputs:null!=n?0:1}}}},sumOverSum:function(t){return null==t&&(t=v),function(e){var n,r;return r=e[0],n=e[1],function(){return{sumNum:0,sumDenom:0,push:function(t){return isNaN(parseFloat(t[r]))||(this.sumNum+=parseFloat(t[r])),isNaN(parseFloat(t[n]))?void 0:this.sumDenom+=parseFloat(t[n])},value:function(){return this.sumNum/this.sumDenom},format:t,numInputs:null!=r&&null!=n?0:2}}}},sumOverSumBound80:function(t,e){return null==t&&(t=!0),null==e&&(e=v),function(n){var r,o;return o=n[0],r=n[1],function(){return{sumNum:0,sumDenom:0,push:function(t){return isNaN(parseFloat(t[o]))||(this.sumNum+=parseFloat(t[o])),isNaN(parseFloat(t[r]))?void 0:this.sumDenom+=parseFloat(t[r])},value:function(){var e;return e=t?1:-1,(.821187207574908/this.sumDenom+this.sumNum/this.sumDenom+1.2815515655446004*e*Math.sqrt(.410593603787454/(this.sumDenom*this.sumDenom)+this.sumNum*(1-this.sumNum/this.sumDenom)/(this.sumDenom*this.sumDenom)))/(1+1.642374415149816/this.sumDenom)},format:e,numInputs:null!=o&&null!=r?0:2}}}},fractionOf:function(t,e,r){return null==e&&(e="total"),null==r&&(r=A),function(){var o;return o=1<=arguments.length?n.call(arguments,0):[],function(n,a,i){return{selector:{total:[[],[]],row:[a,[]],col:[[],i]}[e],inner:t.apply(null,o)(n,a,i),push:function(t){return this.inner.push(t)},format:r,value:function(){return this.inner.value()/n.getAggregator.apply(n,this.selector).inner.value()},numInputs:t.apply(null,o)().numInputs}}}}},u=function(t){return{Count:t.count(b),"Count Unique Values":t.countUnique(b),"List Unique Values":t.listUnique(", "),Sum:t.sum(v),"Integer Sum":t.sum(b),Average:t.average(v),"Sum over Sum":t.sumOverSum(v),"80% Upper Bound":t.sumOverSumBound80(!0,v),"80% Lower Bound":t.sumOverSumBound80(!1,v),"Sum as Fraction of Total":t.fractionOf(t.sum(),"total",A),"Sum as Fraction of Rows":t.fractionOf(t.sum(),"row",A),"Sum as Fraction of Columns":t.fractionOf(t.sum(),"col",A),"Count as Fraction of Total":t.fractionOf(t.count(),"total",A),"Count as Fraction of Rows":t.fractionOf(t.count(),"row",A),"Count as Fraction of Columns":t.fractionOf(t.count(),"col",A)}}(s),m={Table:function(t,e){return g(t,e)},"Table Barchart":function(e,n){return t(g(e,n)).barchart()},Heatmap:function(e,n){return t(g(e,n)).heatmap()},"Row Heatmap":function(e,n){return t(g(e,n)).heatmap("rowheatmap")},"Col Heatmap":function(e,n){return t(g(e,n)).heatmap("colheatmap")}},p={en:{aggregators:u,renderers:m,localeStrings:{renderError:"An error occurred rendering the PivotTable results.",computeError:"An error occurred computing the PivotTable results.",uiRenderError:"An error occurred rendering the PivotTable UI.",selectAll:"Select All",selectNone:"Select None",tooMany:"(too many to list)",filterResults:"Filter results",totals:"Totals",vs:"vs",by:"by"}}},h=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],l=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],y=function(t){return("0"+t).substr(-2,2)},c={bin:function(t,e){return function(n){return n[t]-n[t]%e}},dateFormat:function(t,e,n,r){return null==n&&(n=h),null==r&&(r=l),function(o){var a;return a=new Date(Date.parse(o[t])),isNaN(a)?"":e.replace(/%(.)/g,function(t,e){switch(e){case"y":return a.getFullYear();case"m":return y(a.getMonth()+1);case"n":return n[a.getMonth()];case"d":return y(a.getDate());case"w":return r[a.getDay()];case"x":return a.getDay();case"H":return y(a.getHours());case"M":return y(a.getMinutes());case"S":return y(a.getSeconds());default:return"%"+e}})}}},d=function(){return function(t,e){var n,r,o,a,i,s,u;if(s=/(\d+)|(\D+)/g,i=/\d/,u=/^0/,"number"==typeof t||"number"==typeof e)return isNaN(t)?1:isNaN(e)?-1:t-e;if(n=String(t).toLowerCase(),o=String(e).toLowerCase(),n===o)return 0;if(!i.test(n)||!i.test(o))return n>o?1:-1;for(n=n.match(s),o=o.match(s);n.length&&o.length;)if(r=n.shift(),a=o.shift(),r!==a)return i.test(r)&&i.test(a)?r.replace(u,".0")-a.replace(u,".0"):r>a?1:-1;return n.length-o.length}}(this),t.pivotUtilities={aggregatorTemplates:s,aggregators:u,renderers:m,derivers:c,locales:p,naturalSort:d,numberFormat:f},a=function(){function e(t,n){this.getAggregator=r(this.getAggregator,this),this.getRowKeys=r(this.getRowKeys,this),this.getColKeys=r(this.getColKeys,this),this.sortKeys=r(this.sortKeys,this),this.arrSort=r(this.arrSort,this),this.natSort=r(this.natSort,this),this.aggregator=n.aggregator,this.aggregatorName=n.aggregatorName,this.colAttrs=n.cols,this.rowAttrs=n.rows,this.valAttrs=n.vals,this.tree={},this.rowKeys=[],this.colKeys=[],this.rowTotals={},this.colTotals={},this.allTotal=this.aggregator(this,[],[]),this.sorted=!1,e.forEachRecord(t,n.derivedAttributes,function(t){return function(e){return n.filter(e)?t.processRecord(e):void 0}}(this))}return e.forEachRecord=function(e,n,r){var a,i,s,u,l,c,p,h,d,f,g,m;if(a=t.isEmptyObject(n)?r:function(t){var e,o,a;for(e in n)o=n[e],t[e]=null!=(a=o(t))?a:t[e];return r(t)},t.isFunction(e))return e(a);if(t.isArray(e)){if(t.isArray(e[0])){g=[];for(s in e)if(o.call(e,s)&&(i=e[s],s>0)){c={},f=e[0];for(u in f)o.call(f,u)&&(l=f[u],c[l]=i[u]);g.push(a(c))}return g}for(m=[],h=0,d=e.length;d>h;h++)c=e[h],m.push(a(c));return m}if(e instanceof jQuery)return p=[],t("thead > tr > th",e).each(function(){return p.push(t(this).text())}),t("tbody > tr",e).each(function(){return c={},t("td",this).each(function(e){return c[p[e]]=t(this).text()}),a(c)});throw new Error("unknown input format")},e.convertToArray=function(t){var n;return n=[],e.forEachRecord(t,{},function(t){return n.push(t)}),n},e.prototype.natSort=function(t,e){return d(t,e)},e.prototype.arrSort=function(t,e){return this.natSort(t.join(),e.join())},e.prototype.sortKeys=function(){return this.sorted||(this.rowKeys.sort(this.arrSort),this.colKeys.sort(this.arrSort)),this.sorted=!0},e.prototype.getColKeys=function(){return this.sortKeys(),this.colKeys},e.prototype.getRowKeys=function(){return this.sortKeys(),this.rowKeys},e.prototype.processRecord=function(t){var e,n,r,o,a,i,s,u,l,c,p,h,d;for(e=[],o=[],c=this.colAttrs,i=0,u=c.length;u>i;i++)a=c[i],e.push(null!=(p=t[a])?p:"null");for(h=this.rowAttrs,s=0,l=h.length;l>s;s++)a=h[s],o.push(null!=(d=t[a])?d:"null");return r=o.join(String.fromCharCode(0)),n=e.join(String.fromCharCode(0)),this.allTotal.push(t),0!==o.length&&(this.rowTotals[r]||(this.rowKeys.push(o),this.rowTotals[r]=this.aggregator(this,o,[])),this.rowTotals[r].push(t)),0!==e.length&&(this.colTotals[n]||(this.colKeys.push(e),this.colTotals[n]=this.aggregator(this,[],e)),this.colTotals[n].push(t)),0!==e.length&&0!==o.length?(this.tree[r]||(this.tree[r]={}),this.tree[r][n]||(this.tree[r][n]=this.aggregator(this,o,e)),this.tree[r][n].push(t)):void 0},e.prototype.getAggregator=function(t,e){var n,r,o;return o=t.join(String.fromCharCode(0)),r=e.join(String.fromCharCode(0)),n=0===t.length&&0===e.length?this.allTotal:0===t.length?this.colTotals[r]:0===e.length?this.rowTotals[o]:this.tree[o][r],null!=n?n:{value:function(){return null},format:function(){return""}}},e}(),g=function(e,n){var r,a,i,s,u,l,c,p,h,d,f,g,m,v,b,A,y,w,C,S,T;l={localeStrings:{totals:"Totals"}},n=t.extend(l,n),i=e.colAttrs,f=e.rowAttrs,m=e.getRowKeys(),u=e.getColKeys(),d=document.createElement("table"),d.className="pvtTable",v=function(t,e,n){var r,o,a,i,s,u;if(0!==e){for(o=!0,i=s=0;n>=0?n>=s:s>=n;i=n>=0?++s:--s)t[e-1][i]!==t[e][i]&&(o=!1);if(o)return-1}for(r=0;e+r=0?n>=u:u>=n;i=n>=0?++u:--u)t[e][i]!==t[e+r][i]&&(a=!0);if(a)break;r++}return r};for(p in i)if(o.call(i,p)){a=i[p],w=document.createElement("tr"),0===parseInt(p)&&0!==f.length&&(A=document.createElement("th"),A.setAttribute("colspan",f.length),A.setAttribute("rowspan",i.length),w.appendChild(A)),A=document.createElement("th"),A.className="pvtAxisLabel",A.textContent=a,w.appendChild(A);for(c in u)o.call(u,c)&&(s=u[c],T=v(u,parseInt(c),parseInt(p)),-1!==T&&(A=document.createElement("th"),A.className="pvtColLabel",A.textContent=s[p],A.setAttribute("colspan",T),parseInt(p)===i.length-1&&0!==f.length&&A.setAttribute("rowspan",2),w.appendChild(A)));0===parseInt(p)&&(A=document.createElement("th"),A.className="pvtTotalLabel",A.innerHTML=n.localeStrings.totals,A.setAttribute("rowspan",i.length+(0===f.length?0:1)),w.appendChild(A)),d.appendChild(w)}if(0!==f.length){w=document.createElement("tr");for(c in f)o.call(f,c)&&(h=f[c],A=document.createElement("th"),A.className="pvtAxisLabel",A.textContent=h,w.appendChild(A));A=document.createElement("th"),0===i.length&&(A.className="pvtTotalLabel",A.innerHTML=n.localeStrings.totals),w.appendChild(A),d.appendChild(w)}for(c in m)if(o.call(m,c)){g=m[c],w=document.createElement("tr");for(p in g)o.call(g,p)&&(C=g[p],T=v(m,parseInt(c),parseInt(p)),-1!==T&&(A=document.createElement("th"),A.className="pvtRowLabel",A.textContent=C,A.setAttribute("rowspan",T),parseInt(p)===f.length-1&&0!==i.length&&A.setAttribute("colspan",2),w.appendChild(A)));for(p in u)o.call(u,p)&&(s=u[p],r=e.getAggregator(g,s),S=r.value(),b=document.createElement("td"),b.className="pvtVal row"+c+" col"+p,b.innerHTML=r.format(S),b.setAttribute("data-value",S),w.appendChild(b));y=e.getAggregator(g,[]),S=y.value(),b=document.createElement("td"),b.className="pvtTotal rowTotal",b.innerHTML=y.format(S),b.setAttribute("data-value",S),b.setAttribute("data-for","row"+c),w.appendChild(b),d.appendChild(w)}w=document.createElement("tr"),A=document.createElement("th"),A.className="pvtTotalLabel",A.innerHTML=n.localeStrings.totals,A.setAttribute("colspan",f.length+(0===i.length?0:1)),w.appendChild(A);for(p in u)o.call(u,p)&&(s=u[p],y=e.getAggregator([],s),S=y.value(),b=document.createElement("td"),b.className="pvtTotal colTotal",b.innerHTML=y.format(S),b.setAttribute("data-value",S),b.setAttribute("data-for","col"+p),w.appendChild(b));return y=e.getAggregator([],[]),S=y.value(),b=document.createElement("td"),b.className="pvtGrandTotal",b.innerHTML=y.format(S),b.setAttribute("data-value",S),w.appendChild(b),d.appendChild(w),d.setAttribute("data-numrows",m.length),d.setAttribute("data-numcols",u.length),d},t.fn.pivot=function(e,n){var r,o,i,u,l;r={cols:[],rows:[],filter:function(){return!0},aggregator:s.count()(),aggregatorName:"Count",derivedAttributes:{},renderer:g,rendererOptions:null,localeStrings:p.en.localeStrings},n=t.extend(r,n),u=null;try{i=new a(e,n);try{u=n.renderer(i,n.rendererOptions)}catch(c){o=c,"undefined"!=typeof console&&null!==console&&console.error(o.stack),u=t("").html(n.localeStrings.renderError)}}catch(c){o=c,"undefined"!=typeof console&&null!==console&&console.error(o.stack),u=t("").html(n.localeStrings.computeError)}for(l=this[0];l.hasChildNodes();)l.removeChild(l.lastChild);return this.append(u)},t.fn.pivotUI=function(n,r,i,s){var u,l,c,h,f,g,m,v,b,A,y,w,C,S,T,x,N,F,E,D,O,R,L,k,M,I,K,q,U,V,j,H,B,P,J,_,z,Q,W;null==i&&(i=!1),null==s&&(s="en"),m={derivedAttributes:{},aggregators:p[s].aggregators,renderers:p[s].renderers,hiddenAttributes:[],menuLimit:200,cols:[],rows:[],vals:[],exclusions:{},unusedAttrsVertical:"auto",autoSortUnusedAttrs:!1,rendererOptions:{localeStrings:p[s].localeStrings},onRefresh:null,filter:function(){return!0},localeStrings:p[s].localeStrings},b=this.data("pivotUIOptions"),C=null==b||i?t.extend(m,r):b;try{n=a.convertToArray(n),D=function(){var t,e;t=n[0],e=[];for(w in t)o.call(t,w)&&e.push(w);return e}(),J=C.derivedAttributes;for(f in J)o.call(J,f)&&e.call(D,f)<0&&D.push(f);for(h={},K=0,j=D.length;j>K;K++)M=D[K],h[M]={};a.forEachRecord(n,C.derivedAttributes,function(t){var e,n,r;r=[];for(w in t)o.call(t,w)&&(e=t[w],C.filter(t)&&(null==e&&(e="null"),null==(n=h[w])[e]&&(n[e]=0),r.push(h[w][e]++)));return r}),L=t(""),F=t("").appendTo(L),l=t("").appendTo(L),R.append(t("").append(F).append(g)),this.html(L),Q=C.cols,U=0,B=Q.length;B>U;U++)M=Q[U],this.find(".pvtCols").append(this.find(".axis_"+E.indexOf(M)));for(W=C.rows,V=0,P=W.length;P>V;V++)M=W[V],this.find(".pvtRows").append(this.find(".axis_"+E.indexOf(M)));null!=C.aggregatorName&&this.find(".pvtAggregator").val(C.aggregatorName),null!=C.rendererName&&this.find(".pvtRenderer").val(C.rendererName),y=!0,x=function(r){return function(){var o,a,i,s,u,c,p,h,d,f,g,m,v,b;if(h={derivedAttributes:C.derivedAttributes,localeStrings:C.localeStrings,rendererOptions:C.rendererOptions,cols:[],rows:[]},u=null!=(b=C.aggregators[l.val()]([])().numInputs)?b:0,f=[],r.find(".pvtRows li span.pvtAttr").each(function(){return h.rows.push(t(this).data("attrName"))}),r.find(".pvtCols li span.pvtAttr").each(function(){return h.cols.push(t(this).data("attrName"))}),r.find(".pvtVals select.pvtAttrDropdown").each(function(){return 0===u?t(this).remove():(u--,""!==t(this).val()?f.push(t(this).val()):void 0)}),0!==u)for(p=r.find(".pvtVals"),M=m=0;u>=0?u>m:m>u;M=u>=0?++m:--m){for(s=t("
"),N=t(""),E=function(){var t,n,r;for(r=[],t=0,n=D.length;n>t;t++)f=D[t],e.call(C.hiddenAttributes,f)<0&&r.push(f);return r}(),k=!1,"auto"===C.unusedAttrsVertical){for(c=0,q=0,H=E.length;H>q;q++)u=E[q],c+=u.length;k=c>120}g.addClass(C.unusedAttrsVertical===!0||k?"pvtVertList":"pvtHorizList"),I=function(n){var r,o,a,i,s,u,l,c,p,f,m,v,b,y,S;if(l=function(){var t;t=[];for(w in h[n])t.push(w);return t}(),u=!1,v=t("
").addClass("pvtFilterBox").hide(),v.append(t("

").text(""+n+" ("+l.length+")")),l.length>C.menuLimit)v.append(t("

").html(C.localeStrings.tooMany));else for(o=t("

").appendTo(v),o.append(t("

").appendTo(O).append(l).append(t("
")),t("
").appendTo(O),R=t("
")),S=t("").appendTo(R),C.unusedAttrsVertical===!0||k?(L.find("tr:nth-child(1)").prepend(F),L.find("tr:nth-child(2)").prepend(g)):L.prepend(t("