// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://@sbaseurl@/jsapi/jsapi/esri/copyright.txt and http://www.arcgis.com/apps/webappbuilder/copyright.txt for details.

//>>built
define(["dojo/_base/declare","dijit/_WidgetBase","dojo/_base/lang","jimu/clientStatisticsUtils","jimu/_chartHelpUtils"],function(p,q,e,l,r){return p([q],{postMixInProperties:function(){this.nls=window.jimuNls.statisticsChart},constructor:function(b){this.map=b.map;this.chartHelpUtils=new r({map:this.map,clientStatisticsUtils:l})},init:function(b,a,c,d,g){this.chartHelpUtils.setLayerFeatureLayer(b);this.chartHelpUtils.setSymbolLayer(a);this.chartHelpUtils.setPopupInfo(c);this.chartHelpUtils.setMap(d);
this.chartHelpUtils.setLayerObject(g);this.featureLayer=b;this.layerObject=g},getClientStatisticsData:function(b){var a=l.getClietStatisticsData(b);a=l.sortClientStatisticsData(a,b,this.layerObject||this.featureLayer);a=l.getDataForMaxLabels(a,b.maxLabels);return a=this.chartHelpUtils.keepStatisticsDataBestDecimalPlace(b,a,b.mode)},bindChartEvent:function(b,a,c){this.chartHelpUtils.bindChartEvent(b,a,c)},getChartOptionSeries:function(b,a){return this._createOptionSeries(b,a)},updateChartOptionDisplay:function(b,
a,c){this._assigneeSettingColorToSeries(b,a,c);this.chartHelpUtils.updateChartSeriesDisplayName(b,a,c);return this._mapSettingConfigToChartOption(b,a,c)},_assigneeSettingColorToSeries:function(b,a,c){if(!b||!b.series)return b;this.chartHelpUtils.assigneeSettingColor(a,b.series,c)},_createOptionSeries:function(b,a){var c=b.type,d=b.mode;b=b.valueFields;var g=[];g="count"===d?[""]:"field"===d?[""]:e.clone(b);var h=null;h={type:c,labels:[],series:[]};h.series=g.map(e.hitch(this,function(f){return{name:f,
type:c,data:[]}}));a.forEach(e.hitch(this,function(f){var m=f.label;h.labels.push(m);for(var k=0;k<f.values.length;k++){var n={value:f.values[k],name:m,unit:f.unit};"feature"===d&&(n.originValue=f.originalValues[k]);h.series[k].data.push(n)}}));return h},_mapSettingConfigToChartOption:function(b,a,c){var d=c.type;this._settingColorArrayForPie(b,a,d,c.mode);this._settingAxisDisplay(b,a,d);b.type=d;b.dataZoom=["inside","slider"];"pie"!==d&&(b.dataZoomOption={mode:a.displayRange||"AUTO"});b.confine=
!0;b.backgroundColor=a.backgroundColor;b.tooltip=a.tooltip?e.clone(a.tooltip):{confine:!0,trigger:"radar"===d||"pie"===d?"item":"axis",axisPointer:"pie"!==d?{type:"line"===d?"cross":"shadow",snap:!0}:{type:""}};a.marks&&a.marks.markLine&&(b.markLine=e.clone(a.marks.markLine));a.marks&&a.marks.markArea&&(b.markArea=e.clone(a.marks.markArea));a.legend&&(b.legend=e.clone(a.legend));a.xAxis&&(b.xAxis=e.clone(a.xAxis));a.yAxis&&(b.yAxis=e.clone(a.yAxis));a.dataLabel&&(b.dataLabel=e.clone(a.dataLabel));
"pie"===d&&(b.innerRadius=a.innerRadius);b.theme=a.theme||"light";return b},_settingColorArrayForPie:function(b,a,c,d){"pie"===c&&"field"!==d&&(a=a.seriesStyle)&&a.styles&&a.styles[0]&&(a=a.styles[0].style)&&Array.isArray(a.color)&&(c=e.clone(a.color),2===c.length&&(c=this.chartHelpUtils.getColors(e.clone(a.color),6)),b.color=c)},_settingAxisDisplay:function(b,a,c){if(!(0>["column","bar","line"].indexOf(c))){a.stack||(a.stack=!1);if("column"===c||"bar"===c||"line"===c&&a.area)b.stack=a.stack;"line"!==
c||a.area||(a.area=!1);"line"===c&&(b.area=a.area);b.scale=!1}}})});