/*
    *
    * Wijmo Library 5.20183.550
    * http://wijmo.com/
    *
    * Copyright(c) GrapeCity, Inc.  All rights reserved.
    *
    * Licensed under the GrapeCity Commercial License.
    * sales@wijmo.com
    * wijmo.com/products/wijmo-5/license/
    *
    */
var __extends=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])};return function(t,i){function n(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}();define(["require","exports","wijmo/wijmo","wijmo/wijmo.grid.filter","wijmo/wijmo.input","wijmo/wijmo.grid","wijmo/wijmo.chart","wijmo/wijmo.olap"],function(e,t,i,n,r,s,o,l){"use strict";function a(e,t){var i=e.querySelector(t);return i?i.innerHTML||i.textContent:null}function d(e){return Number(a(e,"LNum"))}function h(e){return d(e)>0?a(e,"Caption"):null}function u(e,t){var i="Cell[CellOrdinal='"+t.toString()+"']",n=e.querySelector(i);if(n){var r=a(n,"Value");if(r)return Number(r)}return null}function c(e,t){if(e.subFields)for(var i=0;i<e.subFields.length;i++){var n=e.subFields[i];if(n.header==t)return n}return e}function p(e,t){if(e.subFields)for(var i=0;i<e.subFields.length;i++)if(e.subFields[i].header==t)return!0;return!1}Object.defineProperty(t,"__esModule",{value:!0});var g="undefined"!=typeof window?window:self,_=l||t;g.wijmo=g.wijmo||{},g.wijmo.olap=_;var f=function(){function e(){this._cnt=0,this._cntn=0,this._sum=0,this._sum2=0,this._min=null,this._max=null,this._first=null,this._last=null}return e.prototype.add=function(t,n){t instanceof e?(this._sum+=t._sum,this._sum2+=t._sum2,this._max=this._max&&t._max?Math.max(this._max,t._max):this._max||t._max,this._min=this._min&&t._min?Math.min(this._min,t._min):this._min||t._min,this._cnt+=t._cnt,this._cntn+=t._cntn):null!=t&&(this._cnt++,i.isBoolean(t)&&(t=t?1:0),(null==this._min||t<this._min)&&(this._min=t),(null==this._max||t>this._max)&&(this._max=t),null==this._first&&(this._first=t),this._last=t,i.isNumber(t)&&!isNaN(t)&&(i.isNumber(n)&&(t*=n),this._cntn++,this._sum+=t,this._sum2+=t*t))},e.prototype.getAggregate=function(e){if(0==this._cnt)return null;var t=0==this._cntn?0:this._sum/this._cntn;switch(e){case i.Aggregate.Avg:return t;case i.Aggregate.Cnt:return this._cnt;case i.Aggregate.Max:return this._max;case i.Aggregate.Min:return this._min;case i.Aggregate.Rng:return this._max-this._min;case i.Aggregate.Sum:return this._sum;case i.Aggregate.VarPop:return this._cntn<=1?0:this._sum2/this._cntn-t*t;case i.Aggregate.StdPop:return this._cntn<=1?0:Math.sqrt(this._sum2/this._cntn-t*t);case i.Aggregate.Var:return this._cntn<=1?0:(this._sum2/this._cntn-t*t)*this._cntn/(this._cntn-1);case i.Aggregate.Std:return this._cntn<=1?0:Math.sqrt((this._sum2/this._cntn-t*t)*this._cntn/(this._cntn-1));case i.Aggregate.First:return this._first;case i.Aggregate.Last:return this._last}throw"Invalid aggregate type."},e}();t._Tally=f;var v=function(){function e(e,t,i,n,r){this._fields=e,this._fieldCount=t,this._valueFields=i,this._valueFieldIndex=n,this._item=r}return Object.defineProperty(e.prototype,"fields",{get:function(){return this._fields},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"valueFields",{get:function(){return this._valueFields},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"valueField",{get:function(){return this._valueFields[this._valueFieldIndex]},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"values",{get:function(){if(null==this._vals){this._vals=new Array(this._fieldCount);for(var e=0;e<this._fieldCount;e++){var t=this._fields[e];this._vals[e]=t._getValue(this._item,!1)}}return this._vals},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"fieldNames",{get:function(){if(!this._names){this._names=[];for(var e=0;e<this.fields.length;e++){var t=this._fields[e];this._names.push(t._getName())}}return this._names},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aggregate",{get:function(){var e=this._valueFields,t=this._valueFieldIndex;return i.assert(e&&t>-1&&t<e.length,"aggregate not available for this key"),e[t].aggregate},enumerable:!0,configurable:!0}),e.prototype.getValue=function(e,t){if(0==this.values.length)return i.culture.olap.PivotEngine.grandTotal;if(e>this.values.length-1)return i.culture.olap.PivotEngine.subTotal;var n=this.values[e];if(t&&!i.isString(n)){var r=this.fields[e],s=r?r.format:"";n=i.Globalize.format(this.values[e],s)}return n},Object.defineProperty(e.prototype,"level",{get:function(){return this._fieldCount==this._fields.length?-1:this._fieldCount},enumerable:!0,configurable:!0}),e.prototype.compareTo=function(e){var t=0;if(null!=e&&e._fields==this._fields){for(var n=this.values,r=e.values,s=Math.min(n.length,r.length),o=0;o<s;o++){var l=null!=n[o]?i.getType(n[o]):null,a=n[o],d=r[o],h=this._fields[o];if(h.sortComparer&&(t=h.sortComparer(a,d),i.isNumber(t))){if(0!=t)return h.descending?-t:t}else{if(l==i.DataType.Date){var u=h.format;if(u&&"d"!=u&&"D"!=u){var c=h._getValue(this._item,!0),p=h._getValue(e._item,!0),g=i.Globalize.parseDate(c,u),_=i.Globalize.parseDate(p,u);g&&_?(a=g,d=_):(a=c,d=p)}}if(!(a==d||i.DateTime.equals(a,d)))return null==a?1:null==d?-1:(t=a<d?-1:1,h.descending?-t:t)}}if(n.length==r.length&&0!=(t=this._valueFieldIndex-e._valueFieldIndex))return t;if(0!=(t=r.length-n.length))return t*(this.fields.engine.totalsBeforeData?-1:1)}return 0},e.prototype.matchesItem=function(e){for(var t=0;t<this._vals.length;t++)if(this.getValue(t,!0)!=this._fields[t]._getValue(e,!0))return!1;return!0},e.prototype.toString=function(e){if(!this._key||e){for(var t="",i=0;i<this._fieldCount;i++){var n=this._fields[i];t+=n._getName()+":"+n._getValue(this._item,!0)+";"}if(this._valueFields?t+=this._valueFields[this._valueFieldIndex]._getName()+":0;":t+="{total}",e)return t+e.toString();this._key=t}return this._key},e._ROW_KEY_NAME="$rowKey",e}();t._PivotKey=v;var m=function(){function e(e,t,i,n,r,s){this._key=new v(e,t,i,n,r),this._nodes={},this._parent=s}return e.prototype.getNode=function(t,i,n,r,s){for(var o=this,l=0;l<i;l++){a=t[l]._getValue(s,!0);(d=o._nodes[a])||(d=new e(t,l+1,n,r,s,o),o._nodes[a]=d),o=d}if(n&&r>-1){var a=n[r].header,d=o._nodes[a];d||(d=new e(t,i,n,r,s,o),o._nodes[a]=d),o=d}return o},Object.defineProperty(e.prototype,"key",{get:function(){return this._key},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this._parent},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"tree",{get:function(){return this._tree||(this._tree=new e(null,0,null,-1,null)),this._tree},enumerable:!0,configurable:!0}),e}();t._PivotNode=m;var y=function(e){function t(t){var n=e.call(this)||this;return n._ng=i.asType(t,R,!1),n}return __extends(t,e),Object.defineProperty(t.prototype,"engine",{get:function(){return this._ng},enumerable:!0,configurable:!0}),t.prototype._performSort=function(e){var t=this._ng;if(t.sortableGroups&&t._getShowRowTotals()==P.Subtotals){var i=0,n=e.length-1;0==this._getItemLevel(e[i])&&i++,0==this._getItemLevel(e[n])&&n--,this._sortGroups(e,1,i,n)}else this._sortData(e)},t.prototype._performFilter=function(e){return this._ng&&0==this._ng.valueFields.length&&0==this._ng.rowFields.length?[]:this.canFilter&&this._filter?e.filter(this._filter,this):e},t.prototype._getGroupRange=function(e,t){var i=this._ng,n=e.indexOf(t),r=n,s=this._getItemLevel(e[n]);if(i.totalsBeforeData)for(r=n;r<e.length-1&&!((o=this._getItemLevel(e[r+1]))>-1&&o<=s);r++);else for(n=r;n;n--){var o=this._getItemLevel(e[n-1]);if(o>-1&&o<=s)break}return[n,r]},t.prototype._sortGroups=function(t,i,n,r){for(var s=[],o=n;o<=r;o++)this._getItemLevel(t[o])==i&&s.push(t[o]);if(s.length){e.prototype._performSort.call(this,s);for(var l=[],o=0;o<s.length;o++){for(var a=this._getGroupRange(t,s[o]),d=l.length,h=a[0];h<=a[1];h++)l.push(t[h]);i<this._ng.rowFields.length-1?this._sortGroups(l,i+1,n+d,l.length-1):this._sortSegment(l,n+d,l.length-1)}for(o=0;o<l.length;o++)t[n+o]=l[o]}else this._sortData(t)},t.prototype._sortSegment=function(t,i,n){var r=t.slice(i,n);e.prototype._performSort.call(this,r);for(var s=0;s<r.length;s++)t[i+s]=r[s]},t.prototype._sortData=function(t){for(var i=0;i<t.length;i++)if(!(this._getItemLevel(t[i])>-1)){for(var n=i;n<t.length-1&&!(this._getItemLevel(t[n+1])>-1);n++);if(n>i){var r=t.slice(i,n+1);e.prototype._performSort.call(this,r);for(var s=0;s<r.length;s++)t[i+s]=r[s]}i=n}},t.prototype._getItemLevel=function(e){return e[v._ROW_KEY_NAME].level},t}(i.CollectionView);t.PivotCollectionView=y;var b=function(){function e(e,t,n,r){this.propertyChanged=new i.Event,this._ng=e,this._binding=new i.Binding(t),this._header=n||i.toHeaderCase(t),this._aggregate=i.Aggregate.Sum,this._showAs=E.NoCalculation,this._isContentHtml=!1,this._visible=!0,this._format="",this._filter=new x(this),r&&i.copy(this,r)}return Object.defineProperty(e.prototype,"binding",{get:function(){return this._binding?this._binding.path:null},set:function(e){if(e!=this.binding){var t=this.binding,n=i.asString(e);if(this._binding=n?new i.Binding(n):null,!this._dataType&&this._ng&&this._binding){var r=this._ng.collectionView;if(r&&r.sourceCollection&&r.sourceCollection.length){var s=r.sourceCollection[0];this._dataType=i.getType(this._binding.getValue(s))}}var o=new i.PropertyChangedEventArgs("binding",t,e);this.onPropertyChanged(o)}},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"getValue",{get:function(){return this._getValueFn},set:function(e){this._getValueFn=i.asFunction(e,!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"header",{get:function(){return this._header},set:function(e){e=i.asString(e,!1);var t=this._ng.fields.getField(e);!e||t&&t!=this?i.assert(!1,"field headers must be unique and non-empty."):this._setProp("_header",i.asString(e))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"filter",{get:function(){return this._filter},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aggregate",{get:function(){return this._aggregate},set:function(e){this._setProp("_aggregate",i.asEnum(e,i.Aggregate))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"showAs",{get:function(){return this._showAs},set:function(e){this._setProp("_showAs",i.asEnum(e,E))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"weightField",{get:function(){return this._weightField},set:function(t){this._setProp("_weightField",i.asType(t,e,!0))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"dataType",{get:function(){return this._dataType},set:function(e){this._setProp("_dataType",i.asEnum(e,i.DataType))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isMeasure",{get:function(){return this._dataType==i.DataType.Number},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"subFields",{get:function(){return this._subFields},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"format",{get:function(){return this._format},set:function(e){this._setProp("_format",i.asString(e))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(e){this._setProp("_width",i.asNumber(e,!0,!0))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"wordWrap",{get:function(){return this._wordWrap},set:function(e){this._setProp("_wordWrap",i.asBoolean(e))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"descending",{get:function(){return!!this._descending},set:function(e){this._setProp("_descending",i.asBoolean(e))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isContentHtml",{get:function(){return this._isContentHtml},set:function(e){this._setProp("_isContentHtml",i.asBoolean(e))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"visible",{get:function(){return this._visible},set:function(e){this._setProp("_visible",i.asBoolean(e))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"sortComparer",{get:function(){return this._srtCmp},set:function(e){e!=this.sortComparer&&(this._srtCmp=i.asFunction(e))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"engine",{get:function(){return this._ng},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"collectionView",{get:function(){return this.engine?this.engine.collectionView:null},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isActive",{get:function(){return this._getIsActive()},set:function(e){this._setIsActive(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"parentField",{get:function(){return this._parent},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"key",{get:function(){return this.header},enumerable:!0,configurable:!0}),e.prototype.onPropertyChanged=function(e){this.propertyChanged.raise(this,e),this._ng._fieldPropertyChanged(this,e)},e.prototype._copy=function(e,t){var i=this;return"subFields"==e&&(this._subFields?this._subFields.splice(0,this._subFields.length):this._subFields=[],t&&t.length&&t.forEach(function(e){var t=i.engine._createField(e,i._autoGenerated);i._subFields.push(t)}),!0)},e.prototype._getIsActive=function(){if(this._ng&&!this._hasSubFields())for(var e=this._ng._viewLists,t=0;t<e.length;t++)for(var i=e[t],n=0;n<i.length;n++)if(i[n].binding==this.binding)return!0;return!1},e.prototype._setIsActive=function(e){if(this._ng&&!this._hasSubFields()){var t=this.isActive;if((e=i.asBoolean(e))!=t)if(e)this.isMeasure?this._ng.valueFields.push(this):this._ng.rowFields.push(this);else{for(var n=this._ng._viewLists,r=0;r<n.length;r++)for(var s=n[r],o=0;o<s.length;o++)(a=s[o])!=this&&a.parentField!=this||(s.removeAt(o),o--);for(var l=this._ng.fields,o=l.length-1;o>=0;o--){var a=l[o];a.parentField==this&&(l.removeAt(o),o--)}}}},e.prototype._hasSubFields=function(){return null!=this._subFields&&this._subFields.length>0},e.prototype._clone=function(){var t=new e(this._ng,this.binding);this._ng._copyProps(t,this,e._props),t._autoGenerated=!0,t._parent=this;for(var i=this.header.replace(/\d+$/,""),n=2;;n++){var r=i+n.toString();if(null==this._ng.fields.getField(r)){t._header=r;break}}return t},e.prototype._setProp=function(e,t,n){var r=this[e];if(t!=r){this[e]=t;var s=new i.PropertyChangedEventArgs(e.substr(1),r,t);this.onPropertyChanged(s)}},e.prototype._getName=function(){return this.header||this.binding},e.prototype._getValue=function(e,t){var n,r=this._binding;return n=i.isFunction(this._getValueFn)?this._getValueFn.call(this,e):this._ng.isServer?e[this.key]:r._key?e[r._key]:r.getValue(e),t&&"string"!=typeof n?i.Globalize.format(n,this._format):n},e.prototype._getWeight=function(e){var t=this._weightField?this._weightField._getValue(e,!1):null;return i.isNumber(t)?t:null},e._props=["dataType","format","width","wordWrap","aggregate","showAs","descending","isContentHtml","visible"],e}();t.PivotField=b;var w=function(e){function t(t,n,r,s){var o=e.call(this,t,n,r,s)||this;return i.assert(null!=o.dimensionType,"CubePivotField objects must specify the field's dimensionType"),o}return __extends(t,e),Object.defineProperty(t.prototype,"header",{get:function(){return this._header},set:function(e){this._setProp("_header",i.asString(e))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"dimensionType",{get:function(){return this._dimensionType},set:function(e){this._setProp("_dimensionType",i.asEnum(e,F,!1))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isMeasure",{get:function(){switch(this._dimensionType){case 1:case 8:return!0}return!1},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"key",{get:function(){return this.binding},enumerable:!0,configurable:!0}),t.prototype._clone=function(){throw"CubePivotField objects cannot be cloned"},t}(b);t.CubePivotField=w;var F;!function(e){e[e.Dimension=0]="Dimension",e[e.Measure=1]="Measure",e[e.Kpi=2]="Kpi",e[e.NameSet=3]="NameSet",e[e.Attribute=4]="Attribute",e[e.Folder=5]="Folder",e[e.Hierarchy=6]="Hierarchy",e[e.Date=7]="Date",e[e.Currency=8]="Currency"}(F=t.DimensionType||(t.DimensionType={}));var C=function(e){function t(t){var i=e.call(this)||this;return i._ng=t,i}return __extends(t,e),Object.defineProperty(t.prototype,"maxItems",{get:function(){return this._maxItems},set:function(e){this._maxItems=i.asInt(e,!0,!0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"engine",{get:function(){return this._ng},enumerable:!0,configurable:!0}),t.prototype.getField=function(e){return this._getField(this,e)},t.prototype._getField=function(e,t){for(var i=0;i<e.length;i++){var n=e[i];if(n.key==t)return n;if(n._hasSubFields()&&(n=this._getField(n.subFields,t)))return n}return null},t.prototype.push=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];for(var r=this._ng,s=0;t&&s<t.length;s++){var o=t[s];if(i.isString(o)&&(o=this==r.fields?new b(r,o):r.fields.getField(o)),i.assert(o instanceof b,"This collection must contain PivotField objects only."),o.key&&this.getField(o.key))return i.assert(!1,"PivotField keys must be unique."),-1;if(null!=this._maxItems&&this.length>=this._maxItems)break;e.prototype.push.call(this,o)}return this.length},t}(i.ObservableArray);t.PivotFieldCollection=C;var x=function(){function e(e){this._fld=e;var t=e;this._valueFilter=new n.ValueFilter(t),this._conditionFilter=new n.ConditionFilter(t)}return Object.defineProperty(e.prototype,"filterType",{get:function(){return null!=this._filterType?this._filterType:this._fld.engine.defaultFilterType},set:function(e){(e=i.asEnum(e,n.FilterType,!0))!=this._filterType&&(this._filterType=e,this.clear())},enumerable:!0,configurable:!0}),e.prototype.apply=function(e){return this._conditionFilter.apply(e)&&this._valueFilter.apply(e)},Object.defineProperty(e.prototype,"isActive",{get:function(){return this._conditionFilter.isActive||this._valueFilter.isActive},enumerable:!0,configurable:!0}),e.prototype.clear=function(){var e=!1;this._valueFilter.isActive&&(this._valueFilter.clear(),e=!0),this._conditionFilter.isActive&&(this._valueFilter.clear(),e=!0),e&&this._fld.onPropertyChanged(new i.PropertyChangedEventArgs("filter",null,null))},Object.defineProperty(e.prototype,"valueFilter",{get:function(){return this._valueFilter},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"conditionFilter",{get:function(){return this._conditionFilter},enumerable:!0,configurable:!0}),e}();t.PivotFilter=x;var T=function(e){function t(t,n){var s=e.call(this,t,null,!0)||this;i.assert(null!=r,"Missing dependency: PivotFieldEditor requires wijmo.input."),s.hostElement.tabIndex=-1;var o=s.getTemplate();s.applyTemplate("wj-control wj-pivotfieldeditor",o,{_dBnd:"sp-bnd",_dHdr:"div-hdr",_dAgg:"div-agg",_dShw:"div-shw",_dWFl:"div-wfl",_dSrt:"div-srt",_btnFltEdt:"btn-flt-edt",_btnFltClr:"btn-flt-clr",_dFmt:"div-fmt",_dSmp:"div-smp",_btnApply:"btn-apply",_btnCancel:"btn-cancel",_gDlg:"g-dlg",_gHdr:"g-hdr",_gAgg:"g-agg",_gShw:"g-shw",_gWfl:"g-wfl",_gSrt:"g-srt",_gFlt:"g-flt",_gFmt:"g-fmt",_gSmp:"g-smp"}),s._pvDate=new Date;var l=i.culture.olap.PivotFieldEditor;return i.setText(s._gDlg,l.dialogHeader),i.setText(s._gHdr,l.header),i.setText(s._gAgg,l.summary),i.setText(s._gShw,l.showAs),i.setText(s._gWfl,l.weighBy),i.setText(s._gSrt,l.sort),i.setText(s._gFlt,l.filter),i.setText(s._gFmt,l.format),i.setText(s._gSmp,l.sample),i.setText(s._btnFltEdt,l.edit),i.setText(s._btnFltClr,l.clear),i.setText(s._btnApply,l.ok),i.setText(s._btnCancel,l.cancel),s._cmbHdr=new r.ComboBox(s._dHdr),s._cmbAgg=new r.ComboBox(s._dAgg),s._cmbShw=new r.ComboBox(s._dShw),s._cmbWFl=new r.ComboBox(s._dWFl),s._cmbSrt=new r.ComboBox(s._dSrt),s._cmbFmt=new r.ComboBox(s._dFmt),s._cmbSmp=new r.ComboBox(s._dSmp),s._initAggregateOptions(),s._initShowAsOptions(),s._initFormatOptions(),s._initSortOptions(),s._updatePreview(),s._cmbShw.textChanged.addHandler(s._updateFormat,s),s._cmbFmt.textChanged.addHandler(s._updatePreview,s),s.addEventListener(s._btnFltEdt,"click",function(e){s._editFilter(),e.preventDefault()}),s.addEventListener(s._btnFltClr,"click",function(e){s._createFilterEditor(),setTimeout(function(){s._eFlt.clearEditor(),s._btnFltEdt.focus(),i.enable(s._btnFltClr,!1)}),e.preventDefault()}),s.addEventListener(s._btnApply,"click",function(e){s.updateField()}),s.initialize(n),s}return __extends(t,e),Object.defineProperty(t.prototype,"field",{get:function(){return this._fld},set:function(e){e!=this._fld&&(this._fld=i.asType(e,b),this.updateEditor())},enumerable:!0,configurable:!0}),t.prototype.updateEditor=function(){if(this._fld){this._dBnd.textContent=this._fld.binding,this._cmbHdr.text=this._fld.header,this._cmbAgg.collectionView.refresh(),this._cmbAgg.selectedValue=this._fld.aggregate,this._cmbSrt.selectedValue=this._fld.descending,this._cmbShw.selectedValue=this._fld.showAs,this._initWeighByOptions(),i.enable(this._btnFltClr,this._fld.filter.isActive),this._cmbFmt.collectionView.refresh(),this._cmbFmt.selectedValue=this._fld.format,this._cmbFmt.selectedValue||(this._cmbFmt.text=this._fld.format);var e=this._fld instanceof w;this._cmbAgg.isDisabled=e,this._cmbWFl.isDisabled=e}},t.prototype.updateField=function(){if(this._fld){var e=this._cmbHdr.text.trim();this._fld.header=e||i.toHeaderCase(this._fld.binding),this._fld.aggregate=this._cmbAgg.selectedValue,this._fld.showAs=this._cmbShw.selectedValue,this._fld.weightField=this._cmbWFl.selectedValue,this._fld.descending=this._cmbSrt.selectedValue,this._eFlt&&this._eFlt.updateFilter(),this._fld.format=this._cmbFmt.selectedValue||this._cmbFmt.text}},t.prototype._initAggregateOptions=function(){var e=this,t=i.culture.olap.PivotFieldEditor.aggs,n=i.Aggregate,r=[{key:t.sum,val:n.Sum,all:!1},{key:t.cnt,val:n.Cnt,all:!0},{key:t.avg,val:n.Avg,all:!1},{key:t.max,val:n.Max,all:!0},{key:t.min,val:n.Min,all:!0},{key:t.rng,val:n.Rng,all:!1},{key:t.std,val:n.Std,all:!1},{key:t.var,val:n.Var,all:!1},{key:t.stdp,val:n.StdPop,all:!1},{key:t.varp,val:n.VarPop,all:!1},{key:t.first,val:n.First,all:!0},{key:t.last,val:n.Last,all:!0}];this._cmbAgg.itemsSource=r,this._cmbAgg.collectionView.filter=function(t){if(t&&t.all)return!0;if(e._fld){var n=e._fld.dataType;return n==i.DataType.Number||n==i.DataType.Boolean}return!1},this._cmbAgg.initialize({displayMemberPath:"key",selectedValuePath:"val"})},t.prototype._initShowAsOptions=function(){var e=i.culture.olap.PivotFieldEditor.calcs,t=[{key:e.noCalc,val:E.NoCalculation},{key:e.dRow,val:E.DiffRow},{key:e.dRowPct,val:E.DiffRowPct},{key:e.dCol,val:E.DiffCol},{key:e.dColPct,val:E.DiffColPct},{key:e.dPctGrand,val:E.PctGrand},{key:e.dPctRow,val:E.PctRow},{key:e.dPctCol,val:E.PctCol},{key:e.dRunTot,val:E.RunTot},{key:e.dRunTotPct,val:E.RunTotPct}];this._cmbShw.itemsSource=t,this._cmbShw.initialize({displayMemberPath:"key",selectedValuePath:"val"})},t.prototype._initFormatOptions=function(){var e=this,t=i.culture.olap.PivotFieldEditor.formats,n=[{key:t.n0,val:"n0",all:!0},{key:t.n2,val:"n2",all:!0},{key:t.c,val:"c",all:!0},{key:t.p0,val:"p0",all:!0},{key:t.p2,val:"p2",all:!0},{key:t.n2c,val:"n2,",all:!0},{key:t.n2cc,val:"n2,,",all:!0},{key:t.n2ccc,val:"n2,,,",all:!0},{key:t.d,val:"d",all:!1},{key:t.MMMMddyyyy,val:"MMMM dd, yyyy",all:!1},{key:t.dMyy,val:"d/M/yy",all:!1},{key:t.ddMyy,val:"dd/M/yy",all:!1},{key:t.dMyyyy,val:"dd/M/yyyy",all:!1},{key:t.MMMyyyy,val:"MMM yyyy",all:!1},{key:t.MMMMyyyy,val:"MMMM yyyy",all:!1},{key:t.yyyy,val:"yyyy",all:!1},{key:t.yyyyQq,val:'yyyy "Q"q',all:!1},{key:t.FYEEEEQU,val:'"FY"EEEE "Q"U',all:!1}];this._cmbFmt.itemsSource=n,this._cmbFmt.isEditable=!0,this._cmbFmt.isRequired=!1,this._cmbFmt.collectionView.filter=function(t){return!(!t||!t.all)||!!e._fld&&e._fld.dataType==i.DataType.Date},this._cmbFmt.initialize({displayMemberPath:"key",selectedValuePath:"val"})},t.prototype._initWeighByOptions=function(){var e=[{key:i.culture.olap.PivotFieldEditor.none,val:null}];if(this._fld)for(var t=this._fld.engine,n=0;n<t.fields.length;n++){var r=t.fields[n];r!=this._fld&&r.dataType==i.DataType.Number&&e.push({key:r.header,val:r})}this._cmbWFl.initialize({displayMemberPath:"key",selectedValuePath:"val",itemsSource:e,selectedValue:this._fld.weightField})},t.prototype._initSortOptions=function(){var e=i.culture.olap.PivotFieldEditor.sorts,t=[{key:e.asc,val:!1},{key:e.desc,val:!0}];this._cmbSrt.itemsSource=t,this._cmbSrt.initialize({displayMemberPath:"key",selectedValuePath:"val"})},t.prototype._updateFormat=function(){switch(this._cmbShw.selectedValue){case E.DiffRowPct:case E.DiffColPct:this._cmbFmt.selectedValue="p0";break;default:this._cmbFmt.selectedValue="n0"}},t.prototype._updatePreview=function(){var e=this._cmbFmt.selectedValue||this._cmbFmt.text,t=i.Globalize.format,n="";if(e){var r=e[0].toLowerCase();n="nfgxc".indexOf(r)>-1?t(1234.5678,e):"p"==r?t(.12345678,e):t(this._pvDate,e)}this._cmbSmp.text=n},t.prototype._editFilter=function(){this._createFilterEditor(),i.showPopup(this._dFlt,this._btnFltEdt,!1,!1,!1),i.moveFocus(this._dFlt,0)},t.prototype._createFilterEditor=function(){var e=this;this._dFlt||(this._dFlt=document.createElement("div"),this._eFlt=new S(this._dFlt,this._fld),i.addClass(this._dFlt,"wj-dropdown-panel"),this._eFlt.lostFocus.addHandler(function(){setTimeout(function(){var t=i.Control.getControl(e._dFlt);t&&!t.containsFocus()&&e._closeFilter()},10)}),this._eFlt.finishEditing.addHandler(function(){e._closeFilter(),i.enable(e._btnFltClr,!0)}))},t.prototype._closeFilter=function(){this._dFlt&&(i.hidePopup(this._dFlt,!0),this.focus())},t.controlTemplate='<div><div class="wj-dialog-header" tabindex="-1"><span wj-part="g-dlg"></span> <span wj-part="sp-bnd"></span></div><div class="wj-dialog-body"><table style="table-layout:fixed"><tr><td wj-part="g-hdr"></td><td><div wj-part="div-hdr"></div></td></tr><tr class="wj-separator"><td wj-part="g-agg"></td><td><div wj-part="div-agg"></div></td></tr><tr class="wj-separator"><td wj-part="g-shw"></td><td><div wj-part="div-shw"></div></td></tr><tr><td wj-part="g-wfl"></td><td><div wj-part="div-wfl"></div></td></tr><tr><td wj-part="g-srt"></td><td><div wj-part="div-srt"></div></td></tr><tr class="wj-separator"><td wj-part="g-flt"></td><td><div><button wj-part="btn-flt-edt" class="wj-btn"></button>&nbsp;&nbsp;<button wj-part="btn-flt-clr" class="wj-btn"></button></div></td></tr><tr class="wj-separator"><td wj-part="g-fmt"></td><td><div wj-part="div-fmt"></div></td></tr><tr><td wj-part="g-smp"></td><td><div wj-part="div-smp" readonly tabindex="-1"></div></td></tr></table></div><div class="wj-dialog-footer"><button wj-part="btn-apply" class="wj-btn wj-hide"></button>&nbsp;&nbsp;<button wj-part="btn-cancel" class="wj-btn wj-hide"></button></div></div>',t}(i.Control);t.PivotFieldEditor=T;var S=function(e){function t(t,n,s){var o=e.call(this,t)||this;o.finishEditing=new i.Event;i.assert(null!=r,"Missing dependency: PivotFilterEditor requires wijmo.input."),o.hostElement.tabIndex=-1;var l=o.getTemplate();o.applyTemplate("wj-control wj-content wj-pivotfiltereditor",l,{_divType:"div-type",_aVal:"a-val",_aCnd:"a-cnd",_divEdtVal:"div-edt-val",_divEdtCnd:"div-edt-cnd",_btnOk:"btn-ok"}),i.setText(o._aVal,i.culture.FlexGridFilter.values),i.setText(o._aCnd,i.culture.FlexGridFilter.conditions),i.setText(o._btnOk,i.culture.olap.PivotFieldEditor.ok);var a=o._btnClicked.bind(o);return o.addEventListener(o._btnOk,"click",a),o.addEventListener(o._aVal,"click",a),o.addEventListener(o._aCnd,"click",a),o.addEventListener(o.hostElement,"keydown",function(e){switch(e.keyCode){case i.Key.Enter:switch(e.target.tagName){case"A":case"BUTTON":o._btnClicked(e);break;default:o.onFinishEditing(new i.CancelEventArgs)}e.preventDefault();break;case i.Key.Escape:o.onFinishEditing(new i.CancelEventArgs),e.preventDefault();break;case i.Key.Tab:i.moveFocus(o.hostElement,e.shiftKey?-1:1),e.preventDefault()}}),o._fld=n,o.initialize(s),o.updateEditor(),o}return __extends(t,e),Object.defineProperty(t.prototype,"field",{get:function(){return this._fld},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"filter",{get:function(){return this._fld?this._fld.filter:null},enumerable:!0,configurable:!0}),t.prototype.updateEditor=function(){var e=n.FilterType.None;this.filter&&(e=this.filter.conditionFilter.isActive||0==(this.filter.filterType&n.FilterType.Value)?n.FilterType.Condition:n.FilterType.Value,this._showFilter(e)),this._edtVal&&this._edtVal.updateEditor(),this._edtCnd&&this._edtCnd.updateEditor()},t.prototype.updateFilter=function(){switch(this._getFilterType()){case n.FilterType.Value:this._edtVal.updateFilter(),this.filter.conditionFilter.clear();break;case n.FilterType.Condition:this._edtCnd.updateFilter(),this.filter.valueFilter.clear()}this.field.onPropertyChanged(new i.PropertyChangedEventArgs("filter",null,null))},t.prototype.clearEditor=function(){this._edtVal&&this._edtVal.clearEditor(),this._edtCnd&&this._edtCnd.clearEditor()},t.prototype.onFinishEditing=function(e){return this.finishEditing.raise(this,e),!e.cancel},t.prototype._showFilter=function(e){switch(e==n.FilterType.Value&&null==this._edtVal&&(this._edtVal=new n.ValueFilterEditor(this._divEdtVal,this.filter.valueFilter)),e==n.FilterType.Condition&&null==this._edtCnd&&(this._edtCnd=new n.ConditionFilterEditor(this._divEdtCnd,this.filter.conditionFilter)),0!=(e&this.filter.filterType)&&(e==n.FilterType.Value?(this._divEdtVal.style.display="",this._divEdtCnd.style.display="none",this._enableLink(this._aVal,!1),this._enableLink(this._aCnd,!0)):(this._divEdtVal.style.display="none",this._divEdtCnd.style.display="",this._enableLink(this._aVal,!0),this._enableLink(this._aCnd,!1))),this.filter.filterType){case n.FilterType.None:case n.FilterType.Condition:case n.FilterType.Value:this._divType.style.display="none";break;default:this._divType.style.display=""}},t.prototype._enableLink=function(e,t){e.style.textDecoration=t?"":"none",e.style.fontWeight=t?"":"bold",i.setAttribute(e,"href",t?"":null)},t.prototype._getFilterType=function(){var e=n.FilterType;return"none"!=this._divEdtVal.style.display?e.Value:e.Condition},t.prototype._btnClicked=function(e){if(e.preventDefault(),e.stopPropagation(),!i.hasClass(e.target,"wj-state-disabled"))return e.target==this._aVal?(this._showFilter(n.FilterType.Value),void i.moveFocus(this._edtVal.hostElement,0)):e.target==this._aCnd?(this._showFilter(n.FilterType.Condition),void i.moveFocus(this._edtCnd.hostElement,0)):void this.onFinishEditing(new i.CancelEventArgs)},t.controlTemplate='<div><div wj-part="div-type" style="text-align:center;margin-bottom:12px;font-size:80%"><a wj-part="a-cnd" href="" tabindex="-1" draggable="false"></a>&nbsp;|&nbsp;<a wj-part="a-val" href="" tabindex="-1" draggable="false"></a></div><div wj-part="div-edt-val" tabindex="-1"></div><div wj-part="div-edt-cnd" tabindex="-1"></div><div style="text-align:right;margin-top:10px"><button wj-part="btn-ok" class="wj-btn"></button></div>',t}(i.Control);t.PivotFilterEditor=S,i._addCultureInfo("olap",{PivotEngine:{grandTotal:"Grand Total",subTotal:"Subtotal"},PivotPanel:{fields:"Choose fields to add to report:",drag:"Drag fields between areas below:",filters:"Filters",cols:"Columns",rows:"Rows",vals:"Values",defer:"Defer Updates",update:"Update"},PivotFieldEditor:{dialogHeader:"Field settings:",header:"Header:",summary:"Summary:",showAs:"Show As:",weighBy:"Weigh by:",sort:"Sort:",filter:"Filter:",format:"Format:",sample:"Sample:",edit:"Edit...",clear:"Clear",ok:"OK",cancel:"Cancel",none:"(none)",sorts:{asc:"Ascending",desc:"Descending"},aggs:{sum:"Sum",cnt:"Count",avg:"Average",max:"Max",min:"Min",rng:"Range",std:"StdDev",var:"Var",stdp:"StdDevPop",varp:"VarPop",first:"First",last:"Last"},calcs:{noCalc:"No calculation",dRow:"Difference from previous row",dRowPct:"% Difference from previous row",dCol:"Difference from previous column",dColPct:"% Difference from previous column",dPctGrand:"% of grand total",dPctRow:"% of row total",dPctCol:"% of column total",dRunTot:"Running total",dRunTotPct:"% running total"},formats:{n0:"Integer (n0)",n2:"Float (n2)",c:"Currency (c)",p0:"Percentage (p0)",p2:"Percentage (p2)",n2c:"Thousands (n2,)",n2cc:"Millions (n2,,)",n2ccc:"Billions (n2,,,)",d:"Date (d)",MMMMddyyyy:"Month Day Year (MMMM dd, yyyy)",dMyy:"Day Month Year (d/M/yy)",ddMyy:"Day Month Year (dd/M/yy)",dMyyyy:"Day Month Year (dd/M/yyyy)",MMMyyyy:"Month Year (MMM yyyy)",MMMMyyyy:"Month Year (MMMM yyyy)",yyyy:"Year (yyyy)",yyyyQq:'Year Quarter (yyyy "Q"q)',FYEEEEQU:'Fiscal Year Quarter ("FY"EEEE "Q"U)'}},_ListContextMenu:{up:"Move Up",down:"Move Down",first:"Move to Beginning",last:"Move to End",filter:"Move to Report Filter",rows:"Move to Row Labels",cols:"Move to Column Labels",vals:"Move to Values",remove:"Remove Field",edit:"Field Settings...",detail:"Show Detail..."},DetailDialog:{header:"Detail View:",ok:"OK",items:"{cnt:n0} items",item:"{cnt} item",row:"Row",col:"Column"},PivotChart:{by:"by",and:"and"},Slicer:{multiSelect:"Multi-Select",clearFilter:"Clear Filter"}});var P;!function(e){e[e.None=0]="None",e[e.GrandTotals=1]="GrandTotals",e[e.Subtotals=2]="Subtotals"}(P=t.ShowTotals||(t.ShowTotals={}));var E;!function(e){e[e.NoCalculation=0]="NoCalculation",e[e.DiffRow=1]="DiffRow",e[e.DiffRowPct=2]="DiffRowPct",e[e.DiffCol=3]="DiffCol",e[e.DiffColPct=4]="DiffColPct",e[e.PctGrand=5]="PctGrand",e[e.PctRow=6]="PctRow",e[e.PctCol=7]="PctCol",e[e.RunTot=8]="RunTot",e[e.RunTotPct=9]="RunTotPct"}(E=t.ShowAs||(t.ShowAs={}));var R=function(){function e(e){this._autoGenFields=!0,this._allowFieldEditing=!0,this._showRowTotals=P.GrandTotals,this._showColTotals=P.GrandTotals,this._totalsBefore=!1,this._sortableGroups=!0,this._showZeros=!1,this._updating=0,this._dirty=!1,this._cntTotal=0,this._cntFiltered=0,this._async=!0,this._serverParms={timeout:M._TIMEOUT,pollInterval:M._POLL_INTERVAL,maxDetail:M._MAXDETAIL},this.itemsSourceChanged=new i.Event,this.viewDefinitionChanged=new i.Event,this.updatingView=new i.Event,this.updatedView=new i.Event,this.error=new i.Event,this._pivotView=new y(this),this._fields=new C(this),this._rowFields=new C(this),this._columnFields=new C(this),this._valueFields=new C(this),this._filterFields=new C(this),this._viewLists=[this._rowFields,this._columnFields,this._valueFields,this._filterFields];var t=this._fieldListChanged.bind(this);this._fields.collectionChanged.addHandler(t),this._viewLists.forEach(function(e){e.collectionChanged.addHandler(t)}),this._defaultFilterType=null,e&&i.copy(this,e)}return Object.defineProperty(e.prototype,"itemsSource",{get:function(){return this._items},set:function(e){var t=this;this._items!=e&&(this._cv&&(this._cv.collectionChanged.removeHandler(this._cvCollectionChanged,this),this._cv=null),this._server&&(this._server.clearPendingRequests(),this._server=null),this._items=e,i.isString(e)?this._server=new M(this,e):i.isObject(e)&&!i.tryCast(e,"ICollectionView")?this._server=new O(this,e):this._cv=i.asCollectionView(e),null!=this._cv&&this._cv.collectionChanged.addHandler(this._cvCollectionChanged,this),this.deferUpdate(function(){t.autoGenerateFields&&t._generateFields(),t._updateFieldTypes()}),this.onItemsSourceChanged())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isServer",{get:function(){return null!=this._server},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"collectionView",{get:function(){return this._cv},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"pivotView",{get:function(){return this._pivotView},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"showRowTotals",{get:function(){return this._showRowTotals},set:function(e){(e=i.asEnum(e,P))!=this.showRowTotals&&(this._showRowTotals=e,this.onViewDefinitionChanged(),this.invalidate())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"showColumnTotals",{get:function(){return this._showColTotals},set:function(e){(e=i.asEnum(e,P))!=this.showColumnTotals&&(this._showColTotals=e,this.onViewDefinitionChanged(),this.invalidate())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"totalsBeforeData",{get:function(){return this._totalsBefore},set:function(e){e!=this._totalsBefore&&(this._totalsBefore=i.asBoolean(e),this.onViewDefinitionChanged(),this._updatePivotView())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"sortableGroups",{get:function(){return this._sortableGroups},set:function(e){e!=this._sortableGroups&&(this._sortableGroups=i.asBoolean(e),this.onViewDefinitionChanged())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"sortOnServer",{get:function(){return this._sortOnServer},set:function(e){this._sortOnServer=i.asBoolean(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"showZeros",{get:function(){return this._showZeros},set:function(e){e!=this._showZeros&&(this._showZeros=i.asBoolean(e),this.onViewDefinitionChanged(),this._updatePivotView())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"defaultFilterType",{get:function(){return null!=this._defaultFilterType?this._defaultFilterType:this._server?n.FilterType.Condition:n.FilterType.Both},set:function(e){this._defaultFilterType=i.asEnum(e,n.FilterType)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"autoGenerateFields",{get:function(){return this._autoGenFields},set:function(e){this._autoGenFields=i.asBoolean(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"allowFieldEditing",{get:function(){return this._allowFieldEditing},set:function(e){this._allowFieldEditing=i.asBoolean(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"fields",{get:function(){return this._fields},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rowFields",{get:function(){return this._rowFields},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"columnFields",{get:function(){return this._columnFields},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"filterFields",{get:function(){return this._filterFields},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"valueFields",{get:function(){return this._valueFields},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"viewDefinition",{get:function(){var e=this,t={showZeros:this.showZeros,showColumnTotals:this.showColumnTotals,showRowTotals:this.showRowTotals,defaultFilterType:this.defaultFilterType,totalsBeforeData:this.totalsBeforeData,sortableGroups:this.sortableGroups,fields:[],rowFields:this._getFieldCollectionProxy(this.rowFields),columnFields:this._getFieldCollectionProxy(this.columnFields),filterFields:this._getFieldCollectionProxy(this.filterFields),valueFields:this._getFieldCollectionProxy(this.valueFields)};return this.fields.forEach(function(i){var n=e._getFieldDefinition(i);t.fields.push(n)}),JSON.stringify(t)},set:function(t){var n=this,r=JSON.parse(t);r&&this.deferUpdate(function(){n._copyProps(n,r,e._props),n.fields.clear(),r.fields.forEach(function(e){var t=n._getFieldFromDefinition(e);n.fields.push(t)}),r.fields.forEach(function(e,t){i.isString(e.weightField)&&(n.fields[t].weightField=n.fields.getField(e.weightField))}),n._setFieldCollectionProxy(n.rowFields,r.rowFields),n._setFieldCollectionProxy(n.columnFields,r.columnFields),n._setFieldCollectionProxy(n.filterFields,r.filterFields),n._setFieldCollectionProxy(n.valueFields,r.valueFields)})},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isViewDefined",{get:function(){var e=this._valueFields.length,t=this._rowFields.length,i=this._columnFields.length;return this._server?e>0&&(t>0||i>0):e>0||t>0||i>0},enumerable:!0,configurable:!0}),e.prototype.beginUpdate=function(){this.cancelPendingUpdates(),this._updating++},e.prototype.endUpdate=function(){this._updating--,this._updating<=0&&(this.onViewDefinitionChanged(),this.refresh())},Object.defineProperty(e.prototype,"isUpdating",{get:function(){return this._updating>0},enumerable:!0,configurable:!0}),e.prototype.deferUpdate=function(e){try{this.beginUpdate(),e()}finally{this.endUpdate()}},e.prototype.refresh=function(e){void 0===e&&(e=!1),this.isUpdating&&!e||this._updateView()},e.prototype.invalidate=function(){var e=this;this._toInv&&(this._toInv=clearTimeout(this._toInv)),this.isUpdating||(this._toInv=setTimeout(function(){e.refresh()},i.Control._REFRESH_INTERVAL))},Object.defineProperty(e.prototype,"async",{get:function(){return this._async},set:function(e){e!=this._async&&(this.cancelPendingUpdates(),this._async=i.asBoolean(e))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"serverTimeout",{get:function(){return this._serverParms.timeout},set:function(e){this._serverParms.timeout=i.asNumber(e,!1,!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"serverPollInterval",{get:function(){return this._serverParms.pollInterval},set:function(e){this._serverParms.pollInterval=i.asNumber(e,!1,!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"serverMaxDetail",{get:function(){return this._serverParms.maxDetail},set:function(e){this._serverParms.maxDetail=i.asNumber(e,!1,!0)},enumerable:!0,configurable:!0}),e.prototype.cancelPendingUpdates=function(){this._toUpdateTallies&&(clearTimeout(this._toUpdateTallies),this._toUpdateTallies=null)},e.prototype.getDetail=function(e,t){var i=this,n=e?e[v._ROW_KEY_NAME]:null,r=this._getKey(t);if(this._server)return this._server.getDetail(n,r);var s=[];return this.collectionView.items.forEach(function(e){!i._applyFilter(e)||null!=n&&!n.matchesItem(e)||null!=r&&!r.matchesItem(e)||s.push(e)}),s},e.prototype.getDetailView=function(e,t){var n=this.getDetail(e,t);return new i.CollectionView(n)},e.prototype.getKeys=function(e,t){var i=e?e[v._ROW_KEY_NAME]:null,n=this._getKey(t);return{rowKey:{fields:i?i.fieldNames:[],values:i?i.values:[]},colKey:{fields:n?n.fieldNames:[],values:n?n.values:[]}}},e.prototype.editField=function(e){if(this.allowFieldEditing){var t=new T(document.createElement("div"),{field:e});new r.Popup(document.createElement("div"),{content:t.hostElement}).show(!0)}},e.prototype.removeField=function(e){for(var t=0;t<this._viewLists.length;t++){var i=this._viewLists[t],n=i.indexOf(e);if(n>-1)return void i.removeAt(n)}},e.prototype.onItemsSourceChanged=function(e){this.itemsSourceChanged.raise(this,e)},e.prototype.onViewDefinitionChanged=function(e){this._updating||this.viewDefinitionChanged.raise(this,e)},e.prototype.onUpdatingView=function(e){this.updatingView.raise(this,e)},e.prototype.onUpdatedView=function(e){this.updatedView.raise(this,e)},e.prototype.onError=function(e){return this.error.raise(this,e),!e.cancel},e.prototype._copy=function(e,t){var n=this;switch(e){case"fields":return this.fields.clear(),this._viewLists.forEach(function(e){e.clear()}),i.asArray(t).forEach(function(e){var t=n._createField(e,!1);n.fields.push(t)}),this._updateFieldTypes(),!0;case"rowFields":case"columnFields":case"valueFields":case"filterFields":return this[e].clear(),i.isArray(t)||(this[e].maxItems=t.maxItems,t=t.items),i.asArray(t).forEach(function(t){var i=n.fields.getField(t);n[e].push(i)}),!0}return!1},e.prototype._getKey=function(e){return this._keys[e]},e.prototype._getRowLevel=function(e){if(i.isNumber(e)){var t=this._pivotView.items[e];e=t?t[v._ROW_KEY_NAME]:null}return e?e.level:-1},e.prototype._getColLevel=function(e){return i.isNumber(e)&&(e=this._colBindings[e]),i.isString(e)&&(e=this._getKey(e)),i.assert(null==e||e instanceof v,"invalid parameter in call to _getColLevel"),e?e.level:-1},e.prototype._applyFilter=function(e){for(var t=this._activeFilterFields,i=0;i<t.length;i++)if(!t[i].filter.apply(e))return!1;return!0},e.prototype._updateView=function(){var e=this;this.cancelPendingUpdates(),this._cntTotal=this._cntFiltered=0,this._tallies={},this._keys={},this._activeFilterFields=[],this._server&&this.isViewDefined?this._server.getOutputView(function(t){e.isViewDefined&&(e._server.updateTallies(t),e._updatePivotView())}):(this._viewLists.forEach(function(t){t.forEach(function(t){t.filter.isActive&&e._activeFilterFields.push(t)})}),this.isViewDefined&&i.hasItems(this._cv)?(this._batchStart=Date.now(),this._updateTallies(this._cv.items,0)):this._updatePivotView())},e.prototype._updateTallies=function(t,i){var n=this,r=t.length,s=new m(this._rowFields,0,null,-1,null),o=this.valueFields;0==o.length&&this.columnFields.length>0&&(o=new C(this)).push(new b(this,""));for(var l=P,a=this._rowFields.length,d=this._getShowRowTotals(),h=d==l.None?a:0,u=d==l.GrandTotals?Math.max(1,a):1,c=this._columnFields.length,p=this._getShowColTotals(),g=p==l.None?c:0,_=p==l.GrandTotals?Math.max(1,c):1,v=o.length,y=this,w=i;w<r;w++){var F=function(r){if(y._async&&r-i>=e._BATCH_SIZE&&Date.now()-y._batchStart>e._BATCH_DELAY)return y._toUpdateTallies=setTimeout(function(){n.onUpdatingView(new D(Math.round(r/t.length*100))),n._batchStart=Date.now(),n._updateTallies(t,r)},e._BATCH_TIMEOUT),{value:void 0};y._cntTotal++;var l=t[r];if(!y._activeFilterFields.length||y._applyFilter(l)){y._cntFiltered++;for(var d=h;d<=a;d+=u){var p=s.getNode(y._rowFields,d,null,-1,l),m=p.key,b=m.toString(),w=y._tallies[b];w||(y._keys[b]=m,y._tallies[b]=w={});for(var F=g;F<=c;F+=_)for(var C=0;C<v;C++){var x=p.tree.getNode(y._columnFields,F,o,C,l).key,T=x.toString(),S=w[T];S||(y._keys[T]=x,S=w[T]=new f);var P=o[C],E=P._getValue(l,!1),R=P._weightField?P._getWeight(l):null;S.add(E,R)}}}}(w);if("object"==typeof F)return F.value}this._toUpdateTallies=null,this._updatePivotView()},e.prototype._updatePivotView=function(){var e=this;this._pivotView.deferUpdate(function(){e.onUpdatingView(new D(100));var t=e._pivotView.sourceCollection;t.length=0;var i={};for(var n in e._tallies)i[n]=!0;var r={};for(var n in e._tallies){u=e._tallies[n];for(var s in u)r[s]=!0}for(var o=e._server&&e.sortOnServer,l=e._getSortedKeys(i,o),a=e._getSortedKeys(r,o),d=0;d<l.length;d++){var h=l[d],u=e._tallies[h],c={};c[v._ROW_KEY_NAME]=e._getKey(h);for(var p=0;p<a.length;p++){var g=a[p],_=u[g],f=e._getKey(g),m=_?_.getAggregate(f.aggregate):null;0!=m||e._showZeros||(m=null),c[g]=m}t.push(c)}e._colBindings=a,e._updateFieldValues(t),e._pivotView.sortDescriptions.clear(),e.onUpdatedView()})},e.prototype._getSortedKeys=function(e,t){var i=this,n=Object.keys(e);return t||n.sort(function(e,t){return i._keys[e].compareTo(i._keys[t])}),n},e.prototype._updateFieldValues=function(e){for(var t=this.valueFields.length,n=this,r=0;r<t;r++)!function(r){var s=n.valueFields[r];switch(s.showAs){case E.RunTot:case E.RunTotPct:for(h=r;h<n._colBindings.length;h+=t){for(g=0;g<e.length;g++)(u=e[g])[_=n._colBindings[h]]=n._getRunningTotal(e,g,h,s.showAs);if(s.showAs==E.RunTotPct)for(g=0;g<e.length;g++){var o=(u=e[g])[_=n._colBindings[h]];if(i.isNumber(o)){var l=n._getLastValueInRowGroup(e,g,h);0!=l&&(u[_]=o/l)}}}break;case E.PctGrand:case E.PctCol:var a=0;if(s.showAs==E.PctGrand)for(h=r;h<n._colBindings.length;h+=t)-1==n._getColLevel(h)&&(a+=n._getColTotal(e,h));for(var d=function(t){s.showAs==E.PctCol&&(a=n._getColTotal(e,t));var r=n._colBindings[t];e.forEach(function(e,t){var n=e[r];i.isNumber(n)&&(e[r]=0!=a?n/a:null)})},h=r;h<n._colBindings.length;h+=t)d(h);break;case E.PctRow:for(g=0;g<e.length;g++){for(var u=e[g],c=0,h=r;h<n._colBindings.length;h+=t)-1==n._getColLevel(h)&&(p=u[_=n._colBindings[h]],i.isNumber(p)&&(c+=p));for(h=r;h<n._colBindings.length;h+=t){var p=u[_=n._colBindings[h]];i.isNumber(p)&&(u[_]=0!=c?p/c:null)}}break;case E.DiffRow:case E.DiffRowPct:for(h=r;h<n._colBindings.length;h+=t)for(g=e.length-1;g>=0;g--)(u=e[g])[_=n._colBindings[h]]=n._getRowDifference(e,g,h,s.showAs);break;case E.DiffCol:case E.DiffColPct:for(var g=0;g<e.length;g++)for(h=n._colBindings.length-t+r;h>=0;h-=t){var u=e[g],_=n._colBindings[h];u[_]=n._getColDifference(e,g,h,s.showAs)}}}(r)},e.prototype._getColTotal=function(e,t){var n=this,r=this._colBindings[t],s=0;return e.forEach(function(e,t){if(-1==n._getRowLevel(t)){var o=e[r];i.isNumber(o)&&(s+=o)}}),s},e.prototype._getRunningTotal=function(e,t,i,n){var r=this._getRowLevel(t);if(0==r)return null;for(var s=this._colBindings[i],o=e[t][s],l=this._getShowRowTotals(),a=this.rowFields.length-2,d=t-1;d>=0;d--){var h=this._getRowLevel(d);if(h==r){if(a>-1&&r<0&&l!=P.Subtotals){var u=e[t].$rowKey,c=e[d].$rowKey;if(u.values[a]!=c.values[a])return null}o+=e[d][s];break}if(h>r)break}return o},e.prototype._getLastValueInRowGroup=function(e,t,i){for(var n=this._colBindings[i],r=e[t][n],s=this._getRowLevel(t),o=this.rowFields.length-2,l=this._getShowRowTotals(),a=t+1;a<e.length;a++){var d=this._getRowLevel(a);if(d==s){if(o>-1&&s<0&&l!=P.Subtotals){var h=e[t].$rowKey,u=e[a].$rowKey;if(h.values[o]!=u.values[o])return r}r=e[a][n]}if(d>s)break}return r},e.prototype._getRowDifference=function(e,t,i,n){var r=this._getRowLevel(t);if(0==r)return null;for(var s=this.rowFields.length-2,o=this._getShowRowTotals(),l=t-1;l>=0;l--){var a=this._getRowLevel(l);if(a==r){if(s>-1&&r<0&&o!=P.Subtotals){var d=e[t].$rowKey,h=e[l].$rowKey;if(d.values[s]!=h.values[s])return null}var u=this._colBindings[i],c=e[t][u],p=e[l][u],g=c-p;return n==E.DiffRowPct&&(g/=p),g}if(a>r)break}return null},e.prototype._getColDifference=function(e,t,i,n){var r=this._getColLevel(i);if(0==r)return null;for(var s=this.valueFields.length,o=this.columnFields.length-2,l=this._getShowColTotals(),a=i-s;a>=0;a-=s){var d=this._getColLevel(a);if(d==r){if(o>-1&&r<0&&l!=P.Subtotals){var h=this._getKey(this._colBindings[i]),u=this._getKey(this._colBindings[a]);if(h.values[o]!=u.values[o])return null}var c=e[t],p=c[this._colBindings[i]],g=c[this._colBindings[a]],_=p-g;return n==E.DiffColPct&&(_/=g),_}if(d>r)break}return null},e.prototype._getShowRowTotals=function(){return this._valueFields.length?this._showRowTotals:P.None},e.prototype._getShowColTotals=function(){return this._valueFields.length?this._showColTotals:P.None},e.prototype._generateFields=function(){var e=this;this._viewLists.forEach(function(e){e.clear()});for(var t=0;t<this.fields.length;t++)(d=this.fields[t])._autoGenerated&&(this.fields.removeAt(t),t--);if(this._server)this._server.getFields().forEach(function(t){var i=e._createField(t,!0);e.fields.getField(i.header)||e.fields.push(i)});else{var n=this.collectionView,r=n?n.sourceCollection:null,s=r?r[0]:null;if(s&&this.autoGenerateFields)for(var o in s)for(var l=null,a=0;a<r.length&&a<1e3&&null==l;a++)if(l=r[a][o],i.isPrimitive(l)){var d=this._createField({binding:o,header:i.toHeaderCase(o),dataType:i.getType(l)},!0);this.fields.getField(d.header)||this.fields.push(d)}}},e.prototype._updateFieldTypes=function(){var e=this,t=this.collectionView,i=t?t.sourceCollection:null;i&&i.length&&this.fields.forEach(function(t){e._updateFieldType(t,i)})},e.prototype._updateFieldType=function(e,t){var n=this;if(e._hasSubFields())e.subFields.forEach(function(e){n._updateFieldType(e,t)});else if(null==e.dataType&&e.binding)for(var r=0;r<t.length&&r<1e3;r++){var s=e._binding.getValue(t[r]);if(null!=s){e.dataType=i.isPrimitive(s)?i.getType(s):null;break}}},e.prototype._createField=function(e,t){var n;return i.isString(e)?n=new b(this,e):e&&(e.key&&delete e.key,n=null!=e.dimensionType?new w(this,e.binding,e.header,e):new b(this,e.binding,e.header,e),null!=e.dataType&&(n.dataType=e.dataType)),n._autoGenerated=t,(t||i.isString(e))&&(n.format=n.dataType==i.DataType.Date?"d":"n0",n.aggregate=n.dataType==i.DataType.Number?i.Aggregate.Sum:i.Aggregate.Cnt),e&&!i.isString(e)&&i.copy(n,e),n},e.prototype._cvCollectionChanged=function(e,t){this.invalidate()},e.prototype._fieldListChanged=function(e,t){if(t.action==i.NotifyCollectionChangedAction.Add){for(var n=e,r=0;r<n.length-1;r++)if(n[r].key)for(var s=r+1;s<n.length;s++)n[r].key==n[s].key&&(n.removeAt(s),s--);if(n!=this._fields)if(this._fields.getField(t.item.key)){for(r=0;r<this._viewLists.length;r++)if(this._viewLists[r]!=n){var o=this._viewLists[r];(l=o.indexOf(t.item))>-1&&o.removeAt(l)}}else n.removeAt(t.index);if(i.isNumber(n.maxItems)&&n.maxItems>-1)for(;n.length>n.maxItems;){var l=n.length-1;n[l]==t.item&&l>0&&l--,n.removeAt(l)}}this.onViewDefinitionChanged(),this.invalidate()},e.prototype._fieldPropertyChanged=function(e,t){if(this.onViewDefinitionChanged(),e.isActive){var i=t.propertyName;"visible"!=i&&("width"!=i&&"wordWrap"!=i&&"isContentHtml"!=i?"format"==i&&this.valueFields.indexOf(e)>-1?this._pivotView.refresh():"showAs"!=i?"descending"!=i?"aggregate"!=i?this.invalidate():this.valueFields.indexOf(e)>-1&&!this.isUpdating&&(this._server?this._updateView():this._updatePivotView()):this._updatePivotView():this.valueFields.indexOf(e)>-1&&!this.isUpdating&&this._updatePivotView():this._pivotView.refresh())}},e.prototype._copyProps=function(e,t,i){for(var n=0;n<i.length;n++){var r=i[n];null!=t[r]&&(e[r]=t[r])}},e.prototype._getFieldFromDefinition=function(e){var t=e.filter;e.filter&&delete e.filter;var i=this._createField(e,!0);return t&&(this._setFilterProxy(i,t),e.filter=t),i},e.prototype._getFieldDefinition=function(e){var t=this,i={binding:e.binding,header:e.header,dataType:e.dataType,aggregate:e.aggregate,showAs:e.showAs,descending:e.descending,format:e.format,width:e.width,wordWrap:e.wordWrap,isContentHtml:e.isContentHtml};return e.weightField&&(i.weightField=e.weightField._getName()),e.key&&(i.key=e.key),e.filter.isActive&&(i.filter=this._getFilterProxy(e)),e._hasSubFields()&&(i.subFields=[],e.subFields.forEach(function(e){i.subFields.push(t._getFieldDefinition(e))})),e instanceof w&&(i.dimensionType=e.dimensionType),i},e.prototype._getFieldCollectionProxy=function(e){var t={items:[]};i.isNumber(e.maxItems)&&e.maxItems>-1&&(t.maxItems=e.maxItems);for(var n=0;n<e.length;n++){var r=e[n];t.items.push(r.key)}return t},e.prototype._setFieldCollectionProxy=function(e,t){e.clear(),e.maxItems=i.isNumber(t.maxItems)?t.maxItems:null;for(var n=0;n<t.items.length;n++)e.push(t.items[n])},e.prototype._getFilterProxy=function(e){var t=e.filter;if(t.conditionFilter.isActive){var n=t.conditionFilter,r={type:"condition",condition1:{operator:n.condition1.operator,value:n.condition1.value},and:n.and,condition2:{operator:n.condition2.operator,value:n.condition2.value}};return n.condition1.isActive||delete r.condition1,n.condition2.isActive||delete r.condition2,r}if(t.valueFilter.isActive){var s=t.valueFilter;return{type:"value",filterText:s.filterText,showValues:s.showValues}}return i.assert(!1,"inactive filters shouldn't be persisted."),null},e.prototype._setFilterProxy=function(e,t){var n=e.filter;switch(n.clear(),t.type){case"condition":var r=n.conditionFilter;if(t.condition1){s=i.changeType(t.condition1.value,e.dataType,e.format);r.condition1.value=s||t.condition1.value,r.condition1.operator=t.condition1.operator}if(i.isBoolean(t.and)&&(r.and=t.and),t.condition2){var s=i.changeType(t.condition2.value,e.dataType,e.format);r.condition2.value=s||t.condition2.value,r.condition2.operator=t.condition2.operator}break;case"value":var o=n.valueFilter;o.filterText=t.filterText,o.showValues=t.showValues}},e._BATCH_SIZE=1e4,e._BATCH_TIMEOUT=0,e._BATCH_DELAY=100,e._props=["showZeros","showRowTotals","showColumnTotals","totalsBeforeData","sortableGroups","defaultFilterType"],e}();t.PivotEngine=R;var D=function(e){function t(t){var n=e.call(this)||this;return n._progress=i.asNumber(t),n}return __extends(t,e),Object.defineProperty(t.prototype,"progress",{get:function(){return this._progress},enumerable:!0,configurable:!0}),t}(i.EventArgs);t.ProgressEventArgs=D;var A=function(){function e(e,t){this._ng=null,this._cubeName=null,this._ng=e,this._cubeName=t}return e.prototype.buildQuery=function(){var e=new G,t=this.buildWhereSection(this._ng.valueFields);return e.append("SELECT ",this.buildAxes()," FROM ",this.buildCubeName(),t),e.append(" CELL PROPERTIES VALUE, FORMAT_STRING"),e.toString()},e.prototype.buildWhereSection=function(e){var t=new G;return 1==e.length&&(t.append(this.buildSetForMeasuresShelf(e)),t.wrap(" WHERE ","")),t.toString()},e.prototype.buildCubeName=function(){var e=new G;e.append(this.buildSubcubeExpression());var t=e.length>0;return t&&e.wrap("SELECT "," FROM "),e.append("[",this._cubeName,"]"),t&&e.wrap("(",")"),e.toString()},e.prototype.buildSubcubeExpression=function(){var e=new G,t=this.getMeasureFilterExpressions(this._ng.valueFields),i=this.buildFilterAttributeSet(this._ng.filterFields),n=this.buildFilterAttributeSet(this._ng.rowFields,t),r=this.buildFilterAttributeSet(this._ng.columnFields,0==n.length?t:null);return e.joinItemToList(i),e.joinItemToList(n),e.joinItemToList(r),e.length>0&&(e.wrap("(",")"),e.append(" ON COLUMNS")),e.toString()},e.prototype.buildFilterAttributeSet=function(e,t){for(var i=new G,n=0;n<e.length;n++){var r=e[n],s=this.buildFilterString(r,0==n?t:null);i.joinItemToList(s)}return i.toString()},e.prototype.buildFilterString=function(e,t){var i=new G;return e.filter.isActive?e.filter.filterType==n.FilterType.Condition&&i.append(this.getConditionFilterString(e,t)):t&&i.append(this.getConditionFilterString(e,t)),i.toString()},e.prototype.getConditionFilterString=function(e,t){var i=new G,n=e.key+".LEVELS(1).ALLMEMBERS",r=e.filter.conditionFilter.condition1,s=e.filter.conditionFilter.condition2;return r.isActive&&(i.append(this.getConditionFilterExpression(e,r)),s.isActive&&i.append(e.filter.conditionFilter.and?" AND ":" OR ")),s.isActive&&i.append(this.getConditionFilterExpression(e,s)),t&&t.length>0&&(i.length>0&&i.append(" AND "),i.append(t.join(" AND "))),i.length>0&&i.wrap("Filter("+n+",(","))"),i.toString()},e.prototype.getMeasureFilterExpressions=function(e){for(var t=[],i=0;i<e.length;i++){var n=new G,r=e[i],s=(r.dimensionType,F.Measure,r.filter.conditionFilter.condition1),o=r.filter.conditionFilter.condition2;s.isActive&&(n.append(this.getConditionFilterExpression(r,s)),o.isActive&&n.append(r.filter.conditionFilter.and?" AND ":" OR ")),o.isActive&&n.append(this.getConditionFilterExpression(r,o)),n.length>0&&(n.wrap("(",")"),t.push(n.toString()))}return t},e.prototype.getConditionFilterExpression=function(e,t){if(!t.isActive)return"";var r=e.dimensionType==F.Measure,s=e.dataType==i.DataType.Number,o=e.dataType==i.DataType.Date,l=s||o?"member_value":"member_caption",a=r?e.key:e.key+".CurrentMember."+l,d=o?"CDate('"+i.Globalize.formatDate(t.value,"d")+"')":t.value.toString(),h=new G;switch(t.operator){case n.Operator.BW:h.append("(Left(",a,",",d.length.toString(),')="',d,'")');break;case n.Operator.EW:h.append("(Right(",a,",",d.length.toString(),')="',d,'")');break;case n.Operator.EQ:r||s||o?h.append("(",a,")=",d):h.append("(",a,')="',d,'"');break;case n.Operator.NE:r||s||o?h.append("(",a,")<>",d):h.append("(",a,')<>"',d,'"');break;case n.Operator.CT:h.append("(InStr(1,",a,',"',d,'")>0)');break;case n.Operator.NC:h.append("(InStr(1,",a,',"',d,'")=0))');break;case n.Operator.GT:h.append("(",a,")>",d);break;case n.Operator.LT:h.append("(",a,")<",d);break;case n.Operator.GE:h.append("(",a,")>=",d);break;case n.Operator.LE:h.append("(",a,")<=",d)}return h.toString()},e.prototype.buildAxes=function(){var e=new G,t=this.buildSetForAttributesShelf(this._ng.rowFields);return e.joinItemToList(t),this._ng.rowFields.length>0&&(this._ng.columnFields.length>0||this._ng.valueFields.length>1?e.append(" ON ROWS"):e.append(" ON COLUMNS")),t=this.buildSetForAttributesColumnShelf(this._ng.columnFields),e.joinItemToList(t),this._ng.columnFields.length>0&&e.append(" ON COLUMNS"),this._ng.valueFields.length>1&&0==this._ng.columnFields.length&&(t=this.buildSetForMeasuresShelf(this._ng.valueFields),e.joinItemToList(t),e.append(" ON COLUMNS")),e.toString()},e.prototype.buildSetForAttributesShelf=function(e){for(var t=new G,i=0;i<e.length;i++){var n=e[i];n.dimensionType!=F.Attribute&&n.dimensionType!=F.Hierarchy||t.joinItemToList(this.buildAttributeSetForAxis(n)),i>0&&t.wrap("CrossJoin(",")")}return t.wrap("NON EMPTY ",""),t.toString()},e.prototype.buildSetForAttributesColumnShelf=function(e){for(var t=new G,i=0;i<e.length;i++){var n=e[i];n.dimensionType!=F.Attribute&&n.dimensionType!=F.Hierarchy||t.joinItemToList(this.buildAttributeSetForAxis(n))}return this._ng.valueFields.length>1&&e.length>0&&t.joinItemToList(this.buildSetForMeasuresShelf(this._ng.valueFields)),(this._ng.valueFields.length>1&&e.length>0||e.length>1)&&t.wrap("CrossJoin(",")"),t.wrap("NON EMPTY ",""),t.toString()},e.prototype.buildSetForMeasuresShelf=function(e){for(var t=new G,i=0;i<e.length;i++){var n=e[i];n.dimensionType!=F.Measure&&n.dimensionType!=F.Kpi||t.joinItemToList(this.buildMeasureSetForAxis(n))}return t.wrap("{","}"),t.toString()},e.prototype.buildAttributeSetForAxis=function(e){var t=new G;return e.dimensionType==F.Hierarchy&&(t.append(e.key),t.append(".ALLMEMBERS"),t.wrap("{","}"),t.wrap("HIERARCHIZE(",")")),t.toString()},e.prototype.buildMeasureSetForAxis=function(e){var t=new G;return e.dimensionType!=F.Measure&&e.dimensionType!=F.Kpi||t.append(e.key),t.toString()},e}();t._MdxQueryBuilder=A;var M=function(){function e(e,t){this._ng=i.asType(e,R),i.assert(this._isValidUrl(t),"Invalid service Url: "+t+")")}return e.prototype.getFields=function(){var e=this,t=null;return i.httpRequest(this._getUrl("Fields"),{async:!1,success:function(e){t=JSON.parse(e.responseText),i.isArray(t)||console.error("Failed to get fields from server: "+e.responseText)},error:function(t){e._handleError("Getting Fields",t)}}),t},e.prototype.getOutputView=function(e){var t=this;this.clearPendingRequests(),this._sendHttpRequest("Analyses",{method:"POST",data:{view:this._ng.viewDefinition},success:function(i){var n=JSON.parse(i.responseText);t._token=n.token,t._start=Date.now(),t._handleResult(n.status,e)},error:function(e){t._handleError("Analyses",e)}})},e.prototype.getDetail=function(t,n){for(var r,s=[],o=this._ng.rowFields.length,l=t?t.values.length:0,a=0;a<o;a++)a<l?s.push(e._getRequestedValue(t.values[a])):s.push(null);o=this._ng.columnFields.length,l=n?n.values.length:0;for(a=0;a<o;a++)a<l?s.push(e._getRequestedValue(n.values[a])):s.push(null);return r=new i.ObservableArray,this._loadArray("Detail",r,{method:"POST",view:this._ng.viewDefinition,keys:s,max:this._ng.serverMaxDetail}),r},e._getRequestedValue=function(e){if(i.isDate(e)){var t=e;return new Date(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()))}return e},e.prototype.clearPendingRequests=function(){this._clearRequest(),this._clearTimeout(),this._clearToken()},e.prototype.updateTallies=function(e){var t=this,i=this._ng,n=i.rowFields.length,r=i.columnFields.length,s=i.valueFields.length,o=new m(i.rowFields,0,null,-1,null),l=null,a=0,d=function(e,d,h){var u=t._getAggregatedFieldCount(e,i.rowFields),c=o.getNode(i.rowFields,n-u,null,-1,e),p=c.key,g=p.toString(),_=p.toString(a>0?a:null),f=i._tallies[_];f||(g!==l&&(a=0,_=g),l=g,i._keys[_]=p,i._tallies[_]=f={}),u=t._getAggregatedFieldCount(e,i.columnFields);for(var v=0;v<s;v++){var m=c.tree.getNode(i.columnFields,r-u,i.valueFields,v,e).key,y=m.toString(),b=i.valueFields[v],w=f[y];if(w)return!1;i._keys[y]=m,(w=f[y]=new j).add(t._getFieldValue(b,e,!1))}return!0};e.forEach(function(e,t,i){d(e)||(a++,d(e))})},e.prototype._getFieldValue=function(e,t,n){var r=t[e.key];return n&&"string"!=typeof r?i.Globalize.format(r,e.format):r},e.prototype._getAggregatedFieldCount=function(e,t){for(var i=t.length,n=0,r=0;r<i;r++){var s=t[r];null==this._getFieldValue(s,e,!1)&&n++}return n},e.prototype._loadArray=function(e,t,n){var r=this;n||(n={}),null==n.skip&&(n.skip=0),null==n.top&&(n.top=100);var s=i.isNumber(n.max)?n.max:1e6;this._request=i.httpRequest(this._getUrl(e),{data:n,method:n.method||"GET",success:function(i){var o=JSON.parse(i.responseText);t.deferUpdate(function(){o.value.forEach(function(e){t.push(e)})}),o.value.length==n.top&&t.length<s&&(n.skip+=n.top,r._loadArray(e,t,n))},error:function(t){r._handleError(e,t)}})},e.prototype._getUrl=function(e,t,n){void 0===t&&(t=this._token);var r=this._ng.itemsSource.toString(),s=r.lastIndexOf("/");r.substr(0,s);switch(e=e.toLowerCase()){case"rawdata":case"detail":return r;case"fields":case"analyses":return r+"/"+e;case"clear":return r+"/analyses/"+t+"/";case"result":case"status":return r+"/analyses/"+t+"/"+e;case"uniquevalues":return r+"/fields/"+n+"/"+e}i.assert(!1,"Unrecognized command")},e.prototype._isValidUrl=function(e){var t=document.createElement("a");return t.href=i.asString(e),t.href=t.href,t.protocol&&t.hostname&&t.pathname&&"/"!=e[e.length-1]},e.prototype._handleResult=function(e,t){var i=this;switch(e.executingStatus.toLowerCase()){case"executing":case"notset":if(Date.now()-this._start>this._ng.serverTimeout)return void this._handleError("Analyses",{status:500,statusText:"Analysis timed out"});this._progress=e.progress,this._ng.onUpdatingView(new D(this._progress)),this._clearTimeout(),this._toGetStatus=setTimeout(function(){i._waitUntilComplete(t)},this._ng.serverPollInterval);break;case"completed":this._progress=100,this._ng.onUpdatingView(new D(this._progress)),this._getResults(t);break;case"exception":this._getResults(t);break;default:this._handleError("Analyses",{status:500,statusText:"Unexpected result..."})}},e.prototype._waitUntilComplete=function(e){var t=this;this._sendHttpRequest("Status",{success:function(i){var n=JSON.parse(i.responseText);t._handleResult(n,e)},error:function(e){t._handleError("Status",e)}})},e.prototype._getResults=function(e){var t=this;this._sendHttpRequest("Result",{success:function(n){t._clearToken();var r=JSON.parse(n.responseText);i.assert(i.isArray(r),"Result array Expected.");var s=[];t._ng._viewLists.forEach(function(e){s=s.concat(e.filter(function(e){return e.dataType==i.DataType.Date}))}),s.length>0&&r.forEach(function(e){s.forEach(function(t){var n=t._binding,r=n.getValue(e);i.isString(r)&&n.setValue(e,new Date(r))})}),i.asFunction(e)(r)},error:function(e){t._handleError("Result",e)}})},e.prototype._handleError=function(e,t){this.clearPendingRequests(),e='** HttpRequest error on command "'+e+'"',this._ng.onError(new i.RequestErrorEventArgs(t,e))&&this._throwResponseError(e,t)},e.prototype._throwResponseError=function(e,t){e=e+"\r\n"+t.status+"\r\n";var i=t.responseText||"";throw 500==t.status&&t.responseText&&(i=JSON.parse(t.responseText).ExceptionMessage),e+=i||t.statusText},e.prototype._sendHttpRequest=function(e,t){var n=this._getUrl(e);this._request=i.httpRequest(n,t)},e.prototype._clearToken=function(){this._token&&(this._clearRequest(),this._clearTimeout(),this._sendHttpRequest("Clear",{method:"DELETE"}),this._token=null)},e.prototype._clearRequest=function(){this._request&&4!=this._request.readyState&&(this._request.abort(),this._request=null)},e.prototype._clearTimeout=function(){this._toGetStatus&&(clearTimeout(this._toGetStatus),this._toGetStatus=null)},e._TIMEOUT=6e4,e._POLL_INTERVAL=500,e._MAXDETAIL=1e3,e}();t._ServerConnection=M;var j=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.add=function(e,t){i.assert(0==this._cnt,"Server tallies have a single value."),this._aggregatedValue=e},t.prototype.getAggregate=function(e){return this._aggregatedValue},t}(f),O=function(e){function t(t,n){var r=e.call(this,t,n.url)||this;return r._jsonResult=null,r._dataTypes=null,r._debug=!1,i.assert(i.isString(n.cube)&&!i.isNullOrWhiteSpace(n.cube),"Cube name required."),r._cubeName=n.cube,r._url=n.url,r}return __extends(t,e),t.prototype.getFields=function(){this._getSession();return this._jsonResult=null,this._dataTypes=null,this._getProperties(this._token),this._getDimensions(this._token),this._endSession(),this._jsonResult},t.prototype.getOutputView=function(e){this._ng.onUpdatingView(new D(0));var t=this,n=new A(this._ng,this._cubeName).buildQuery();this._jsonResult=[],this._getSession(),this._execQuery(this._token,n,function(n){i.asFunction(e)(t._jsonResult),t._ng.onUpdatingView(new D(100))})},t.prototype.getDetail=function(e,t){throw"getDetail method not supported"},t.prototype._getSession=function(){var e=this,t=this._url;return i.httpRequest(t,{async:!1,data:V,method:"POST",requestHeaders:{"Content-Type":"text/xml"},success:function(t){var i=t.responseXML.getElementsByTagName("Session");e._token=i[0].getAttribute("SessionId")},error:function(t){e._handleError("Begin Session",t)}})},t.prototype._endSession=function(){var e=this,t=this._url;return i.httpRequest(t,{async:!1,data:k(e._token),method:"POST",requestHeaders:{"Content-Type":"text/xml"},error:function(t){e._handleError("End Session",t)},complete:function(t){e._token=void 0}})},t.prototype._getProperties=function(e){var t=this,n=this._url;return i.httpRequest(n,{async:!1,data:B(e,t._cubeName),method:"POST",requestHeaders:{"Content-Type":"text/xml"},success:function(e){for(var n={},r=e.responseXML.getElementsByTagName("row"),s=0;s<r.length;s++){var o=a(r[s],"HIERARCHY_UNIQUE_NAME");switch(Number(a(r[s],"DATA_TYPE"))){case 2:case 3:case 4:case 5:case 6:n[o]=i.DataType.Number;break;case 7:n[o]=i.DataType.Date}}t._dataTypes=n},error:function(e){t._handleError("Get Properties",e)}})},t.prototype._getDimensions=function(e){var t=this,n=this._url;return i.httpRequest(n,{async:!1,data:L(e,t._cubeName),method:"POST",requestHeaders:{"Content-Type":"text/xml"},success:function(n){for(var r=[],s=n.responseXML.getElementsByTagName("row"),o=0;o<s.length;o++)if("2"!==a(s[o],"DIMENSION_TYPE")){var l=a(s[o],"DIMENSION_UNIQUE_NAME"),d={header:a(s[o],"DIMENSION_CAPTION"),dataType:i.DataType.Object,dimensionType:F.Dimension,subFields:[]};t._getSubFolders(e,l,d),r.push(d)}else t._getMeasures(e,r);var h={header:"KPIs",dataType:i.DataType.Object,dimensionType:F.Kpi,subFields:[]};t._getKPIs(e,h),r.push(h),t._jsonResult=r},error:function(e){t._handleError("Get Dimensions",e)}})},t.prototype._getSubFolders=function(e,t,n){var r=this,s=this._url;i.httpRequest(s,{async:!1,data:I(e,r._cubeName,t),method:"POST",requestHeaders:{"Content-Type":"text/xml"},success:function(e){for(var t=e.responseXML.getElementsByTagName("row"),s=0;s<t.length;s++){var o={header:a(t[s],"HIERARCHY_NAME"),binding:a(t[s],"HIERARCHY_UNIQUE_NAME"),dataType:i.DataType.String,dimensionType:F.Hierarchy};r._dataTypes[o.binding]&&(o.dataType=r._dataTypes[o.binding]);for(var l=a(t[s],"HIERARCHY_DISPLAY_FOLDER").split("\\"),d=n,h=0;h<l.length;h++)if(""!=l[h]){var u={header:l[h],dataType:i.DataType.Object,dimensionType:F.Folder,subFields:[]};p(d,l[h])?d=c(d,l[h]):(d.subFields.push(u),d=u)}d.subFields.push(o)}},error:function(e){r._handleError("Get Hierarchies",e)}})},t.prototype._getMeasures=function(e,t){var n=this,r=this._url;return i.httpRequest(r,{async:!1,data:H(e,n._cubeName),method:"POST",requestHeaders:{"Content-Type":"text/xml"},success:function(e){for(var n=e.responseXML.getElementsByTagName("row"),r={},s=0;s<n.length;s++){var o=a(n[s],"MEASUREGROUP_NAME"),l={header:a(n[s],"MEASURE_CAPTION"),binding:a(n[s],"MEASURE_UNIQUE_NAME"),dataType:i.DataType.Number,dimensionType:F.Measure};if(Object.keys(r).indexOf(o)<0){var d={header:o,dataType:i.DataType.Number,dimensionType:F.Measure,subFields:[]};d.subFields.push(l),t.push(d),r[o]=d}else r[o].subFields.push(l)}},error:function(e){n._handleError("Get Measures",e)}})},t.prototype._getKPIs=function(e,t){var n=this,r=this._url;return i.httpRequest(r,{async:!1,data:N(e,n._cubeName),method:"POST",requestHeaders:{"Content-Type":"text/xml"},success:function(e){for(var n=e.responseXML.getElementsByTagName("row"),r=0;r<n.length;r++){for(var s=a(n[r],"KPI_DISPLAY_FOLDER").split("\\"),o=t,l=0;l<s.length;l++){var d={header:s[l],dataType:i.DataType.Object,dimensionType:F.Folder,subFields:[]};p(o,s[l])?o=c(o,s[l]):(o.subFields.push(d),o=d)}var h={header:a(n[r],"KPI_CAPTION"),binding:a(n[r],"KPI_VALUE"),dataType:i.DataType.Number,dimensionType:F.Kpi};o.subFields.push(h)}},error:function(e){n._handleError("Get KPIs",e)}})},t.prototype._execQuery=function(e,t,n){var r=this,s=this._url;return i.httpRequest(s,{async:!0,data:U(e,t),method:"POST",requestHeaders:{"Content-Type":"text/xml"},success:function(e){var s=e.responseXML,o=s.querySelector("Error");if(o)throw"SSAS Error\r\n"+o.getAttribute("Description")+"\r\n"+t;r._createPivotKeys(s),i.asFunction(n)(e)},error:function(e){r._handleError("Execute Query",e)},complete:function(e){r._endSession()}})},t.prototype._createPivotKeys=function(e){var t=null,i=null,n=e.querySelector("CellData");this._ng.columnFields.length>0||this._ng.valueFields.length>1?(i=e.querySelector("Axis[name='Axis0']"),this._ng.rowFields.length>0&&(t=e.querySelector("Axis[name='Axis1']"))):this._ng.rowFields.length>0&&(t=e.querySelector("Axis[name='Axis0']"));var r=t&&this._ng.rowFields.length>0,s=i&&this._ng.columnFields.length>0;r&&s?this._createRowKeys(n,t,i):r?this._createRowOnlyKeys(n,t):s&&this._createColumnOnlyKeys(n,i)},t.prototype._createRowKeys=function(e,t,i){for(var n=0,r=t.getElementsByTagName("Tuple"),s=i.getElementsByTagName("Tuple").length,o=0;o<r.length;o++){var l=r[o],a=this._validateTuple(l);a?n=this._createColumnKeys(e,i,a,n):n+=s}},t.prototype._createRowOnlyKeys=function(e,t){for(var i=0,n=t.getElementsByTagName("Tuple"),r=this._ng.valueFields.length,s=0;s<n.length;s++){var o=n[s],l=this._validateTuple(o);if(l){for(var a=0;a<this._ng.valueFields.length;a++)l[this._ng.valueFields[a].key]=u(e,i++);this._jsonResult.push(l)}else i+=r}},t.prototype._createColumnKeys=function(e,t,i,n){for(var r=t.getElementsByTagName("Tuple"),s=this._ng.valueFields.length,o=0;o<r.length;o+=s){var l=r[o],a=this._validateTuple(l);if(a){for(var d in i)a[d]=i[d];for(var h=0;h<this._ng.valueFields.length;h++)a[this._ng.valueFields[h].key]=u(e,n++);this._jsonResult.push(a)}else n+=s}return n},t.prototype._createColumnOnlyKeys=function(e,t){for(var i=0,n=t.getElementsByTagName("Tuple"),r=this._ng.valueFields.length,s=0;s<n.length;s+=r){var o=n[s],l=this._validateTuple(o);if(l){for(var a=0;a<this._ng.valueFields.length;a++)l[this._ng.valueFields[a].key]=u(e,i++);this._jsonResult.push(l)}}},t.prototype._validateTuple=function(e){for(var t=e.getElementsByTagName("Member"),i=void 0,n={},r=0;r<t.length;r++){var s=t[r],o=d(s),l=s.getAttribute("Hierarchy"),a=h(s);if(0==r)i=o;else if(o>i)return null;l.indexOf(".")>=0&&(n[l]=a)}return n},t}(M);t._SqlServerConnection=O;var V='\n    <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">\n        <Header>\n            <BeginSession soap:mustUnderstand="1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:schemas-microsoft-com:xml-analysis" />\n        </Header>\n        <Body>\n            <Execute xmlns="urn:schemas-microsoft-com:xml-analysis">\n                <Command>\n                    <Statement />\n                </Command>\n                <Properties>\n                </Properties>\n            </Execute>\n        </Body>\n    </Envelope>',k=function(e){return'\n    <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">\n        <Header>\n            <XA:EndSession soap:mustUnderstand="1" SessionId="'+e+'" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:XA="urn:schemas-microsoft-com:xml-analysis" />\n        </Header>\n        <Body>\n            <Execute xmlns="urn:schemas-microsoft-com:xml-analysis">\n                <Command>\n                    <Statement />\n                </Command>\n                <Properties>\n                </Properties>\n            </Execute>\n        </Body>\n    </Envelope>'},L=function(e,t){return'\n    <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">\n        <Header>\n            <XA:Session soap:mustUnderstand="1" SessionId="'+e+'" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:XA="urn:schemas-microsoft-com:xml-analysis" />\n        </Header>\n        <Body>\n            <Discover xmlns="urn:schemas-microsoft-com:xml-analysis">\n                <RequestType>MDSCHEMA_DIMENSIONS</RequestType>\n                <Restrictions>\n                    <RestrictionList>\n                        <CUBE_NAME>'+t+"</CUBE_NAME>\n                    </RestrictionList>\n                </Restrictions>\n                <Properties>\n                </Properties>\n            </Discover>\n        </Body>\n    </Envelope>"},I=function(e,t,i){return'\n    <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">\n        <Header>\n            <XA:Session soap:mustUnderstand="1" SessionId="'+e+'" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:XA="urn:schemas-microsoft-com:xml-analysis" />\n        </Header>\n        <Body>\n            <Discover xmlns="urn:schemas-microsoft-com:xml-analysis">\n                <RequestType>MDSCHEMA_HIERARCHIES</RequestType>\n                <Restrictions>\n                    <RestrictionList>\n                        <CUBE_NAME>'+t+"</CUBE_NAME>\n                        <DIMENSION_UNIQUE_NAME>"+i+"</DIMENSION_UNIQUE_NAME>\n                    </RestrictionList>\n                </Restrictions>\n                <Properties>\n                </Properties>\n            </Discover>\n        </Body>\n    </Envelope>"},H=function(e,t){return'\n    <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">\n        <Header>\n            <XA:Session soap:mustUnderstand="1" SessionId="'+e+'" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:XA="urn:schemas-microsoft-com:xml-analysis" />\n        </Header>\n        <Body>\n            <Discover xmlns="urn:schemas-microsoft-com:xml-analysis">\n                <RequestType>MDSCHEMA_MEASURES</RequestType>\n                <Restrictions>\n                    <RestrictionList>\n                        <CUBE_NAME>'+t+"</CUBE_NAME>\n                    </RestrictionList>\n                </Restrictions>\n                <Properties>\n                </Properties>\n            </Discover>\n        </Body>\n    </Envelope>"},N=function(e,t){return'\n    <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">\n        <Header>\n            <XA:Session soap:mustUnderstand="1" SessionId="'+e+'" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:XA="urn:schemas-microsoft-com:xml-analysis" />\n        </Header>\n        <Body>\n            <Discover xmlns="urn:schemas-microsoft-com:xml-analysis">\n                <RequestType>MDSCHEMA_KPIS</RequestType>\n                <Restrictions>\n                    <RestrictionList>\n                        <CUBE_NAME>'+t+"</CUBE_NAME>\n                    </RestrictionList>\n                </Restrictions>\n                <Properties>\n                </Properties>\n            </Discover>\n        </Body>\n    </Envelope>"},B=function(e,t){return'\n    <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">\n        <Header>\n            <XA:Session soap:mustUnderstand="1" SessionId="'+e+'" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:XA="urn:schemas-microsoft-com:xml-analysis" />\n        </Header>\n        <Body>\n            <Discover xmlns="urn:schemas-microsoft-com:xml-analysis">\n                <RequestType>MDSCHEMA_PROPERTIES</RequestType>\n                <Restrictions>\n                    <RestrictionList>\n                        <CUBE_NAME>'+t+"</CUBE_NAME>\n                        <PROPERTY_NAME>MEMBER_VALUE</PROPERTY_NAME>\n                    </RestrictionList>\n                </Restrictions>\n                <Properties>\n                </Properties>\n            </Discover>\n        </Body>\n    </Envelope>"},U=function(e,t){return'\n    <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">\n        <Header>\n            <XA:Session soap:mustUnderstand="1" SessionId="'+e+'" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:XA="urn:schemas-microsoft-com:xml-analysis" />\n        </Header>\n        <Body>\n            <Execute xmlns="urn:schemas-microsoft-com:xml-analysis">\n                <Command>\n                    <Statement>\n                        <![CDATA[\n                        '+t+"\n                        ]]>\n                    </Statement>\n                </Command>\n                <Properties>\n                    <PropertyList>\n                        <Content>Data</Content>\n                    </PropertyList>\n                </Properties>\n            </Execute>\n        </Body>\n    </Envelope>"},G=function(){function e(){this._text=""}return Object.defineProperty(e.prototype,"length",{get:function(){return this._text.length},enumerable:!0,configurable:!0}),e.prototype.toString=function(){return this._text},e.prototype.append=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._text=(i=this._text).concat.apply(i,e);var i},e.prototype.joinToList=function(e){for(var t=[],i=1;i<arguments.length;i++)t[i-1]=arguments[i];var n=t.join();this.length>0&&n.length>0?this._text=(r=this._text).concat.apply(r,[e].concat(t)):n.length>0&&(this._text=n);var r},e.prototype.joinItemToList=function(e){this.joinToList(",",e)},e.prototype.wrap=function(e,t){this.length>0&&(this._text=e.concat(this._text,t))},e.wrap=function(e,t,i){return t.length>0?e.concat(t,i):""},e}();t._TextBuilder=G;var K=function(e){function t(t){var n=e.call(this,document.createElement("div"),{header:"Field Context Menu",displayMemberPath:"text",commandParameterPath:"parm",command:{executeCommand:function(e){n._execute(e)},canExecuteCommand:function(e){return n._canExecute(e)}}})||this;return n._full=t,n.itemsSource=n._getMenuItems(t),i.addClass(n.dropDown,"context-menu wj-olap-context-menu"),n}return __extends(t,e),t.prototype.refresh=function(t){void 0===t&&(t=!0),this.itemsSource=this._getMenuItems(this._full),e.prototype.refresh.call(this,t)},t.prototype.attach=function(e){var t=this;i.assert(e instanceof s.FlexGrid,"Expecting a FlexGrid control...");var n=e.hostElement;n.addEventListener("contextmenu",function(i){t._selectField(e,i)&&(i.preventDefault(),t.owner=n,t.show(i))})},t.prototype._selectField=function(e,t){var i=e.hitTest(t);if(i.panel!=e.cells||!i.range.isValid)return!1;var n=e.rows[i.row].dataItem;return!(n instanceof w&&n.subFields&&n.subFields.length)&&(e.select(i.range,!0),!0)},t.prototype._getMenuItems=function(e){var t;t=e?[{text:'<div class="menu-icon"></div>*',parm:"up"},{text:'<div class="menu-icon"></div>*',parm:"down"},{text:'<div class="menu-icon"></div>*',parm:"first"},{text:'<div class="menu-icon"></div>*',parm:"last"},{text:'<div class="wj-separator"></div>'},{text:'<div class="menu-icon"><span class="wj-glyph-filter"></span></div>*',parm:"filter"},{text:'<div class="menu-icon">&#8801;</div>*',parm:"rows"},{text:'<div class="menu-icon">&#10996;</div>*',parm:"cols"},{text:'<div class="menu-icon">&#931;</div>*',parm:"vals"},{text:'<div class="wj-separator"></div>'},{text:'<div class="menu-icon menu-icon-remove">&#10006;</div>*',parm:"remove"},{text:'<div class="wj-separator"></div>'},{text:'<div class="menu-icon">&#9965;</div>*',parm:"edit"}]:[{text:'<div class="menu-icon"><span class="wj-glyph-filter"></span></div>*',parm:"filter"},{text:'<div class="menu-icon">&#8801;</div>*',parm:"rows"},{text:'<div class="menu-icon">&#10996;</div>*',parm:"cols"},{text:'<div class="menu-icon">&#931;</div>*',parm:"vals"},{text:'<div class="wj-separator"></div>'},{text:'<div class="menu-icon">&#9965;</div>*',parm:"edit"}];for(var n=0;n<t.length;n++){var r=t[n];if(r.parm){var s=i.culture.olap._ListContextMenu[r.parm];i.assert(s,"missing localized text for item "+r.parm),r.text=r.text.replace(/([^>]+$)/,s)}}return t},t.prototype._execute=function(e){var t=i.Control.getControl(this.owner),n=t.itemsSource,r=t.selection.row,s=t.rows[r].dataItem,o=s?s.engine:null,l=this._getTargetList(o,e);switch(e){case"up":case"first":case"down":case"last":if(o){var a=n.indexOf(s),d="up"==e?a-1:"first"==e?0:"down"==e?a+1:"last"==e?n.length:-1;o.deferUpdate(function(){n.removeAt(a),n.insert(d,s)})}break;case"filter":case"rows":case"cols":case"vals":l&&s&&l.push(s);break;case"remove":s&&o.removeField(s);break;case"edit":s&&o.editField(s)}},t.prototype._canExecute=function(e){var t=i.Control.getControl(this.owner);if(!t)return!1;var n=t.selection.row,r=n>-1?t.rows[n].dataItem:null,s=r?r.engine:null,o=this._getTargetList(s,e),l=!!r&&r instanceof w,a=!!r&&r.isMeasure;switch(e){case"up":case"first":return n>0;case"down":case"last":return n<t.rows.length-1;case"filter":case"rows":case"cols":return!a&&o&&o.indexOf(r)<0;case"vals":return(!l||a)&&o&&o.indexOf(r)<0;case"edit":return s&&s.allowFieldEditing;case"detail":return r&&!l}return!0},t.prototype._getTargetList=function(e,t){if(e)switch(t){case"filter":return e.filterFields;case"rows":return e.rowFields;case"cols":return e.columnFields;case"vals":return e.valueFields}return null},t}(r.Menu);t._ListContextMenu=K;var q=function(e){function t(t,o){var l=e.call(this,t,null,!0)||this;l._showIcons=!0,l._restrictDrag=null,l.itemsSourceChanged=new i.Event,l.viewDefinitionChanged=new i.Event,l.updatingView=new i.Event,l.updatedView=new i.Event;var a="Missing dependency: PivotPanel requires ";i.assert(null!=r,a+"wijmo.input."),i.assert(null!=s&&null!=n,a+"wijmo.grid.filter.");var d=l.getTemplate();l.applyTemplate("wj-control wj-content wj-pivotpanel",d,{_dFields:"d-fields",_dFilters:"d-filters",_dRows:"d-rows",_dCols:"d-cols",_dVals:"d-vals",_dProgress:"d-prog",_btnUpdate:"btn-update",_chkDefer:"chk-defer",_gFlds:"g-flds",_gDrag:"g-drag",_gFlt:"g-flt",_gCols:"g-cols",_gRows:"g-rows",_gVals:"g-vals",_gDefer:"g-defer"}),l._globalize();var h=l.hostElement;l.addEventListener(h,"dragstart",l._dragstart.bind(l)),l.addEventListener(h,"dragover",l._dragover.bind(l)),l.addEventListener(h,"dragleave",l._dragover.bind(l)),l.addEventListener(h,"drop",l._drop.bind(l)),l.addEventListener(h,"dragend",l._dragend.bind(l)),l._lbFields=l._createFieldGrid(l._dFields),l._lbFilters=l._createFieldGrid(l._dFilters),l._lbRows=l._createFieldGrid(l._dRows),l._lbCols=l._createFieldGrid(l._dCols),l._lbVals=l._createFieldGrid(l._dVals);var u=l._ctxMenuShort=new K(!1);return u.attach(l._lbFields),(u=l._ctxMenuFull=new K(!0)).attach(l._lbFilters),u.attach(l._lbRows),u.attach(l._lbCols),u.attach(l._lbVals),l._dMarker=i.createElement('<div class="wj-marker" style="display:none">&nbsp;</div>'),l.hostElement.appendChild(l._dMarker),l.addEventListener(l._btnUpdate,"click",function(e){l._ng.refresh(!0),e.preventDefault()}),l.addEventListener(l._chkDefer,"click",function(e){i.enable(l._btnUpdate,l._chkDefer.checked),l._chkDefer.checked?l._ng.beginUpdate():l._ng.endUpdate()}),l.engine=new R,l.initialize(o),l}return __extends(t,e),t.prototype._getProductInfo=function(){return"D6F4,PivotPanel"},Object.defineProperty(t.prototype,"engine",{get:function(){return this._ng},set:function(e){var t=this;this._ng&&(this._ng.itemsSourceChanged.removeHandler(this._itemsSourceChanged),this._ng.viewDefinitionChanged.removeHandler(this._viewDefinitionChanged),this._ng.updatingView.removeHandler(this._updatingView),this._ng.updatedView.removeHandler(this._updatedView),this._ng.error.removeHandler(this._requestError)),e=i.asType(e,R,!1),this._ng=e,this._ng.itemsSourceChanged.addHandler(this._itemsSourceChanged,this),this._ng.viewDefinitionChanged.addHandler(this._viewDefinitionChanged,this),this._ng.updatingView.addHandler(this._updatingView,this),this._ng.updatedView.addHandler(this._updatedView,this),this._ng.error.addHandler(this._requestError,this),this._lbFields.itemsSource=e.fields,this._lbFilters.itemsSource=e.filterFields,this._lbRows.itemsSource=e.rowFields,this._lbCols.itemsSource=e.columnFields,this._lbVals.itemsSource=e.valueFields,this._lbFields.collectionView.filter=function(e){return e.visible&&null==e.parentField},"Filters,Rows,Cols,Vals".split(",").forEach(function(e){t["_lb"+e].collectionView.filter=function(e){return e.visible}})},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"itemsSource",{get:function(){return this._ng.itemsSource},set:function(e){e instanceof R?this.engine=e:this._ng.itemsSource=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"collectionView",{get:function(){return this._ng.collectionView},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"pivotView",{get:function(){return this._ng.pivotView},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"autoGenerateFields",{get:function(){return this.engine.autoGenerateFields},set:function(e){this._ng.autoGenerateFields=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"fields",{get:function(){return this._ng.fields},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rowFields",{get:function(){return this._ng.rowFields},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"columnFields",{get:function(){return this._ng.columnFields},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"valueFields",{get:function(){return this._ng.valueFields},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"filterFields",{get:function(){return this._ng.filterFields},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"viewDefinition",{get:function(){return this._ng.viewDefinition},set:function(e){this._ng.viewDefinition=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isViewDefined",{get:function(){return this._ng.isViewDefined},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"showFieldIcons",{get:function(){return this._showIcons},set:function(e){e!=this._showIcons&&(this._showIcons=i.asBoolean(e),this.invalidate())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"restrictDragging",{get:function(){return this._restrictDrag},set:function(e){this._restrictDrag=i.asBoolean(e,!0)},enumerable:!0,configurable:!0}),t.prototype.onItemsSourceChanged=function(e){this.itemsSourceChanged.raise(this,e)},t.prototype.onViewDefinitionChanged=function(e){this.viewDefinitionChanged.raise(this,e)},t.prototype.onUpdatingView=function(e){this.updatingView.raise(this,e)},t.prototype.onUpdatedView=function(e){this.updatedView.raise(this,e)},t.prototype.refresh=function(t){var i=this;void 0===t&&(t=!0),"Fields,Filters,Rows,Cols,Vals".split(",").forEach(function(e){var t=i["_lb"+e];t.refresh(),t.collectionView.refresh()}),t&&(this._globalize(),this._ctxMenuShort.refresh(),this._ctxMenuFull.refresh()),e.prototype.refresh.call(this,t)},t.prototype._copy=function(e,t){switch(e){case"engine":return this.engine=t,!0}return!1},t.prototype._globalize=function(){var e=i.culture.olap.PivotPanel;i.setText(this._gFlds,e.fields),i.setText(this._gDrag,e.drag),i.setText(this._gFlt,e.filters),i.setText(this._gCols,e.cols),i.setText(this._gRows,e.rows),i.setText(this._gVals,e.vals),i.setText(this._gDefer,e.defer),i.setText(this._btnUpdate,e.update)},t.prototype._itemsSourceChanged=function(e,t){this.onItemsSourceChanged(t)},t.prototype._viewDefinitionChanged=function(e,t){e.isUpdating||(this.invalidate(),this.onViewDefinitionChanged(t))},t.prototype._updatingView=function(e,t){var n=i.clamp(t.progress,5,100)%100;this._dProgress.style.width=n+"%",this.onUpdatingView(t)},t.prototype._updatedView=function(e,t){this.onUpdatedView(t)},t.prototype._requestError=function(e,t){this._dProgress.style.width="0"},t.prototype._createFieldGrid=function(e){var t=this,n=new s.FlexGrid(e,{autoGenerateColumns:!1,childItemsPath:"subFields",columns:[{binding:"header",width:"*"}],headersVisibility:"None",selectionMode:"Cell",showAlternatingRows:!1});return n.cells.hostElement.parentElement.style.overflowX="hidden",n.formatItem.addHandler(function(e,n){var r=e.rows[n.row].dataItem;i.assert(r instanceof b,"PivotField expected...");var s=r._hasSubFields();i.toggleClass(n.cell,"wj-header",s),n.cell.setAttribute("draggable",(!s).toString());var o=n.cell.innerHTML;r.filter.isActive&&(o+='&nbsp;&nbsp;<span class="wj-glyph-filter"></span>'),e==t._lbVals&&(o+=' <span class="wj-aggregate">('+i.Aggregate[r.aggregate]+")</span>"),e!=t._lbFields||s||(t._showIcons&&(o='<span class="wj-glyph-'+(r.isMeasure?"measure":"dimension")+'"></span> '+o),o='<label><input type="checkbox"'+(r.isActive?" checked":"")+"> "+o+"</label>"),n.cell.innerHTML=o}),n.addEventListener(e,"click",function(e){var i=e.target;if(i instanceof HTMLInputElement&&"checkbox"==i.type){var r=t._hitTestField(n,e);r instanceof b&&(r.isActive=i.checked)}}),n},t.prototype._dragstart=function(e){var t=this._getFlexGridTarget(e);t&&(this._dragField=this._hitTestField(t,e),this._dragSource=this._dragField instanceof b?t.hostElement:null,this._dragSource&&e.dataTransfer&&(i._startDrag(e.dataTransfer,"copyMove"),e.stopPropagation()))},t.prototype._dragover=function(e){var t=!1,i=this._getFlexGridTarget(e);if(i&&this._dragField){if(this._dragSource==this._dFields&&i!=this._lbFields){var n=i.itemsSource;if(null==n.maxItems||n.length<n.maxItems){var r=this._dragField;i.itemsSource.indexOf(r)<0?t=!0:i==this._lbVals&&(t=!(r instanceof w))}}this._dragSource&&this._dragSource!=this._dFields&&(t=!0)}if(t&&this._getRestrictDrag()&&this._dragSource!=i.hostElement){var s=this._dragField.isMeasure;i==this._lbVals?t=s:i!=this._lbRows&&i!=this._lbCols||(t=!s)}t?(this._updateDropMarker(i,e),e.dataTransfer.dropEffect=this._dragSource==this._dFields?"copy":"move",e.preventDefault(),e.stopPropagation()):this._updateDropMarker()},t.prototype._drop=function(e){var t=this,n=this._getFlexGridTarget(e);if(n&&this._dragField){var r=i.Control.getControl(this._dragSource),s=this._dragField;r==this._lbFields&&n==this._lbVals&&n.itemsSource.indexOf(s)>-1&&(s=s._clone(),this.engine.fields.push(s)),n==this._lbFields?s.isActive=!1:this._ng.deferUpdate(function(){var e=n.itemsSource,i=e.indexOf(s);i!=t._dropIndex&&(i>-1&&(e.removeAt(i),i<t._dropIndex&&t._dropIndex--),e.insert(t._dropIndex,s))})}this._resetMouseState()},t.prototype._dragend=function(e){this._resetMouseState()},t.prototype._hitTestField=function(e,t){var i=e.hitTest(t.target);return i.panel==e.cells&&i.range.isValid?(e.select(i.range,!0),e.rows[i.row].dataItem):null},t.prototype._getRestrictDrag=function(){var e=this._restrictDrag;return null==e&&this.fields.length&&(e=this.fields[0]instanceof w),e},t.prototype._resetMouseState=function(){this._dragSource=null,this._updateDropMarker()},t.prototype._getFlexGridTarget=function(e){var t=i.Control.getControl(i.closest(e.target,".wj-flexgrid"));return t instanceof s.FlexGrid?t:null},t.prototype._updateDropMarker=function(e,t){if(t){var n;if(e.rows.length){var r=e.hitTest(t),s=r.row;s>-1?(n=e.getCellBoundingRect(s,0),r.point.y>n.top+n.height/2&&(n.top+=n.height,s++),this._dropIndex=s):(s=e.viewRange.bottomRow,(n=e.getCellBoundingRect(s,0)).top+=n.height,this._dropIndex=s+1)}else(n=i.Rect.fromBoundingRect(e.hostElement.getBoundingClientRect())).top+=4,this._dropIndex=0;var o=this.hostElement,l=o.getBoundingClientRect();i.setCss(this._dMarker,{left:Math.round(n.left-l.left)+o.scrollLeft,top:Math.round(n.top-l.top-2)+o.scrollTop,width:Math.round(n.width),height:4,display:""})}else this._dMarker.style.display="none"},t.controlTemplate='<div><label wj-part="g-flds"></label><div wj-part="d-fields"></div><label wj-part="g-drag"></label><table><tr><td width="50%"><label><span class="wj-glyph wj-glyph-filter"></span> <span wj-part="g-flt"></span></label><div wj-part="d-filters"></div></td><td width= "50%" style= "border-left-style:solid"><label><span class="wj-glyph">&#10996;</span> <span wj-part="g-cols"></span></label><div wj-part="d-cols"></div></td></tr><tr style= "border-top-style:solid"><td width="50%"><label><span class="wj-glyph">&#8801;</span> <span wj-part="g-rows"></span></label><div wj-part="d-rows"></div></td><td width= "50%" style= "border-left-style:solid"><label><span class="wj-glyph">&#931;</span> <span wj-part="g-vals"></span></label><div wj-part="d-vals"></div></td></tr></table><div wj-part="d-prog" class="wj-state-selected" style="width:0px;height:3px"></div><div style="display:table"><label style="display:table-cell;vertical-align:middle"><input wj-part="chk-defer" type="checkbox"/> <span wj-part="g-defer"></span></label><button wj-part="btn-update" class="wj-btn wj-state-disabled" style="float:right;margin:6px" disabled></button></div></div>',t}(i.Control);t.PivotPanel=q;var W=function(e){function t(){var t=e.call(this,document.createElement("div"),{header:"PivotGrid Context Menu",displayMemberPath:"text",commandParameterPath:"parm",command:{executeCommand:function(e){t._execute(e)},canExecuteCommand:function(e){return t._canExecute(e)}}})||this;return t.itemsSource=t._getMenuItems(),i.addClass(t.dropDown,"context-menu wj-olap-context-menu"),t}return __extends(t,e),t.prototype.refresh=function(t){void 0===t&&(t=!0),this.itemsSource=this._getMenuItems(),e.prototype.refresh.call(this,t)},t.prototype.attach=function(e){var t=this;i.assert(e instanceof X,"Expecting a PivotGrid control...");var n=e.hostElement;n.addEventListener("contextmenu",function(r){if(e.customContextMenu&&(r.preventDefault(),t.owner=n,t._selectField(r))){var s=t.dropDown;t.selectedIndex=-1,t.onIsDroppedDownChanging(new i.CancelEventArgs)&&(i.showPopup(s,r),t.onIsDroppedDownChanged(),s.focus())}})},t.prototype._selectField=function(e){this._targetField=null,this._htDown=null;var t=i.Control.getControl(this.owner),n=t.engine,r=t.hitTest(e),o=s.CellType;switch(r.cellType){case o.Cell:t.select(r.range),this._targetField=n.valueFields[r.col%n.valueFields.length],this._htDown=r;break;case o.ColumnHeader:this._targetField=n.columnFields[r.row];break;case o.RowHeader:this._targetField=n.rowFields[r.col];break;case o.TopLeft:r.row==r.panel.rows.length-1&&(this._targetField=n.rowFields[r.col])}return null!=this._targetField},t.prototype._getMenuItems=function(){for(var e=[{text:'<div class="menu-icon menu-icon-remove">&#10006;</div>Remove Field',parm:"remove"},{text:'<div class="menu-icon">&#9965;</div>Field Settings...',parm:"edit"},{text:'<div class="wj-separator"></div>'},{text:'<div class="menu-icon">&#8981;</div>Show Detail...',parm:"detail"}],t=0;t<e.length;t++){var n=e[t];if(n.parm){var r=i.culture.olap._ListContextMenu[n.parm];i.assert(r,"missing localized text for item "+n.parm),n.text=n.text.replace(/([^>]+$)/,r)}}return e},t.prototype._execute=function(e){var t=i.Control.getControl(this.owner),n=this._targetField,r=this._htDown;switch(e){case"remove":t.engine.removeField(n);break;case"edit":t.engine.editField(n);break;case"detail":t.showDetail(r.row,r.col)}},t.prototype._canExecute=function(e){var t=this._targetField,n=i.Control.getControl(this.owner),r=n?n.engine:null;switch(e){case"remove":return null!=t;case"edit":return null!=t&&r&&r.allowFieldEditing;case"detail":return null!=this._htDown&&r.valueFields.length&&null!=t&&!(t instanceof w)}return!0},t}(r.Menu);t._GridContextMenu=W;var Y=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.getMergedRange=function(t,i,n,r){void 0===r&&(r=!0);var o=t.grid.collectionView;if(this._ng=o instanceof y?o.engine:null,!this._ng)return e.prototype.getMergedRange.call(this,t,i,n,r);if(i<0||i>=t.rows.length||n<0||n>=t.columns.length)return null;switch(t.cellType){case s.CellType.TopLeft:return this._getMergedTopLeftRange(t,i,n);case s.CellType.RowHeader:return this._getMergedRowHeaderRange(t,i,n,r?t.viewRange:null);case s.CellType.ColumnHeader:return this._getMergedColumnHeaderRange(t,i,n,r?t.viewRange:null)}return null},t.prototype._getMergedTopLeftRange=function(e,t,i){for(var n=new s.CellRange(t,i);n.col>0&&!e.getCellData(t,n.col,!0);)n.col--;for(;n.col2<e.columns.length-1&&!e.getCellData(t,n.col2+1,!0);)n.col2++;return n},t.prototype._getMergedRowHeaderRange=function(e,t,i,n){var r=this._ng._getRowLevel(t);if(r>-1&&i>=r){var o=e.getCellData(t,i,!1),l=void 0,a=void 0,d=n?n.col:0,h=n?n.col2:e.columns.length-1;for(l=i;l>d&&e.getCellData(t,l-1,!1)==o;l--);for(a=i;a<h&&e.getCellData(t,a+1,!1)==o;a++);return l!=a?new s.CellRange(t,l,t,a):null}var u,c,p=n?n.row:0,g=n?n.row2:e.rows.length-1;for(u=t;u>p&&this._sameColumnValues(e,t,u-1,i);u--);for(c=t;c<g&&this._sameColumnValues(e,t,c+1,i);c++);return u!=c?new s.CellRange(u,i,c,i):null},t.prototype._sameColumnValues=function(e,t,i,n){for(;n>=0;n--)if(e.getCellData(t,n,!1)!=e.getCellData(i,n,!1))return!1;return!0},t.prototype._getMergedColumnHeaderRange=function(e,t,i,n){var r=this._ng._getKey(e.columns[i].binding),o=e.getCellData(t,i,!1),l=this._ng._getColLevel(r);if(l>-1&&t>=l){var a=void 0,d=void 0,h=n?n.row:0,u=n?n.row2:e.rows.length-1;for(a=t;a>h&&e.getCellData(a-1,i,!1)==o;a--);for(d=t;d<u&&e.getCellData(d+1,i,!1)==o;d++);if(a!=d)return new s.CellRange(a,i,d,i)}var c,p,g=n?n.col:0,_=n?n.col2:e.columns.length-1;for(c=i;c>g&&this._sameRowValues(e,t,i,c-1);c--);for(p=i;p<_&&this._sameRowValues(e,t,i,p+1);p++);return c!=p?new s.CellRange(t,c,t,p):null},t.prototype._sameRowValues=function(e,t,i,n){for(;t>=0;t--)if(e.getCellData(t,i,!1)!=e.getCellData(t,n,!1))return!1;return!0},t}(s.MergeManager);t._PivotMergeManager=Y;var X=function(e){function t(t,n){var r=e.call(this,t)||this;return r._showDetailOnDoubleClick=!0,r._collapsibleSubtotals=!0,r._customCtxMenu=!0,r._showRowFldSort=!1,r._showRowFldHdrs=!0,r._showColFldHdrs=!0,r._centerVert=!0,r._collapsedKeys={},i.addClass(r.hostElement,"wj-pivotgrid"),r.isReadOnly=!0,r.deferResizing=!0,r.showAlternatingRows=!1,r.autoGenerateColumns=!1,r.allowDragging=s.AllowDragging.None,r.mergeManager=new Y(r),r.customContextMenu=!0,r.initialize(n),r.formatItem.addHandler(r._formatItem,r),r.addEventListener(r.hostElement,"mousedown",r._mousedown.bind(r),!0),r.addEventListener(r.hostElement,"mouseup",r._mouseup.bind(r),!0),r.addEventListener(r.hostElement,"dblclick",r._dblclick.bind(r),!0),r._ctxMenu=new W,r._ctxMenu.attach(r),r}return __extends(t,e),t.prototype._getProductInfo=function(){return"D6F4,PivotGrid"},Object.defineProperty(t.prototype,"engine",{get:function(){return this._ng},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"showDetailOnDoubleClick",{get:function(){return this._showDetailOnDoubleClick},set:function(e){this._showDetailOnDoubleClick=i.asBoolean(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"detailDialog",{get:function(){return this._dlgDetail||(this._dlgDetail=new z(document.createElement("div"))),this._dlgDetail},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"showRowFieldHeaders",{get:function(){return this._showRowFldHdrs},set:function(e){e!=this._showRowFldHdrs&&(this._showRowFldHdrs=i.asBoolean(e),this._updateFixedContent())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"showColumnFieldHeaders",{get:function(){return this._showColFldHdrs},set:function(e){e!=this._showColFldHdrs&&(this._showColFldHdrs=i.asBoolean(e),this._updateFixedContent())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"showRowFieldSort",{get:function(){return this._showRowFldSort},set:function(e){e!=this._showRowFldSort&&(this._showRowFldSort=i.asBoolean(e),this._updateFixedContent())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"customContextMenu",{get:function(){return this._customCtxMenu},set:function(e){this._customCtxMenu=i.asBoolean(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"collapsibleSubtotals",{get:function(){return this._collapsibleSubtotals},set:function(e){e!=this._collapsibleSubtotals&&(this._collapsibleSubtotals=i.asBoolean(e),this.invalidate())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"centerHeadersVertically",{get:function(){return this._centerVert},set:function(e){e!=this._centerVert&&(this._centerVert=i.asBoolean(e),this.invalidate())},enumerable:!0,configurable:!0}),t.prototype.getDetail=function(e,t){var n=this.rows[i.asInt(e)].dataItem,r=this.columns[i.asInt(t)].binding;return this._ng.getDetail(n,r)},t.prototype.getKeys=function(e,t){var n=this.rows[i.asInt(e)],r=this.columns[i.asInt(t)],s=n?n.dataItem:null,o=r?r.binding:null;return this._ng.getKeys(s,o)},t.prototype.getDetailView=function(e,t){var n=this.rows[i.asInt(e)].dataItem,r=this.columns[i.asInt(t)].binding;return this._ng.getDetailView(n,r)},t.prototype.showDetail=function(e,t){if(this._ng.valueFields.length){var i=this.detailDialog;i.showDetail(this,new s.CellRange(e,t)),i.show(!0)}},t.prototype.collapseRowsToLevel=function(e){this._collapseRowsToLevel(e)},t.prototype.collapseColumnsToLevel=function(e){this._collapseColsToLevel(e)},t.prototype._getQuickAutoSize=function(){return i.isBoolean(this.quickAutoSize)?this.quickAutoSize:this.formatItem.handlerCount<=1&&null==this.itemFormatter},t.prototype._bindGrid=function(t){var n=this;this.deferUpdate(function(){var r=n.preserveOutlineState,o=n._collapsedKeys,l=n.rows,a=n.columns;if(r||(o=n._collapsedKeys={}),e.prototype._bindGrid.call(n,t),n._ng&&r&&!i.isEmpty(o)){for(var d=n._ng.totalsBeforeData,h=d?l.length-1:0,u=d?-1:l.length,c=d?-1:1,p=h;p!=u;p+=c){var g=l[p].dataItem;(f=g?g[v._ROW_KEY_NAME]:null)&&f.level>0&&o[f.toString()]&&n._setRowCollapsed(new s.CellRange(p,f.level-1),!0)}h=d?a.length-1:0,u=d?-1:a.length,c=d?-1:1;for(p=h;p!=u;p+=c){var _=a[p].binding,f=n._ng._getKey(_);f&&f.level>0&&o[f.toString()]&&n._setColCollapsed(new s.CellRange(f.level-1,p),!0)}}})},t.prototype._getCollectionView=function(e){return e instanceof q?e=e.engine.pivotView:e instanceof R&&(e=e.pivotView),i.asCollectionView(e)},t.prototype.refresh=function(t){void 0===t&&(t=!0),this._ctxMenu.refresh(),e.prototype.refresh.call(this,t)},t.prototype.onItemsSourceChanged=function(t){this._ng&&(this._ng.updatedView.removeHandler(this._updatedView,this),this._ng.viewDefinitionChanged.removeHandler(this._viewDefinitionChanged,this)),this._collapsedKeys={};var i=this.collectionView;this._ng=i instanceof y?i.engine:null,this._ng&&(this._ng.updatedView.addHandler(this._updatedView,this),this._ng.viewDefinitionChanged.addHandler(this._viewDefinitionChanged,this)),this._updatedView(),this._bindGrid(!0),e.prototype.onItemsSourceChanged.call(this,t)},t.prototype.onResizedColumn=function(t){var i=this._ng;if(i){if(t.panel.columns==this.rowHeaders.columns){var n=i.rowFields;t.col<n.length&&((r=n[t.col]).width=t.panel.columns[t.col].renderWidth)}if(t.panel.columns==this.columnHeaders.columns&&(n=i.valueFields).length>0){var r=n[t.col%n.length];r.width=t.panel.columns[t.col].renderWidth}}e.prototype.onResizedColumn.call(this,t)},t.prototype.onSortingColumn=function(t){var i=this._ng;return(!i||!i.isUpdating)&&e.prototype.onSortingColumn.call(this,t)},t.prototype.onDraggingColumn=function(t){var i=this._ng;return(!i||!i.isUpdating)&&e.prototype.onDraggingColumn.call(this,t)},t.prototype.onDraggedColumn=function(t){var i=this._ng;if(i&&t.panel.columns==this.topLeftCells.columns){var n=i.rowFields,r=n[t.data.col];i.deferUpdate(function(){n.removeAt(t.data.col),n.insert(t.col,r)})}e.prototype.onDraggedColumn.call(this,t)},t.prototype._updatedView=function(){this._updateFixedCounts(),this.columns.clear(),this.rows.clear()},t.prototype._viewDefinitionChanged=function(){this._collapsedKeys={}},t.prototype.onLoadedRows=function(t){if(0==this.columns.length){var n=this.collectionView,r=n?n.sourceCollection:null;if(r&&r.length){var o=r[0];for(var l in o)if(l!=v._ROW_KEY_NAME){var a=new s.Column({binding:l,dataType:null!=o[l]?i.getType(o[l]):i.DataType.Number});this.columns.push(a)}}}this._updateFixedContent(),e.prototype.onLoadedRows.call(this,t)},t.prototype._updateFixedCounts=function(){var e,t=this._ng,i=t&&t.isViewDefined;e=Math.max(1,i?t.rowFields.length:1),this._setLength(this.topLeftCells.columns,e),e=Math.max(1,i?t.columnFields.length:1),t&&t.columnFields.length&&t.valueFields.length>1&&e++,this._setLength(this.topLeftCells.rows,e)},t.prototype._setLength=function(e,t){for(;e.length<t;)e.push(e instanceof s.ColumnCollection?new s.Column:new s.Row);for(;e.length>t;)e.removeAt(e.length-1)},t.prototype._updateFixedContent=function(){var e=this._ng;if(e&&e.isViewDefined){for(var t=this.topLeftCells,n=0;n<t.rows.length;n++)for(h=0;h<t.columns.length;h++){l="";this.showRowFieldHeaders&&h<e.rowFields.length&&n==t.rows.length-1&&(l=e.rowFields[h].header),this.showColumnFieldHeaders&&!l&&n<e.columnFields.length&&0==h&&(l=e.columnFields[n].header+":"),t.setCellData(n,h,l,!1,!1)}t=this.rowHeaders;for(n=0;n<t.rows.length;n++){r=t.rows[n].dataItem[v._ROW_KEY_NAME];i.assert(r instanceof v,"missing PivotKey for row...");for(h=0;h<t.columns.length;h++){l=r.getValue(h,!0);t.setCellData(n,h,l,!1,!1)}}t=this.columnHeaders;for(h=0;h<t.columns.length;h++){var r=e._getKey(t.columns[h].binding),s=e.valueFields,o=s.length>1||0==s.length||r.level>-1;i.assert(r instanceof v,"missing PivotKey for column...");for(n=0;n<t.rows.length;n++){var l=o&&n==t.rows.length-1&&s.length?s[h%s.length].header:r.getValue(n,!0);t.setCellData(n,h,l,!1,!1)}}t=this.topLeftCells;for(h=0;h<t.columns.length;h++){var a=t.columns[h],d=h<e.rowFields.length?e.rowFields[h]:null;a.width=d&&i.isNumber(d.width)?d.width:this.columns.defaultSize,a.wordWrap=d?d.wordWrap:null,a.align=null}t=this.cells;for(var h=0;h<t.columns.length;h++){var a=t.columns[h],d=e.valueFields.length?e.valueFields[h%e.valueFields.length]:null;a.width=d&&i.isNumber(d.width)?d.width:this.columns.defaultSize,a.wordWrap=d?d.wordWrap:null,a.format=d?d.format:null}}else this.topLeftCells.setCellData(0,0,null)},t.prototype._formatItem=function(e,t){var n=this._ng;if(n){if(t.panel==this.topLeftCells){t.cell.style.textAlign="";var r=t.row<t.panel.rows.length-1||0==n.rowFields.length;i.toggleClass(t.cell,"wj-col-field-hdr",r),i.toggleClass(t.cell,"wj-row-field-hdr",!r)}t.panel==this.columnHeaders&&(n.valueFields.length<2||t.row<t.panel.rows.length-1)&&(t.cell.style.textAlign="");var o=null;t.panel==this.topLeftCells&&t.row==t.panel.rows.length-1&&this.allowDragging&s.AllowDragging.Columns&&(o=!0),i.setAttribute(t.cell,"draggable",o);var l;switch(t.panel){case this.rowHeaders:l=n.rowFields[t.col%n.rowFields.length];break;case this.columnHeaders:l=n.columnFields[t.row];break;case this.cells:l=n.valueFields[t.col]}l&&l.isContentHtml&&(t.cell.innerHTML=t.cell.textContent);var a=n._getRowLevel(t.row),d=n._getColLevel(t.panel.columns[t.col].binding);if(i.toggleClass(t.cell,"wj-aggregate",a>-1||d>-1),this._collapsibleSubtotals){if(t.panel==this.rowHeaders&&n._getShowRowTotals()==P.Subtotals){h=this.getMergedRange(t.panel,t.row,t.col,!1)||t.range;t.col<n.rowFields.length-1&&h.rowSpan>1&&(t.cell.innerHTML=this._getCollapsedGlyph(this._getRowCollapsed(h))+t.cell.innerHTML)}if(t.panel==this.columnHeaders&&n._getShowColTotals()==P.Subtotals){var h=this.getMergedRange(t.panel,t.row,t.col,!1)||t.range;t.row<n.columnFields.length-1&&h.columnSpan>1&&(t.cell.innerHTML=this._getCollapsedGlyph(this._getColCollapsed(h))+t.cell.innerHTML)}}if(t.panel==this.topLeftCells&&this.showRowFieldSort&&t.col<n.rowFields.length&&t.row==this._getSortRowIndex()&&(l=n.rowFields[t.col],i.toggleClass(t.cell,"wj-sort-asc",!l.descending),i.toggleClass(t.cell,"wj-sort-desc",l.descending),t.cell.innerHTML+=' <span class="wj-glyph-'+(l.descending?"down":"up")+'"></span>'),this._centerVert&&t.cell.hasChildNodes&&(t.panel==this.rowHeaders||t.panel==this.columnHeaders)){var u=i.createElement('<div style="display:table-cell;vertical-align:middle"></div>');this._docRange||(this._docRange=document.createRange()),this._docRange.selectNodeContents(t.cell),this._docRange.surroundContents(u),i.setCss(t.cell,{display:"table",tableLayout:"fixed",paddingTop:0,paddingBottom:0})}}},t.prototype._getCollapsedGlyph=function(e){return'<div style="display:inline-block;cursor:pointer" '+t._WJA_COLLAPSE+'><span class="wj-glyph-'+(e?"plus":"minus")+'"></span></div>&nbsp'},t.prototype._mousedown=function(e){if(e.defaultPrevented||0!=e.button)this._htDown=null;else if(this._htDown=this.hitTest(e),null!=i.closest(e.target,"["+t._WJA_COLLAPSE+"]")&&null!=this._htDown.panel){var n=this._htDown.range,r=void 0;switch(this._htDown.panel.cellType){case s.CellType.RowHeader:r=this._getRowCollapsed(n),e.shiftKey||e.ctrlKey?this._collapseRowsToLevel(n.col+(r?2:1)):this._setRowCollapsed(n,!r);break;case s.CellType.ColumnHeader:r=this._getColCollapsed(n),e.shiftKey||e.ctrlKey?this._collapseColsToLevel(n.row+(r?2:1)):this._setColCollapsed(n,!r)}this._htDown=null,e.preventDefault()}},t.prototype._mouseup=function(e){if(this._htDown&&!e.defaultPrevented&&"col-resize"!=this.hostElement.style.cursor){var t=this.hitTest(e);if(this._htDown.panel==t.panel&&t.range.equals(this._htDown.range)){var i=this._ng,n=this.topLeftCells;if(t.panel==n&&t.row==n.rows.length-1&&t.col>-1){if(this.allowSorting&&t.panel.columns[t.col].allowSorting&&!i.isUpdating){var r=new s.CellRangeEventArgs(t.panel,t.range);if(this.onSortingColumn(r)){i.pivotView.sortDescriptions.clear();var o=i.rowFields[t.col];o.descending=!o.descending,this.onSortedColumn(r)}}e.preventDefault()}}}},t.prototype._dblclick=function(e){if(!e.defaultPrevented&&this._showDetailOnDoubleClick){var t=this._htDown;if(t&&t.panel==this.cells){var i=this._ng;i&&i.fields.length>0&&(i.fields[0]instanceof w||this.showDetail(t.row,t.col))}}},t.prototype._getRowLevel=function(e){return this._ng._getRowLevel(e)},t.prototype._getGroupedRows=function(e){var t,n,r=this._getRowLevel.bind(this),o=e.col+1;if(this._ng.totalsBeforeData){for(n=e.row;n<this.rows.length-1&&!((l=r(n+1))>-1&&l<=o);n++);for(t=n;t>0&&r(t)!=o;t--);}else{for(t=e.row;t>0;t--){var l=r(t-1);if(l>-1&&l<=o)break}for(n=t;n<this.rows.length-1&&r(n)!=o;n++);}return r(t)==o&&t++,r(n)==o&&n--,i.assert(n>=t,"group end < start?"),n>=t?new s.CellRange(t,e.col,n,e.col2):e},t.prototype._toggleRowCollapsed=function(e){this._setRowCollapsed(e,!this._getRowCollapsed(e))},t.prototype._getRowCollapsed=function(e){e=this._getGroupedRows(e);var t=this._ng.totalsBeforeData?e.row-1:e.row2+1,i=this.rows[t]||this.rows[e.row],n=i?i.dataItem[v._ROW_KEY_NAME]:null;return!!n&&this._collapsedKeys[n.toString()]},t.prototype._setRowCollapsed=function(e,t){var n=this;e=this._getGroupedRows(e);var r=this._ng.totalsBeforeData?e.row-1:e.row2+1,o=this.rows[r]||this.rows[e.row],l=o?o.dataItem[v._ROW_KEY_NAME]:null;l&&(this._collapsedKeys[l.toString()]=t),this.deferUpdate(function(){for(d=e.row;d<=e.row2;d++)n.rows[d].visible=!t;if(o&&(o.visible=!0),!t){for(var l=n._getRowLevel(r),a=[],d=e.row;d<=e.row2;d++)if(n._getRowLevel(d)>-1){var h=n._getGroupedRows(new s.CellRange(d,l));i.assert(h.row>=e.row&&h.row2<=e.row2,"child range overflow"),a.push(h),d++}a.forEach(function(e){var t=n._getRowCollapsed(e);n._setRowCollapsed(e,t)})}})},t.prototype._collapseRowsToLevel=function(e){var t=this;e>=this._ng.rowFields.length&&(e=-1),this.deferUpdate(function(){for(var i=0;i<t.rows.length;i++){var n=t._getRowLevel(i);if(n>0){var r=t.rows[i].dataItem[v._ROW_KEY_NAME];t._collapsedKeys[r.toString()]=e>0&&n>=e}if(e<0)t.rows[i].visible=!0;else{var s=n>-1&&n<=e;s||(t._ng.totalsBeforeData?0==i&&(s=!0):i==t.rows.length-1&&(s=!0)),t.rows[i].visible=s}}})},t.prototype._getColLevel=function(e){return this._ng._getColLevel(this.columns[e].binding)},t.prototype._getGroupedCols=function(e){var t,n=this._getColLevel.bind(this),r=e.row+1,o=e.col;if(this._ng.totalsBeforeData)for(o=e.col2;o<this.columns.length&&(l=n(o))==r;o++);for(;o>0&&!((l=n(o-1))>-1&&l<=r);o--);for(t=o;t<this.columns.length-1;t++){var l=n(t+1);if(l>-1&&l<=r)break}return n(o)==r&&o++,n(t)==r&&t--,i.assert(t>=o,"group end < start?"),t>=o?new s.CellRange(e.row,o,e.row2,t):e},t.prototype._toggleColCollapsed=function(e){this._setColCollapsed(e,!this._getColCollapsed(e))},t.prototype._getColCollapsed=function(e){e=this._getGroupedCols(e);var t=this._ng,i=t.totalsBeforeData?e.col-t.valueFields.length:e.col2+1,n=this.columns[i],r=n?n.binding:null;return!!r&&this._collapsedKeys[r.toString()]},t.prototype._setColCollapsed=function(e,t){var n=this;e=this._getGroupedCols(e);var r=this._ng,o=r.totalsBeforeData?e.col-r.valueFields.length:e.col2+1,l=this.columns[o],a=l?l.binding:null;a&&(this._collapsedKeys[a.toString()]=t),this.deferUpdate(function(){for(var l=1;l<=r.valueFields.length;l++)n.columns[r.totalsBeforeData?e.col-l:e.col2+l].visible=!0;for(h=e.col;h<=e.col2;h++)n.columns[h].visible=!t;if(!t){for(var a=n._getColLevel(o),d=[],h=e.col;h<=e.col2;h++)if(n._getColLevel(h)>-1){var u=n._getGroupedCols(new s.CellRange(a,h));i.assert(u.col>=e.col&&u.col2<=e.col2,"child range overflow"),d.push(u),h+=r.valueFields.length-1}d.forEach(function(e){var t=n._getColCollapsed(e);n._setColCollapsed(e,t)})}})},t.prototype._collapseColsToLevel=function(e){var t=this;e>=this._ng.columnFields.length&&(e=-1),this.deferUpdate(function(){for(var i=0;i<t.columns.length;i++){var n=t._getColLevel(i);if(n>0){var r=t._ng._getKey(t.columns[i].binding);t._collapsedKeys[r.toString()]=e>0&&n>=e}if(e<0)t.columns[i].visible=!0;else{var s=n>-1&&n<=e;t.columns[i].visible=s}}})},t._WJA_COLLAPSE="wj-pivot-collapse",t}(s.FlexGrid);t.PivotGrid=X;var z=function(e){function t(t,n){var r=e.call(this,t,null)||this,o=r.getTemplate();r.applyTemplate("wj-control wj-detaildialog",o,{_sCnt:"sp-cnt",_dSummary:"div-summary",_dGrid:"div-grid",_btnOK:"btn-ok",_gHdr:"g-hdr"});var l=i.culture.olap.DetailDialog;return r._gHdr.textContent=l.header,r._btnOK.textContent=l.ok,r._g=new s.FlexGrid(r._dGrid,{isReadOnly:!0}),r.initialize(n),r}return __extends(t,e),t.prototype.showDetail=function(e,t){var n=this,r=e.getDetailView(t.row,t.col);this._g.itemsSource=r;var s=i.tryCast(r,"IPagedCollectionView");this._updateDetailCount(s?s.totalItemCount:r.items.length),r.collectionChanged.addHandler(function(){n._updateDetailCount(r.items.length)});var o=e.engine,l=i.culture.olap.DetailDialog,a="",d=e.rows[t.row].dataItem[v._ROW_KEY_NAME];this._rowHdr=i.escapeHtml(this._getHeader(d)),this._rowHdr&&(a+=l.row+": <b>"+this._rowHdr+"</b><br>");var h=o._getKey(e.columns[t.col].binding);this._colHdr=i.escapeHtml(this._getHeader(h)),this._colHdr&&(a+=l.col+": <b>"+this._colHdr+"</b><br>");var u=o.valueFields,c=u[t.col%u.length],p=e.getCellData(t.row,t.col,!0);this._cellHdr=i.escapeHtml(c.header),this._cellValue=i.escapeHtml(p),a+=this._cellHdr+": <b>"+this._cellValue+"</b>",this._dSummary.innerHTML=a},Object.defineProperty(t.prototype,"rowHeader",{get:function(){return this._rowHdr},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"columnHeader",{get:function(){return this._colHdr},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"cellHeader",{get:function(){return this._cellHdr},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"cellValue",{get:function(){return this._cellValue},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"detailCount",{get:function(){return this._detailCount},enumerable:!0,configurable:!0}),t.prototype._updateDetailCount=function(e){var t=i.culture.olap.DetailDialog;this._sCnt.textContent=i.format(1==e?t.item:t.items,{cnt:e}),this._detailCount=e},t.prototype._getHeader=function(e){if(e&&e.values&&e.values.length){for(var t=[],i=0;i<e.values.length;i++)t.push(e.getValue(i,!0));return t.join(" - ")}return null},t.controlTemplate='<div><div class="wj-dialog-header"><span wj-part="g-hdr">Detail View:</span> <span wj-part="sp-cnt"></span></div><div class="wj-dialog-body"><div wj-part="div-summary" class="wj-summary"></div><div wj-part="div-grid"></div></div><div class="wj-dialog-footer"><button wj-part="btn-ok"class="wj-hide wj-btn">OK</button>&nbsp;&nbsp;</div></div>',t}(r.Popup);t.DetailDialog=z;var Q;!function(e){e[e.Column=0]="Column",e[e.Bar=1]="Bar",e[e.Scatter=2]="Scatter",e[e.Line=3]="Line",e[e.Area=4]="Area",e[e.Pie=5]="Pie"}(Q=t.PivotChartType||(t.PivotChartType={}));var J;!function(e){e[e.Always=0]="Always",e[e.Never=1]="Never",e[e.Auto=2]="Auto"}(J=t.LegendVisibility||(t.LegendVisibility={}));var Z=function(e){function t(n,r){var s=e.call(this,n)||this;return s._chartType=Q.Column,s._showHierarchicalAxes=!0,s._showTotals=!1,s._showTitle=!0,s._showLegend=J.Always,s._legendPosition=o.Position.Right,s._maxSeries=t.MAX_SERIES,s._maxPoints=t.MAX_POINTS,s._stacking=o.Stacking.None,s._colItms=[],s._dataItms=[],s._lblsSrc=[],s._grpLblsSrc=[],i.addClass(s.hostElement,"wj-pivotchart"),s._isPieChart()?s._createFlexPie():s._createFlexChart(),e.prototype.initialize.call(s,r),s}return __extends(t,e),t.prototype._getProductInfo=function(){return"D6F4,PivotChart"},Object.defineProperty(t.prototype,"engine",{get:function(){return this._ng},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"itemsSource",{get:function(){return this._itemsSource},set:function(e){if(e&&this._itemsSource!==e){var t=this._itemsSource;e instanceof q?e=e.engine.pivotView:e instanceof R&&(e=e.pivotView),this._itemsSource=i.asCollectionView(e),this._onItemsSourceChanged(t)}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"chartType",{get:function(){return this._chartType},set:function(e){if((e=i.asEnum(e,Q))!=this._chartType){var t=this._chartType;this._chartType=e,this._changeChartType(),e!==Q.Bar&&t!==Q.Bar||this._updatePivotChart()}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"showHierarchicalAxes",{get:function(){return this._showHierarchicalAxes},set:function(e){e!=this._showHierarchicalAxes&&(this._showHierarchicalAxes=i.asBoolean(e,!0),!this._isPieChart()&&this._flexChart&&this._updateFlexChart(this._dataItms,this._lblsSrc,this._grpLblsSrc))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"showTotals",{get:function(){return this._showTotals},set:function(e){e!=this._showTotals&&(this._showTotals=i.asBoolean(e,!0),this._updatePivotChart())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"showTitle",{get:function(){return this._showTitle},set:function(e){e!=this._showTitle&&(this._showTitle=i.asBoolean(e,!0),this._updatePivotChart())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"showLegend",{get:function(){return this._showLegend},set:function(e){(e=i.asEnum(e,J))!=this.showLegend&&(this._showLegend=e,this._updatePivotChart())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"legendPosition",{get:function(){return this._legendPosition},set:function(e){(e=i.asEnum(e,o.Position))!=this.legendPosition&&(this._legendPosition=e,this._updatePivotChart())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"stacking",{get:function(){return this._stacking},set:function(e){(e=i.asEnum(e,o.Stacking))!=this._stacking&&(this._stacking=e,this._flexChart&&(this._flexChart.stacking=this._stacking,this._updatePivotChart()))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"maxSeries",{get:function(){return this._maxSeries},set:function(e){e!=this._maxSeries&&(this._maxSeries=i.asNumber(e),this._updatePivotChart())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"maxPoints",{get:function(){return this._maxPoints},set:function(e){e!=this._maxPoints&&(this._maxPoints=i.asNumber(e),this._updatePivotChart())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"flexChart",{get:function(){return this._flexChart},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"flexPie",{get:function(){return this._flexPie},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"header",{get:function(){return this._header},set:function(e){e!=this._header&&(this._header=i.asString(e,!0),this.invalidate())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"footer",{get:function(){return this._footer},set:function(e){e!=this._footer&&(this._footer=i.asString(e,!0),this.invalidate())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"headerStyle",{get:function(){return this._headerStyle},set:function(e){e!=this._headerStyle&&(this._headerStyle=e,this.invalidate())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"footerStyle",{get:function(){return this._footerStyle},set:function(e){e!=this._footerStyle&&(this._footerStyle=e,this.invalidate())},enumerable:!0,configurable:!0}),t.prototype.refresh=function(t){void 0===t&&(t=!0),e.prototype.refresh.call(this,t),this._isPieChart()?this._flexPie&&this._flexPie.refresh(t):this._flexChart&&this._flexChart.refresh(t),this._updatePivotChart()},t.prototype.saveImageToDataUrl=function(e,t){this._isPieChart()?this._flexPie&&this._flexPie.saveImageToDataUrl(e,t):this._flexChart&&this._flexChart.saveImageToDataUrl(e,t)},t.prototype.saveImageToFile=function(e){this._isPieChart()?this._flexPie&&this._flexPie.saveImageToFile(e):this._flexChart&&this._flexChart.saveImageToFile(e)},t.prototype._onItemsSourceChanged=function(e){this._ng&&this._ng.updatedView.removeHandler(this._updatePivotChart,this),e&&e.collectionChanged.removeHandler(this._updatePivotChart,this);var t=this._itemsSource;this._ng=t instanceof y?t.engine:null,this._ng&&this._ng.updatedView.addHandler(this._updatePivotChart,this),this._itemsSource&&this._itemsSource.collectionChanged.addHandler(this._updatePivotChart,this),this._updatePivotChart()},t.prototype._createFlexChart=function(){var e=this,t=document.createElement("div");this.hostElement.appendChild(t),this._flexChart=new o.FlexChart(t),this._flexChart._bindingSeparator=null,this._flexChart.legend.position=o.Position.Right,this._flexChart.bindingX=v._ROW_KEY_NAME,this._flexChart.stacking=this._stacking,this._flexChart.tooltip.content=function(t){var i=t.name?"<b>"+t.name+"</b> <br/>":"";return i+=e._getLabel(t.x)+" "+e._getValue(t)},this._flexChart.hostElement.style.visibility="hidden"},t.prototype._createFlexPie=function(){var e=this,t=document.createElement("div");this.hostElement.appendChild(t),this._colMenu=new r.Menu(t),this._colMenu.displayMemberPath="text",this._colMenu.selectedValuePath="prop",this._colMenu.hostElement.style.visibility="hidden";var i=document.createElement("div");this.hostElement.appendChild(i),this._flexPie=new o.FlexPie(i),this._flexPie.bindingName=v._ROW_KEY_NAME,this._flexPie.tooltip.content=function(t){return"<b>"+e._getLabel(e._dataItms[t.pointIndex][v._ROW_KEY_NAME])+"</b> <br/>"+e._getValue(t)},this._flexPie.rendering.addHandler(this._updatePieInfo,this)},t.prototype._updatePivotChart=function(){if(this._ng&&this._ng.pivotView){for(var e,t=[],i=[],n=[],r=0,s=this._ng.pivotView,o=this._ng.rowFields,l=0;l<s.items.length;l++){var a=s.items[l],d=a.$rowKey;if(0==l&&this._getColumns(a),t.length>=this._maxPoints)break;if(!this._isTotalRow(a[v._ROW_KEY_NAME])){t.push(a),i.push({value:t.length-1,text:this._getLabel(a[v._ROW_KEY_NAME])});for(c=0;c<o.length;c++)if(n.length<=c&&n.push([]),this._getMergeIndex(d,e)<c){r=n[c].length-1;var h=n[c][r];if(0===r&&c<o.length-1&&(h.value=(h.width-1)/2),r>0&&c<o.length-1){var u=this._getOffsetWidth(n[c]);h.value=u+(h.width-1)/2}n[c].push({value:t.length-1,text:d.getValue(c,!0),width:1})}else r=n[c].length-1,n[c][r].width++;e=d}}for(var c=0;c<o.length;c++)c<n.length&&(r=n[c].length-1,n[c][r].value=this._getOffsetWidth(n[c])+(n[c][r].width-1)/2);this._dataItms=t,this._lblsSrc=i,this._grpLblsSrc=n,this._updateFlexChartOrPie()}},t.prototype._updateFlexChartOrPie=function(){var e=this._isPieChart();!e&&this._flexChart?this._updateFlexChart(this._dataItms,this._lblsSrc,this._grpLblsSrc):e&&this._flexPie&&this._updateFlexPie(this._dataItms,this._lblsSrc)},t.prototype._updateFlexChart=function(e,t,i){var n,r=this._flexChart,s=r?r.hostElement:null;if(this._ng&&r&&s){if(r.beginUpdate(),r.itemsSource=e,this._createSeries(),r.series&&r.series.length>0&&e.length>0?s.style.visibility="visible":s.style.visibility="hidden",r.header=this.header||this._getChartTitle(),this.headerStyle&&(r.headerStyle=this.headerStyle),this.footer&&(r.footer=this.footer),this.footerStyle&&(r.footerStyle=this.footerStyle),this._isRotatedChart()){if(this._showHierarchicalAxes&&i.length>0){if(r.axisY.itemsSource=i[i.length-1],r.axisX.labelAngle=void 0,i.length>=2)for(l=i.length-2;l>=0;l--)this._createGroupAxes(i[l])}else r.axisY.labelAngle=void 0,r.axisY.itemsSource=t;r.axisX.itemsSource=void 0}else{if(this._showHierarchicalAxes&&i.length>0){if(r.axisX.itemsSource=i[i.length-1],i.length>=2)for(var l=i.length-2;l>=0;l--)this._createGroupAxes(i[l])}else r.axisX.labelAngle=void 0,r.axisX.itemsSource=t;r.axisY.itemsSource=void 0}r.axisX.labelPadding=6,r.axisY.labelPadding=6,this._isRotatedChart()?(n=r.axisX,r.axisY.reversed=!0):(n=r.axisY,r.axisY.reversed=!1),r.stacking!==o.Stacking.Stacked100pc&&this._ng.valueFields.length>0&&this._ng.valueFields[0].format?n.format=this._ng.valueFields[0].format:n.format="",r.legend.position=this._getLegendPosition(),r.endUpdate()}},t.prototype._updateFlexPie=function(e,t){var i=this._flexPie,n=i?i.hostElement:null,r=this._colMenu;if(this._ng&&i&&n){this._colItms.length>0&&e.length>0?n.style.visibility="visible":n.style.visibility="hidden",i.beginUpdate(),i.itemsSource=e,i.bindingName=v._ROW_KEY_NAME,this._colItms&&this._colItms.length>0&&(i.binding=this._colItms[0].prop),i.header=this.header||this._getChartTitle(),this.headerStyle&&(i.headerStyle=this.headerStyle),this.footer&&(i.footer=this.footer),this.footerStyle&&(i.footerStyle=this.footerStyle),i.legend.position=this._getLegendPosition(),i.endUpdate();var s=this._getTitle(this._ng.columnFields);""!==s&&(s="<b>"+s+": </b>"),this._colItms&&this._colItms.length>1&&e.length>0?(r.hostElement.style.visibility="visible",r.header=s+this._colItms[0].text,r.itemsSource=this._colItms,r.command={executeCommand:function(e){var t=r.selectedItem;r.header=s+t.text,i.binding=t.prop}},r.selectedIndex=0,r.invalidate(),r.listBox.invalidate()):r.hostElement.style.visibility="hidden"}},t.prototype._getLegendPosition=function(){var e=this.legendPosition;if(this.showLegend==J.Never)e=o.Position.None;else if(this.showLegend==J.Auto&&this.flexChart&&this.flexChart.series){var t=0;this.flexChart.series.forEach(function(e){var i=e.visibility;e.name&&i!=o.SeriesVisibility.Hidden&&i!=o.SeriesVisibility.Plot&&t++}),t<2&&(e=o.Position.None)}return e},t.prototype._createSeries=function(){this._flexChart&&(this._flexChart.series.length=0);for(var e=1==this._ng.valueFields.length,t=0;t<this._colItms.length;t++){var i=new o.Series,n=this._colItms[t].prop,r=this._colItms[t].text;if(e){var s=r.lastIndexOf(";");s>-1&&(r=r.substr(0,s))}i.binding=n,i.name=r,this._flexChart.series.push(i)}},t.prototype._getColumns=function(e){var t,i=0;if(e){this._colItms=[];for(var n in e)e.hasOwnProperty(n)&&n!==v._ROW_KEY_NAME&&i<this._maxSeries&&this._isValidColumn(n)&&(t=this._ng._getKey(n),this._getLabel(t),this._colItms.push({prop:n,text:this._getLabel(t)}),i++)}},t.prototype._createGroupAxes=function(e){var i,n=this,r=this._flexChart,s=this._isRotatedChart()?r.axisY:r.axisX;if(e){(i=new o.Axis).labelAngle=0,i.labelPadding=6,i.position=this._isRotatedChart()?o.Position.Left:o.Position.Bottom,i.majorTickMarks=o.TickMark.None,i.itemsSource=e,i.reversed=s.reversed,i.itemFormatter=function(r,s){var o=.5*e.filter(function(e){return e.value==s.val})[0].width;if(n._isRotatedChart()){var l=i.reversed?-1:1,a=i.convert(s.val+o)+5*l,d=i.convert(s.val-o)-5*l,h=i._axrect.left+i._axrect.width-5;r.drawLine(h,a,h,d,t.HRHAXISCSS),r.drawLine(h,a,h+5,a,t.HRHAXISCSS),r.drawLine(h,d,h+5,d,t.HRHAXISCSS),r.drawLine(h,s.pos.y,h-5,s.pos.y,t.HRHAXISCSS)}else{var u=i.convert(s.val-o)+5,c=i.convert(s.val+o)-5,p=i._axrect.top;r.drawLine(u,p,c,p,t.HRHAXISCSS),r.drawLine(u,p,u,p-5,t.HRHAXISCSS),r.drawLine(c,p,c,p-5,t.HRHAXISCSS),r.drawLine(s.pos.x,p,s.pos.x,p+5,t.HRHAXISCSS)}return s},i.min=s.actualMin,i.max=s.actualMax,s.rangeChanged.addHandler(function(){isNaN(i.min)&&isNaN(s.actualMin)||i.min==s.actualMin||(i.min=s.actualMin),isNaN(i.max)&&isNaN(s.actualMax)||i.max==s.actualMax||(i.max=s.actualMax)});var l=new o.Series;l.visibility=o.SeriesVisibility.Hidden,this._isRotatedChart()?l.axisY=i:l.axisX=i,r.series.push(l)}},t.prototype._updateFlexPieBinding=function(){this._flexPie.binding=this._colMenu.selectedValue,this._flexPie.refresh()},t.prototype._updatePieInfo=function(){var e=this;this._flexPie&&(this._flexPie._labels=this._flexPie._labels.map(function(t,i){return e._lblsSrc[i].text}))},t.prototype._changeChartType=function(){var e=null;if(this.chartType===Q.Pie)this._flexPie||this._createFlexPie(),this._updateFlexPie(this._dataItms,this._lblsSrc),this._swapChartAndPie(!1);else{switch(this.chartType){case Q.Column:e=o.ChartType.Column;break;case Q.Bar:e=o.ChartType.Bar;break;case Q.Scatter:e=o.ChartType.Scatter;break;case Q.Line:e=o.ChartType.Line;break;case Q.Area:e=o.ChartType.Area}this._flexChart?"none"!==this._flexChart.hostElement.style.display&&e!==Q.Bar&&this._flexChart.chartType!==o.ChartType.Bar||this._updateFlexChart(this._dataItms,this._lblsSrc,this._grpLblsSrc):(this._createFlexChart(),this._updateFlexChart(this._dataItms,this._lblsSrc,this._grpLblsSrc)),this._flexChart.chartType=e,this._swapChartAndPie(!0)}},t.prototype._swapChartAndPie=function(e){var t=this;this._flexChart&&(this._flexChart.hostElement.style.display=e?"block":"none"),this._flexPie&&(this._flexPie.hostElement.style.display=e?"none":"block"),this._colMenu&&this._colMenu.hostElement&&(this._colMenu.hostElement.style.display=e?"none":"block",this._colMenu.hostElement.style.top="0",setTimeout(function(){t._colMenu.hostElement.style.top=""},0))},t.prototype._getLabel=function(e){var t="";if(!e||!e.values)return t;var i=e.valueFields?e.valueField:null;switch(e.values.length){case 0:i&&(t+=i.header);break;case 1:t+=e.getValue(0,!0),i&&(t+="; "+i.header);break;default:for(var n=0;n<e.values.length;n++)n>0&&(t+="; "),t+=e.getValue(n,!0);i&&(t+="; "+i.header)}return t},t.prototype._getValue=function(e){var t=this._ng.valueFields,n=e.series?e.series.chart.series.indexOf(e.series):0,r=n<t.length?t[n].format:t.length?t[0].format:"";return r?i.Globalize.format(e.y,r):e._yfmt},t.prototype._getChartTitle=function(){if(!this.showTitle||!this._ng.valueFields.length)return null;var e=this._ng,t=this._getTitle(e.valueFields),n=this._getTitle(e.rowFields),r=this._getTitle(e.columnFields),s=t,o=i.culture.olap.PivotChart;return t&&this._dataItms.length>0&&(n&&(s+=i.format(" {by} {rows}",{by:o.by,rows:n})),r&&(s+=i.format(" {and} {cols}",{and:n?o.and:o.by,cols:r}))),s},t.prototype._getTitle=function(e){for(var t="",i=0;i<e.length;i++)t.length>0&&(t+="; "),t+=e[i].header;return t},t.prototype._isValidColumn=function(e){var t=e.split(";"),i=this._showTotals;return 0===this._ng.columnFields.length||(t&&2===t.length?i:!(!t||t.length-2!==this._ng.columnFields.length)&&!i)},t.prototype._isTotalRow=function(e){return e.values.length<this._ng.rowFields.length},t.prototype._isPieChart=function(){return this._chartType==Q.Pie},t.prototype._isRotatedChart=function(){return!this._isPieChart()&&this._chartType==Q.Bar!==this._flexChart.rotated},t.prototype._getMergeIndex=function(e,t){var i=-1;if(null!=e&&null!=t&&e.values.length==t.values.length&&e.values.length==e.fields.length&&t.values.length==t.fields.length)for(var n=0;n<e.values.length;n++){if(e.getValue(n,!0)!=t.getValue(n,!0))return i;i=n}return i},t.prototype._getOffsetWidth=function(e){var t=0;if(e.length<=1)return t;for(var i=0;i<e.length-1;i++)t+=e[i].width;return t},t.MAX_SERIES=100,t.MAX_POINTS=100,t.HRHAXISCSS="wj-hierarchicalaxes-line",t}(i.Control);t.PivotChart=Z;var $=function(e){function t(t,n){var r=e.call(this,t,null,i.isIE()&&!i.isEdge())||this;r._mSel=!1,r._fldPropChangeBnd=r._fldPropChange.bind(r);var s=r.getTemplate();r.applyTemplate("wj-slicer wj-nocheck wj-control wj-content",s,{_root:"root",_divHdr:"div-hdr",_divHdrText:"div-hdr-text",_btnMSel:"btn-msel",_btnClear:"btn-clear"});var o=i.culture.olap.Slicer,l=new i.Tooltip;return i.setAttribute(r._btnMSel,"aria-label",o.multiSelect),i.setAttribute(r._btnClear,"aria-label",o.clearFilter),l.setTooltip(r._btnMSel,o.multiSelect),l.setTooltip(r._btnClear,o.clearFilter),r.addEventListener(r._btnClear,"click",function(e){r._clear()}),r.addEventListener(r._btnMSel,"click",function(e){r.multiSelect=!r.multiSelect}),r.initialize(n),r}return __extends(t,e),Object.defineProperty(t.prototype,"field",{get:function(){return this._fld},set:function(e){var t=this;if(e!=this._fld){this._divListBox&&(this.removeEventListener(this._divListBox,"click"),i.removeChild(this._divListBox),this._divListBox=null,this._lbx.dispose(),this._lbx=null),this._edt&&(this._clear(),this._edt.dispose());var r=this._fld;if(r&&r.propertyChanged.removeHandler(this._fldPropChangeBnd),(r=this._fld=i.asType(e,b,!0)).propertyChanged.addHandler(this._fldPropChangeBnd),r&&!r.isActive&&r.engine.filterFields.push(r),r){var s=document.createElement("div");this._edt=new n.ValueFilterEditor(s,r.filter.valueFilter)}this._edt&&(this._divListBox=this._edt.hostElement.querySelector(".wj-listbox"),this._root.appendChild(this._divListBox),this._lbx=i.Control.getControl(this._divListBox),this._lbx.checkedItemsChanged.addHandler(function(e,i){t.multiSelect||(t._mSel=!0,t._lbx.checkedItems=[t._lbx.selectedItem],t._mSel=!1),t._edt&&r&&(t._edt.updateFilter(),r.engine.invalidate())})),this._updateHeader(),i.isIE()&&!i.isEdge()&&this.refresh()}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"header",{get:function(){return this._hdr},set:function(e){e!=this._hdr&&(this._hdr=i.asString(e),this._updateHeader())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"showHeader",{get:function(){return"none"!=this._divHdr.style.display},set:function(e){this._divHdr.style.display=i.asBoolean(e)?"":"none"},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"showCheckboxes",{get:function(){return!i.hasClass(this.hostElement,"wj-nocheck")},set:function(e){i.toggleClass(this.hostElement,"wj-nocheck",!i.asBoolean(e))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"multiSelect",{get:function(){return this._mSel},set:function(e){this._mSel=i.asBoolean(e),i.toggleClass(this._btnMSel,"wj-state-active",this._mSel)},enumerable:!0,configurable:!0}),t.prototype.refresh=function(t){void 0===t&&(t=!0),i.isIE()&&!i.isEdge()&&this.hostElement&&i.setCss(this._lbx.hostElement,{height:this.hostElement.clientHeight-this._divHdr.offsetHeight}),e.prototype.refresh.call(this,t)},t.prototype._fldPropChange=function(e,t){switch(t.propertyName){case"header":this._updateHeader();break;case"format":case"binding":e.filter.clear(),this._edt.updateEditor()}},t.prototype._updateHeader=function(){var e=this._hdr;e||null==this._fld||(e=this._fld.header),this._divHdrText.textContent=e},t.prototype._clear=function(){this._edt&&(this._edt.clearEditor(),this._edt.updateFilter(),this._fld.engine.invalidate())},t.controlTemplate='<div wj-part="root"><div wj-part="div-hdr" class="wj-header"><div wj-part="div-hdr-text"></div><button wj-part="btn-msel" class="wj-btn btn-msel" tabindex="-1"><span class="wj-glyph">&#8801;</span></button><button wj-part="btn-clear" class="wj-btn btn-clear" tabindex="-1"><span class="wj-glyph">&times;</span></button></div></div>',t}(i.Control);t.Slicer=$});