(function(){"use strict";u8.Crm.Widgets.AnalysisResultChart=function(t,e){this.Widget(t,$.extend({},u8.Crm.Widgets.AnalysisResultChart.defaults,e));$assert(this.model,"Failed to create AnalysisResultChart widget! Missing property 'model'.");this.model.bind("Execute",this._onModelExecute.bind(this),this.id);this.commandDelegates=[this.model];this._isCreated=false;this._createDrillMenu=u8.Crm.Widgets.AnalysisResult.createDrillMenu;u8.using({types:["Charts"]},this._create.bind(this))};u8.Crm.Widgets.AnalysisResultChart.defaults={chartView:{},showEditor:true,showValues:true,showLegend:true,showDrillMenus:true};u8.Crm.Widgets.AnalysisResultChart.makeClass({name:"AnalysisResultChart",events:["Create"],deriveFrom:u8.Base.Widgets.Widget});$.extend(u8.Crm.Widgets.AnalysisResultChart.prototype,{dispose:function(){if(this._isDisposed){return}this.model.unbind("*",this.id);this.Widget_dispose()},_create:function(){if(this._isDisposed){return}var t=this;this._createModel(function(){if(t._isDisposed){return}t._createView();u8.tools.createdWhenReady(t)})},_createModel:function(t){this.chartView=$.extend(true,{options:{fixedChartType:this.fixedChartType,chartType:this.chartType,hideSelector:this.hideSelector,showValues:this.showValues,showLegend:this.showLegend}},this.chartView);if(!this.model.result){return this.model.wait("Execute",t)}else{t()}},_createView:function(){delete this._chart;this.empty();var t=this._createDataProvider();if(!t){return}var e=this.$("<div />").appendTo(this.element);this._chart=new u8.Base.Widgets.ChartView(e,$.extend({parent:this,dataProvider:t,onClick:this._onChartClick.bind(this),autoSize:true,aspectRatio:null,showEditor:this.showEditor},this.chartView))},_onChartClick:function(t,e){if(!this.showDrillMenus){return}var i=this.model.result,s=i&&i.rows[e.valueIndex];if(!s){return}var r=e.elEvent;var a=s.cat,h=this.model.settings.getDrillDowns({cat:a}),o=this._createDrillMenu(h,s,$t("TXT_StatisticControllerText_30"));if(!o){return}o.disposeOnHide=true;o.show({alignTo:r.target,position:{anchor:"left-middle"}})},_createDataProvider:function(){var t=this.model.result;var e={};$.extend(e,this.chartView&&this.chartView.options&&this.chartView.options.showValues!=null&&{chartOptions:{showvalues:this.chartView.options.showValues===false?"0":"1"}});$.extend(true,e,this._chart&&this._chart.options);var i=this.chartView&&this.chartView.options&&(this.chartView.options.chartType||this.chartView.options.fixedChartType);if(i=="Bubble"){return t&&t.buildBubbleChartDataProvider({options:e})}else{return t&&t.buildChartDataProvider({options:e})}},_onModelExecute:function(t){var e=this._chart;if(!e){return}e.dataProvider.result=t.result;e.update()}})})();