// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
define("esri/dijit/geoenrichment/ReportPlayer/core/charts/chartUtils/builder/_ColumnBarLineChartBuilder","dojo/_base/declare dojo/_base/lang dojox/charting/axis2d/Default ../ThemeCalculator ../ChartTypes ../ChartSorting ../../../supportClasses/conditionalStyling/ConditionalStyleUtil ../plots/ClusteredColumns ../plots/StackedColumns ../plots/ClusteredBars ../plots/StackedBars ../plots/PictureClusteredColumns ../plots/PictureClusteredBars ../plots/Lines ../plots/StackedLines ../plots/Areas ../plots/StackedAreas ../../../themes/ReportThemes ../CustomGridPlot ../AxisUtil esri/dijit/geoenrichment/utils/ColorUtil ./_ChartDataUtil ./_TooltipInfoBuilder ./_ChartDataLabelBuilder ./ChartPlots".split(" "),
function(fa,l,ga,u,h,I,J,Q,R,S,T,U,V,v,W,X,Y,w,Z,aa,N,E,O,ba,n){function ca(a,b,c,e,m){a=288*e/680/(a+1);"Small"===c?a*=.5:"Large"===c&&(a*=1.5);return a/(m?1:b)}function F(a,b){return a.captionFieldInfo?E.getCaptionValue(a,b):a.label||""}var r={getComparisonPlotName:function(a,b){return b&&b.chartType===h.LINE&&a!==h.LINE?n.SECONDARY:null},isComparisonInPrimaryPlot:function(a,b){return!this.getComparisonPlotName(a,b)},getEffectiveNumberOfSeries:function(a,b,c){return this.canShowComparison(c,a)?
r.isComparisonInPrimaryPlot(b,c)?a.length+1:a.length:a.length},canShowComparison:function(a,b){return a&&1===b.length},updateSeriesItemsForComparisonInfo:function(a){if(this.canShowComparison(a.comparisonInfo,a.seriesItems)){var b=a.seriesItems.slice();b.push({isComparisonSeries:!0,label:a.selectedComparisonAreaName,points:b[0].points.slice()});a.seriesItemsWithComparison=b}}};return{configureChart:function(a){var b=a.chart,c=a.visualProperties,e=a.chartType,m=a.comparisonInfo,d=a.themeSettings,g=
a.viewModel;b._pointIndexToLabelMap={};var f=g.reportStyle===w.GRAPHIC&&l.mixin({},d.xAxis.axisStyle,c.xAxis.style),f=N.toColor(f.color||"#000000");f.a=E.undefinedToDefault(c.yAxis.gridLinesOpacity,1);f=N.toCSSColor(f);b.addPlot(n.GRID,{type:Z,vMajorLines:c.yAxis.gridLines,majorVLine:{color:f,width:.5},vMinorLines:!1,hMajorLines:c.xAxis.gridLines,majorHLine:{color:f,width:.5},hMinorLines:!1});f=b.getPlot(n.GRID);f.xHasHalfTickOffset=c.yAxis.gridLinesCentered;f.yHasHalfTickOffset=c.xAxis.gridLinesCentered;
var f={gap:50},p=-1!==c.dataLabels.indexOf("Label"),q=-1!==c.dataLabels.indexOf("Value"),da=-1!==c.dataLabels.indexOf("Percent"),ea=c.dataLabelsInside?"inside":"outside",p=p||q||da?{precision:0,labels:!0,labelStyle:ea,labelHorizontalAlign:c.dataLabelsHorizontalAlign,htmlLabels:!0,labelOffset:5,labelFunc:function(a){return ba.formatDataLabel(a.y,a.name,a._valuesSumsInSeries,c)}}:null,q=g.dynamicReportInfo&&g.chartAnimationAllowed?{animate:!0}:null;switch(e){case h.COLUMN:b.addPlot(n.PRIMARY,l.mixin({type:c.isStacked?
R:Q},f,p,q));break;case h.BAR:b.addPlot(n.PRIMARY,l.mixin({type:c.isStacked?T:S},f,p,q));break;case h.LINE:b.addPlot(n.PRIMARY,l.mixin({type:c.fillLineArea?c.isStacked?Y:X:c.isStacked?W:v,markers:g.reportStyle===w.GRAPHIC&&!c.fillLineArea},q));break;case h.PICTURE_COLUMN:b.addPlot(n.PRIMARY,l.mixin({type:U},f,p,q));break;case h.PICTURE_BAR:b.addPlot(n.PRIMARY,l.mixin({type:V},f,p,q))}r.isComparisonInPrimaryPlot(e,m)||(b.addPlot(n.SECONDARY,l.mixin({type:v,markers:!0})),b.movePlotToFront(n.SECONDARY));
b.movePlotToBack(n.GRID);b.addAxis("x",this._createXAxis(null,c,e,d,g,b));b.addAxis("y",this._createYAxis(null,c,e,d,g));this.updateBarSize(a)},_createXAxis:function(a,b,c,e,m,d){var g=b.xAxis;b="OtherSide"!==g.placement;var f=l.mixin({},e.xAxis.axisStyle,g.style),p=l.mixin({},e.xAxis.titleStyle,g.titleStyle),q=g.lineColor||e.xAxis.lineColor;c=h.isBarLike(c);m={stroke:{width:g.show&&g.showLine?1:0,color:q},title:g.title,titleOrientation:!c&&b?"away":"axis",titleFont:u.combineFontString(p),titleFontColor:p.color,
vertical:c,leftBottom:b,majorTicks:!0,majorTick:function(){var a=g.show&&g.showLine&&g.showTicks?5:0;g.ticksInside&&(a*=-1);return{length:a,color:q}}(),majorTickStep:1,minorTicks:!1,microTicks:!1,minorTickStep:.5,microTickStep:.01,font:u.combineFontString(f),fontColor:f.color,dropLabels:m.reportStyle===w.CLASSIC,majorLabels:g.show,minorLabels:!1,labelFunc:function(a,c,b){c=d._pointIndexToLabelMap&&d._pointIndexToLabelMap[c];return void 0!==c?c:a},rotation:-g.labelsAngle||0};return l.mixin(m,a)},_createYAxis:function(a,
b,c,e,m){var d=b.yAxis;b="OtherSide"!==d.placement;var g=l.mixin({},e.yAxis.axisStyle,d.style),f=l.mixin({},e.yAxis.titleStyle,d.titleStyle),p=d.lineColor||e.yAxis.lineColor;c=h.isBarLike(c);m={fixUpper:"major",includeZero:!0,stroke:{width:d.show&&d.showLine?1:0,color:p},title:d.title,titleOrientation:c&&b?"away":"axis",titleFont:u.combineFontString(f),titleFontColor:f.color,vertical:!c,leftBottom:b,majorTicks:!0,majorTick:function(){var a=d.show&&d.showLine&&d.showTicks?5:0;d.ticksInside&&(a*=-1);
return{length:a,color:p}}(),majorTickStep:200,minorTicks:!1,microTicks:!1,minorTickStep:100,microTickStep:10,font:u.combineFontString(g),fontColor:g.color,dropLabels:m.reportStyle===w.CLASSIC,majorLabels:d.show,minorLabels:!1,rotation:-d.labelsAngle||0,labelFunc:function(a,c,b){return a}};return l.mixin(m,a)},updateBarSize:function(a){var b=a.chart,c=a.visualProperties,e=a.comparisonInfo,m=a.seriesItems,d=a.chartType;a=a.chartSize;if(b&&d!==h.LINE){a=a||c[h.isColumnLike(d)?"width":"height"];var g=
0;m.forEach(function(a){g=Math.max(g,a.points.length)});c=ca(g,r.getEffectiveNumberOfSeries(m,d,e),c.columnThickness,a,c.isStacked);b.getPlot(n.PRIMARY).opt.maxBarSize=c;b.getPlot(n.PRIMARY).opt.minBarSize=c}},calcSeries:function(a){r.updateSeriesItemsForComparisonInfo(a);if(a.chartType===h.LINE)return this._calcSeriesLine(a);if(a.seriesItemsWithComparison&&!r.isComparisonInPrimaryPlot(a.chartType,a.comparisonInfo)){var b=a.seriesItemsWithComparison[a.seriesItemsWithComparison.length-1];delete a.seriesItemsWithComparison;
var c=this._calcSeriesColumnBar(a),e=l.mixin({},a);e.seriesItems=[b];e.isSecondaryPlot=!0;e.primarySeries=c[0];e.reverseXY=h.isBarLike(a.chartType);a=this._calcSeriesLine(e);return c.concat(a)}return this._calcSeriesColumnBar(a)},_updatePointIndexToLabelMap:function(a,b,c,e){var m=a._pointIndexToLabelMap[b];if(void 0===m||""===m)a._pointIndexToLabelMap[b]=F(c,e)},_calcSeriesColumnBar:function(a){var b=a.chart,c=a.visualProperties,e=a.seriesItems,m=1===e.length,e=a.seriesItemsWithComparison||e,d=a.chartType,
g=a.comparisonInfo,f=a.themeSettings,p=a.viewModel,q=a.previewFeatureIndex,h=a.isMultiFeatureChart,l=a.excludedSeriesHash,n=1===e.length&&a.sorting,w=a.selectedComparisonIndex,G=a.ge,L=this,t=0,z=[],k;c.isStacked&&(k=[]);b._pointIndexToLabelMap={};var H={},A;c.conditionalStyling&&(a=J.getStatistics(c.conditionalStyling))&&e.length&&(A=E.getChartData(a,e[0].points.length));e.forEach(function(a,e){if(a.points.length){var x={name:a.label,data:[],params:{plot:a.isComparisonSeries&&r.getComparisonPlotName(d,
g)||void 0}},P=[],K=0,M=1E6,B=-1E6;a.points.forEach(function(c,b){var d=E.getPreviewValue(c,b,e,!1,p,h?b:q,A,a.isComparisonSeries,w,G),d=(P[b]=d)||0;l&&l[a.label]||(k?(k[b]=k[b]||0,k[b]+=d):t=Math.max(d,t),K+=d,M=Math.min(M,d),B=Math.max(B,d))});var D=K/a.points.length;u.provideMissingIconsForPoints(a.points,d);a.points.forEach(function(b,k){var n=P[k],q=n||0,l=k+1,y;c.conditionalStyling&&(y=(y=J.getConditionalStyle(q,c.conditionalStyling))&&y.backgroundColor);y=y||u.calcColorForPoint(b,a,k,e,m?1:
2,d,f,a.isComparisonSeries,g);var h=O.getTooltipInfo(n,F(b,p),a.label,M,B,K,D,c,d,y,c.conditionalStyling),C=H[l]=H[l]||[];C.push(h);h.getGroup=function(){return C};var t=u.calcIconForPoint(b,y,d),r=u.calcBackgroundIconForPoint(b,d,f,c);x.data.push({x:l,y:q,isUnavailableData:isNaN(n),valueProp:"y",unsortedIndex:k,name:F(b,p),_valuesSumsInSeries:K,point:b,fill:y,tooltip:h,icon:t,bgIcon:r,stroke:{width:0}})});n&&n!==I.NONE&&(x.data.sort(function(a,b){return(a.y-b.y)*(n===I.DESC?-1:1)}),x.data.forEach(function(a,
b){a.x=b+1}));x.data.forEach(function(a){L._updatePointIndexToLabelMap(b,a.x,a.point,p)});z.push(x)}});k&&(k.sort(function(a,b){return b-a}),t=k[0]);this._prettifyYAxis(t,b,c,d,f,p);return z},_calcSeriesLine:function(a){var b=a.chart,c=a.visualProperties,e=a.seriesItems,m=1===e.length,e=a.seriesItemsWithComparison||e,d=a.isSecondaryPlot,g=a.reverseXY,f=a.comparisonInfo,l=a.themeSettings,q=a.viewModel,r=a.previewFeatureIndex,w=a.isMultiFeatureChart,I=a.selectedComparisonIndex,J=a.ge,G=h.LINE,L=this,
t=0,z=[],k;c.isStacked&&(k=[]);var H={};e.forEach(function(d,e){if(d.points.length){var h=d.isComparisonSeries?1:e,p=u.calcColorForPoint(null,d,0,h,m?1:2,G,l,d.isComparisonSeries,f),x={name:d.label,data:[],params:{plot:d.isComparisonSeries&&a.isSecondaryPlot?n.SECONDARY:void 0,stroke:{color:p,width:c.lineThickness||1}}},B=[],D=0,C=1E6,v=-1E6;d.points.forEach(function(a,b){var c=E.getPreviewValue(a,b,h,!1,q,w?b:r,null,d.isComparisonSeries,I,J),c=(B[b]=c)||0;k?(k[b]=k[b]||0,k[b]+=c):t=Math.max(c,t);
D+=c;C=Math.min(C,c);v=Math.max(v,c)});var A=D/d.points.length;d.points.forEach(function(a,e){var f=B[e],l=f||0,h=e+1;L._updatePointIndexToLabelMap(b,h,a,q);var k=O.getTooltipInfo(f,F(a,q),d.label,C,v,D,A,c,G,p),m=H[h]=H[h]||[];m.push(k);k.getGroup=function(){return m};f={isUnavailableData:isNaN(f),unsortedIndex:e,name:F(a,q),_valuesSumsInSeries:D,point:a,fill:"#FFFFFF",stroke:{color:p},tooltip:k};g?(f.x=l,f.y=h,f.valueProp="x"):(f.x=h,f.y=l,f.valueProp="y");d.isComparisonSeries&&(f.marker=u.getComparisonSymbol());
x.data.push(f)});z.push(x)}});k&&(k.sort(function(a,b){return b-a}),t=k[0]);if(d){var A=g?"y":"x",v=[];a.primarySeries.data.forEach(function(a){var b=z[0].data[a.unsortedIndex];b[A]=a.x;v.push(b)});z[0].data=v}else this._prettifyYAxis(t,b,c,G,l,q);return z},_prettifyYAxis:function(a,b,c,e,h,d){b.removeAxis("y");b.addAxis("y",this._createYAxis(aa.getPrettifyYAxisParameters(a),c,e,h,d))},supportConditionalStyling:function(a){return h.isConditionalStylingEnabled(a)},getFullSeriesItems:function(a){r.updateSeriesItemsForComparisonInfo(a);
return a.seriesItemsWithComparison||a.seriesItems}}});