// 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/iconRendering/IconRenderer","dojo/_base/declare dojo/dom-construct dojo/dom-geometry dojo/dom-style dijit/Destroyable ../chartUtils/ChartTypes ../chartUtils/builder/ChartPlots ../chartUtils/plots/supportClasses/GaugeLabelPlacement ../../supportClasses/templateJsonUtils/fieldInfo/FieldInfoBuilder ../../supportClasses/TableUtil ../../infographics/infographicUtils/InfographicThemeUtil esri/dijit/geoenrichment/ReportPlayer/core/sections/SectionTypes esri/dijit/geoenrichment/utils/DomUtil esri/dijit/geoenrichment/ReportPlayer/core/supportClasses/ViewModes".split(" "),
function(k,r,B,l,y,g,m,z,n,A,p,v,w,x){k=k(y,{renderIcons:function(a){this._destroyIcons();var b=this._getRenderFunction(a.chartType);b&&this[b](a);this._renderFloatingIcons(a)},_getRenderFunction:function(a){switch(a){case g.GAUGE:return"_renderDonutIcons";case g.DONUT:return"_renderDonutIcons";case g.RING:return"_renderRingIcons";case g.COLUMN:return"_renderColumnIcons";case g.BAR:return"_renderBarIcons"}return null},_renderDonutIcons:function(a){if(a.visualProperties.showChartIcons){var b=a.chart.getPlot(m.PRIMARY).getRenderResults();
if(b){var d=r.create("div",{"class":"chartContainer_chartIcon"},a.iconNode),e=b.radiusInner,f=0,c=1;a.chartType===g.GAUGE&&(c=Math.max(.6,b.ryMultiplier),a.visualProperties.gaugeLabelPlacement===z.INSIDE&&(f=b.chartIconOffset,e=Math.min(e,b.maxIconSize)));f=(a.chartH/c-e+f)/2+(b.chartShiftY||0);f=Math.min(f,a.chartH-e-10);l.set(d,{width:e+"px",height:e+"px",left:(a.chartW-e)/2+(b.chartShiftX||0)+"px",top:f+"px"});this._createIconSection(a,a.visualProperties.chartIcons&&a.visualProperties.chartIcons[0]||
this._getDefaultIcon(),e,d)}}},_renderRingIcons:function(a){if(a.visualProperties.showChartIcons){var b=a.chart.getPlot(m.PRIMARY).getRenderResults();if(b){b.slicePies.sort(function(a,b){return a.r-b.r});var d=b.slicePies[0],e=b.slicePies[b.slicePies.length-1],f=r.create("div",{"class":"chartContainer_chartIcon"},a.iconNode),c=0;b.labels?(c=Math.max(50,.8*Math.min(2*d.r,Math.min(b.maxLabelWidth,a.chartW-(e.cx+e.r)))),l.set(f,{width:c+"px",height:c+"px",left:Math.max(e.cx+e.r+15,e.cx+e.r+b.maxLabelWidth/
2-c/2)+"px",top:e.cy-c/2+"px"})):(c=1.4*d.r,l.set(f,{width:c+"px",height:c+"px",left:d.cx-c/2+"px",top:d.cy-c/2+"px"}));this._createIconSection(a,a.visualProperties.chartIcons&&a.visualProperties.chartIcons[0]||this._getDefaultIcon(),c,f)}}},_renderColumnIcons:function(a){this._renderAxisIcons(a,!0)},_renderBarIcons:function(a){this._renderAxisIcons(a,!1)},_renderAxisIcons:function(a,b){if(a.visualProperties.showAxisIcons){var d=this,e=a.chart.calculateGeometry();if(e.series[0].group){var f=e.series[0].group.children.map(function(a){return a.rawNode}),
c,q;e.series[0].data.forEach(function(a,b){void 0!==a.unsortedIndex&&(c=c||{},c[b]=a.unsortedIndex);q=q||{};q[b]=a.fill});var k=a.visualProperties.isStacked||a.comparisonInfo&&a.comparisonInfo.chartType===g.LINE?1:e.series.length,m=w.position(a.iconNode);f.forEach(function(e,g){var n=c?c[g]:g,t=w.position(e),u=r.create("div",{"class":"chartContainer_chartIcon"},a.iconNode),h=Math.min(50,a.chartW/f.length);l.set(u,{width:h+"px",height:h+"px"});var p=a.visualProperties.xAxis.show?0:h/(b?2:3.5);b?l.set(u,
{left:t.x-m.x+(t.w*k-h)/2+"px",bottom:-h+p+"px"}):l.set(u,{top:t.y-m.y+(t.h*k-h)/2+"px",left:-h+p+"px"});d._createIconSection(a,a.visualProperties.chartIcons&&a.visualProperties.chartIcons[n]||d._getDefaultIcon(),h,u,n,q&&q[g])})}}},_floatingIconsSection:null,_renderFloatingIcons:function(a){var b=a.visualProperties.floatingIcons;if(b&&b.length){b.forEach(function(b){b=b.data.data[0].fieldInfos[b.data.columns[0].field].shapeJson;var d=a.viewModel.getChartDefaultStyles(a.theme||a.themeContext);p.applyThemeSettingsToShapeJson(b,
d)});var d={"class":"chartContainer_floatingIconSection"};d.initialWidth=a.chartW;d.json={type:v.DETAILS,stack:b};d.viewModel=a.viewModel;d.themeContext=a.themeContext;d.theme=a.theme;d.tableClass="chartContainerFloatingIconTable";d.hasFixedLayout=!1;d.parentWidget=a.parentWidget;this._provideParamsForFloatingIconSection(d,a);this._floatingIconsSection=a.viewModel.layoutBuilder.createElement("section",d,a.iconNode);this._floatingIconsSection.setResizedHeight(a.chartH);this._floatingIconsSection.setViewMode(this._viewMode||
x.EDIT)}},_provideParamsForFloatingIconSection:function(a,b){},_getDefaultIcon:function(){},_iconSections:null,_createIconSection:function(a,b,d,e,f,c){if(b&&(b.imageJson||b.shapeJson)){if(b.shapeJson){var g=a.viewModel.getChartDefaultStyles(a.theme||a.themeContext);p.applyThemeSettingsToShapeJson(b.shapeJson,g);b.shapeJson.themeStyle&&c&&(b.shapeJson.themeStyle.borderColor=c,b.shapeJson.themeStyle.fillColor=c)}b=A.createSingleCellTable({width:d,height:d,fieldInfo:b.imageJson?n.createFieldInfoFromImage(b.imageJson):
n.createFieldInfoFromShape(b.shapeJson),cellStyle:{backgroundColor:"transparent"}});c={};c.initialWidth=d;c.json={type:v.DETAILS,stack:[b]};c.viewModel=a.viewModel;c.themeContext=a.themeContext;c.theme=a.theme;c.tableClass="chartContainerIconTable";c.hasFixedLayout=!0;c.parentWidget=a.parentWidget;this._provideParamsForIconSection(c,a);a=a.viewModel.layoutBuilder.createElement("section",c,e);a.setResizedHeight(d);a.setViewMode(this._viewMode||x.EDIT);a.__unsortedIndex=f;this._iconSections.push(a)}},
_getSectionUnsortedIndex:function(a){return a&&void 0!==a.__unsortedIndex?a.__unsortedIndex:-1},_provideParamsForIconSection:function(a,b,d){},_viewMode:null,setViewMode:function(a){this._viewMode!==a&&(this._viewMode=a,this._iconSections&&this._iconSections.forEach(function(b){b.setViewMode(a)}),this._floatingIconsSection&&this._floatingIconsSection.setViewMode(a))},_destroyIcons:function(){this._iconSections=this._iconSections||[];this._iconSections.forEach(function(a){var b=a.domNode&&a.domNode.parentNode;
a.destroy();b&&r.destroy(b)});this._iconSections.length=0;this._floatingIconsSection&&this._floatingIconsSection.destroy();this._floatingIconsSection=null},destroy:function(){this._destroyIcons();this.inherited(arguments)}});k.AXIS_ICON_MAX_SIZE=50;return k});