// 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/plots/Donut","dojo/_base/Color dojo/_base/declare dojo/_base/lang dojox/charting/plot2d/Base dojox/charting/plot2d/_PlotEvents dojox/charting/plot2d/common dojox/gfx dojox/gfx/matrix dojox/lang/functional dojox/lang/utils dojo/has ./animation/_DonutAnimation".split(" "),function(U,F,G,H,I,R,J,K,w,A,M,S){var T={createPath:function(a,d,f,b,c,e,g,k,n,u,p,l){var h=function(c,h,l){d=void 0!==h?h:d;h=B.getEndAngle(d,c,e,g,n,p,l);1===c&&
(h=Number(h.toFixed(5)));c=f*k;l=h-d;var r=b.cx+f*Math.cos(d),q=b.cy+f*Math.sin(d),m=b.cx+f*Math.cos(h),t=b.cy+f*Math.sin(h);if(c){var y=b.cx+c*Math.cos(d),v=b.cy+c*Math.sin(d),w=b.cx+c*Math.cos(h),x=b.cy+c*Math.sin(h);shape=a.createPath().moveTo(y,v).lineTo(r,q).arcTo(f,f,0,l>Math.PI,!0,m,t).lineTo(w,x).arcTo(c,c,0,l>Math.PI,!1,y,v).closePath().setStroke(u.series.stroke)}else shape=a.createPath().moveTo(b.cx,b.cy).lineTo(r,q).arcTo(f,f,0,l>Math.PI,!0,m,t).lineTo(b.cx,b.cy).closePath().setStroke(u.series.stroke);
specialFill=u.series.fill;shape.setFill(specialFill);return{shape:shape,end:h,donutGap:g}};l.push({isSlice:!0,sliceIndex:c,func:h});return h}},B={getStartAngle:function(a,d){return a.series.donutArcPercent&&100!==a.series.donutArcPercent?-270+(100-a.series.donutArcPercent)/100*360/2:(a.series.startAngle||0)+d},getEndAngle:function(a,d,f,b,c,e,g){a=a+2*d*Math.PI-b;f&&(f=e+2*Math.PI-b,a=g||c.series.donutArcPercent&&100!==c.series.donutArcPercent?Math.min(a+b,f):f);return a}};return F([H,I,S],{enableHole:!0,
enableGap:!0,startAngleOffset:0,_animationInfos:null,_dataLabels:null,defaultParams:{labels:!0,ticks:!1,fixed:!0,precision:1,labelStyle:"outside",htmlLabels:!0,radGrad:"native",fanSize:5,startAngle:0,animate:null},optionalParams:{radius:0,omitLabels:!1,stroke:{},outline:{},shadow:{},fill:{},filter:{},styleFunc:null,font:"",fontColor:"",labelWiring:{}},constructor:function(a,d){this.opt=G.clone(this.defaultParams);A.updateWithObject(this.opt,d);A.updateWithPattern(this.opt,d,this.optionalParams);this.axes=
[];this.run=null;this.dyn=[];this.runFilter=[]},clear:function(){this.inherited(arguments);this.dyn=[];this.run=null;return this},setAxis:function(a){return this},addSeries:function(a){this.run=a;return this},getSeriesStats:function(){return G.delegate(R.defaultStats)},getRequiredColors:function(){return this.run?this.run.data.length:0},getRenderResults:function(){return this._lastRenderResults},render:function(a,d){if(!this.dirty)return this;this.resetEvents();this.dirty=!1;this._eventSeries={};
this.cleanGroup();var f=this.group,b=this.chart.theme;if(!this.run||!this.run.data.length)return this;var c=(a.width-d.l-d.r)/2,e=(a.height-d.t-d.b)/2/this._getRYMultiplier(b),g=Math.min(c,e),k="font"in this.opt?this.opt.font:b.series.font,n,u=K._degToRad(this._getStartAngle(b)),p=u,l,h,x,t,r,A=this.events(),q=this.run.data.map(function(b,a){"number"!==typeof b&&b.hidden&&(this.runFilter.push(a),b.hidden=!1);return this.runFilter.some(function(b){return b===a})?"number"===typeof b?0:{y:0,text:b.text}:
b},this);this.dyn=[];"radius"in this.opt&&(r=g=this.opt.radius);var m={cx:d.l+c,cy:d.t+e,r:g},N;l=w.map(q,"x ? Math.max(x.y, 0) : 0");if(w.every(l,"\x3c\x3d 0"))return f.createCircle(m).setStroke(b.series.stroke),this.dyn=l.map(function(){return{}}),this;h=w.map(l,"/this",w.foldl(l,"+",0));this.opt.labels&&(x=h.map(function(b,a){if(0>b)return"";var c=q[a];return"text"in c?c.text:this._getLabel(100*b)+"%"},this));var y=this.enableHole?(b.series.donutHolePercent||0)/100:0,v=this.enableGap?K._degToRad(b.series.donutGap||
0):0;h=this._fixSlices(h,v);this._lastRenderResults={};this._animationInfos=[];this._dataLabels=[];var C=w.map(q,function(a,c){var d=[this.opt,this.run];null!=a&&"number"!==typeof a&&d.push(a);this.opt.styleFunc&&d.push(this.opt.styleFunc(a));return b.next("slice",d,!0)},this);l=this._preprocessParams(q,b,g,c,e,m,h);m=l.circle;g=l.r;if(this.opt.labels)switch(t=n=0,x.forEach(function(b,a){var c=J._base._getTextBox(b,{font:C[a].series.font});n=Math.max(n,c.h);t=Math.max(t,c.w)}),this.opt.labelStyle){case "outside":l=
g;g=Math.min(c-t,e-n)-5;r=g+t/2;g=Math.max(g,l/2);break;case "inside":r=Math.abs((g-g*y)/2+g*y+(g-t/2))/2;break;case "columns":r=g=Math.min(c-t-20,e-2*n)}var O=Array(h.length);h.some(function(a,c){a=this._getSliceValueAt(h,c,b);var d=q[c],e=C[c];N=g*y;var k=T.createPath(f,p,g,m,c,c+1===h.length,v,y,b,e,u,this._animationInfos)(a),l=k.end;shape=k.shape;this.dyn.push({fill:void 0,stroke:e.series.stroke});A&&(d={element:"slice",index:c,run:this.run,shape:shape,x:c,y:"number"===typeof d?d:d.y,cx:m.cx,
cy:m.cy,cr:g},this._connectEvents(d),O[c]=d);p=l+v;return!1},this);if(this.opt.labels){var P=M("dojo-bidi")&&this.chart.isRightToLeft();if("outside"===this.opt.labelStyle||"inside"===this.opt.labelStyle)p=u,h.some(function(c,d){c=this._getSliceValueAt(h,d,b);if(0>=c)return!1;var e=C[d];if(1<=c)return this._dataLabels.push(this.renderLabel(f,m.cx,m.cy+n/2,x[d],e,!0)),!0;var k=B.getEndAngle(p,c,d+1===h.length,v,b,u);if(this.opt.omitLabels&&.001>k-p)return!1;var g=(p+k)/2,l=r;"outside"===this.opt.labelStyle&&
(l=1.15*r+(n-t/2-.15*r)*Math.abs(Math.sin(g)));var q=m.cx+l*Math.cos(g);this._dataLabels.push(this.renderLabel(f,P?a.width-q:q,m.cy+l*Math.sin(g)+n/2,x[d],e,!0));p=k+v;return!1},this);else if("columns"===this.opt.labelStyle){var p=u,F=this.opt.omitLabels,D=[];h.forEach(function(c,a){c=this._getSliceValueAt(h,a,b);var d=B.getEndAngle(p,c,a+1===h.length,v,b,u),e=(p+d)/2;D.push({angle:e,left:0>Math.cos(e),theme:C[a],index:a,omit:F?.001>d-p:!1});p=d+v},this);e=J._base._getTextBox("a",{font:k}).h;this._getProperLabelRadius(D,
e,1.1*r);for(e=0;e<D.length;e++)if(k=D[e],!k.omit){var z=m.cx-c,E=m.cx+c;l=J._base._getTextBox(x[e],{font:k.theme.series.font}).w;var H=m.cx+k.labelR*Math.cos(k.angle),L=m.cy+k.labelR*Math.sin(k.angle),E=k.left?z+l:E-l,z=k.left?z:E,Q=f.createPath().moveTo(m.cx+r*Math.cos(k.angle),m.cy+r*Math.sin(k.angle));Q.lineTo(H,L);Q.lineTo(E,L).setStroke(k.theme.series.labelWiring);this._dataLabels.push(this.renderLabel(f,P?a.width-l-z:z,L,x[e],k.theme,!1,"left"))}}}var I=0;this._eventSeries[this.run.name]=w.map(q,
function(b){return 0>=b?null:O[I++]});M("dojo-bidi")&&this._checkOrientation(this.group,a,d);this._lastRenderResults=G.mixin(this._lastRenderResults,{labels:this.opt.labels,radiusInner:N,radiusOuter:g});this._renderAdditionalElements(q,b,g,f,m,h);this.opt.animate&&this._renderAnimation(q,b,g,f,m,h);return this},_getStartAngle:function(a){return B.getStartAngle(a,this.startAngleOffset)},_fixSlices:function(a,d){var f=[],b=0,c=[],e=d/(2*Math.PI)+.001;a.forEach(function(a,d){if(a<e){var g=e-a;a=e;b+=
g;c.push(d);f[d]=a}});var g=b/(a.length-c.length);a.forEach(function(a,b){-1===c.indexOf(b)&&(a-=g,f[b]=a)});return f},_getSliceValueAt:function(a,d,f){return Math.max(0,a[d])*(f.series.donutArcPercent?f.series.donutArcPercent/100:1)},_preprocessParams:function(a,d,f,b,c,e,g){return{circle:e,r:f}},_getRYMultiplier:function(a){return Math.max(.625,a.series.donutArcPercent&&100!==a.series.donutArcPercent?(1+Math.cos(K._degToRad(360*(100-a.series.donutArcPercent)/100/2.1)))/2:1)},_renderAdditionalElements:function(a,
d,f,b,c,e){},_getProperLabelRadius:function(a,d,f){var b,c,e=1,g=1;if(1===a.length)a[0].labelR=f;else{for(var k=0;k<a.length;k++){var n=Math.abs(Math.sin(a[k].angle));a[k].left?e>=n&&(e=n,b=a[k]):g>=n&&(g=n,c=a[k])}b.labelR=c.labelR=f;this._calculateLabelR(b,a,d);this._calculateLabelR(c,a,d)}},_calculateLabelR:function(a,d,f){for(var b=a.index,c=d.length,e=a.labelR;!(d[b%c].left^d[(b+1)%c].left);)d[(b+1)%c].omit||(e=(Math.sin(d[b%c].angle)*e+(d[b%c].left?-f:f))/Math.sin(d[(b+1)%c].angle),e=e<a.labelR?
a.labelR:e,d[(b+1)%c].labelR=e),b++;b=a.index;for(c=0===b?c-1:b-1;!(d[b].left^d[c].left);)d[c].omit||(e=(Math.sin(d[b].angle)*e+(d[b].left?f:-f))/Math.sin(d[c].angle),e=e<a.labelR?a.labelR:e,d[c].labelR=e),b--,c--,b=0>b?b+d.length:b,c=0>c?c+d.length:c}})});