radar.js 5.84 KB
AmCharts.AmRadarChart=AmCharts.Class({inherits:AmCharts.AmCoordinateChart,construct:function(a){this.type="radar";AmCharts.AmRadarChart.base.construct.call(this,a);this.cname="AmRadarChart";this.marginRight=this.marginBottom=this.marginTop=this.marginLeft=0;this.radius="35%";AmCharts.applyTheme(this,a,this.cname)},initChart:function(){AmCharts.AmRadarChart.base.initChart.call(this);this.dataChanged&&(this.updateData(),this.dataChanged=!1,this.dispatchDataUpdated=!0);this.drawChart()},updateData:function(){this.parseData();
var a=this.graphs,b;for(b=0;b<a.length;b++)a[b].data=this.chartData},updateGraphs:function(){var a=this.graphs,b;for(b=0;b<a.length;b++){var c=a[b];c.index=b;c.width=this.realRadius;c.height=this.realRadius;c.x=this.marginLeftReal;c.y=this.marginTopReal}},parseData:function(){AmCharts.AmRadarChart.base.parseData.call(this);this.parseSerialData()},updateValueAxes:function(){var a=this.valueAxes,b;for(b=0;b<a.length;b++){var c=a[b];c.axisRenderer=AmCharts.RadAxis;c.guideFillRenderer=AmCharts.RadarFill;
c.axisItemRenderer=AmCharts.RadItem;c.autoGridCount=!1;c.x=this.marginLeftReal;c.y=this.marginTopReal;c.width=this.realRadius;c.height=this.realRadius}},drawChart:function(){AmCharts.AmRadarChart.base.drawChart.call(this);var a=this.updateWidth(),b=this.updateHeight(),c=this.marginTop+this.getTitleHeight(),d=this.marginLeft,b=b-c-this.marginBottom;this.marginLeftReal=d+(a-d-this.marginRight)/2;this.marginTopReal=c+b/2;this.realRadius=AmCharts.toCoordinate(this.radius,a,b);this.updateValueAxes();this.updateGraphs();
a=this.chartData;if(AmCharts.ifArray(a)){if(0<this.realWidth&&0<this.realHeight){a=a.length-1;d=this.valueAxes;for(c=0;c<d.length;c++)d[c].zoom(0,a);d=this.graphs;for(c=0;c<d.length;c++)d[c].zoom(0,a);(a=this.legend)&&a.invalidateSize()}}else this.cleanChart();this.dispDUpd();this.chartCreated=!0},formatString:function(a,b,c){var d=b.graph;-1!=a.indexOf("[[category]]")&&(a=a.replace(/\[\[category\]\]/g,String(b.serialDataItem.category)));d=d.numberFormatter;d||(d=this.nf);a=AmCharts.formatValue(a,
b.values,["value"],d,"",this.usePrefixes,this.prefixesOfSmallNumbers,this.prefixesOfBigNumbers);-1!=a.indexOf("[[")&&(a=AmCharts.formatDataContextValue(a,b.dataContext));return a=AmCharts.AmRadarChart.base.formatString.call(this,a,b,c)},cleanChart:function(){AmCharts.callMethod("destroy",[this.valueAxes,this.graphs])}});AmCharts.RadAxis=AmCharts.Class({construct:function(a){var b=a.chart,c=a.axisThickness,d=a.axisColor,m=a.axisAlpha,p=a.x,e=a.y;this.set=b.container.set();b.axesSet.push(this.set);var f=a.axisTitleOffset,n=a.radarCategoriesEnabled,l=a.chart.fontFamily,g=a.fontSize;void 0===g&&(g=a.chart.fontSize);var r=a.color;void 0===r&&(r=a.chart.color);if(b){this.axisWidth=a.height;a=b.chartData;var w=a.length,t;for(t=0;t<w;t++){var k=180-360/w*t,h=p+this.axisWidth*Math.sin(k/180*Math.PI),q=e+this.axisWidth*Math.cos(k/
180*Math.PI);0<m&&(h=AmCharts.line(b.container,[p,h],[e,q],d,m,c),this.set.push(h));if(n){var u="start",h=p+(this.axisWidth+f)*Math.sin(k/180*Math.PI),q=e+(this.axisWidth+f)*Math.cos(k/180*Math.PI);if(180==k||0===k)u="middle",h-=5;0>k&&(u="end",h-=10);180==k&&(q-=5);0===k&&(q+=5);k=AmCharts.text(b.container,a[t].category,r,l,g,u);k.translate(h+5,q);this.set.push(k);k.getBBox()}}}}});AmCharts.RadItem=AmCharts.Class({construct:function(a,b,c,d,m,p,e,f){void 0===c&&(c="");var n=a.chart.fontFamily,l=a.fontSize;void 0===l&&(l=a.chart.fontSize);var g=a.color;void 0===g&&(g=a.chart.color);var r=a.chart.container;this.set=d=r.set();var w=a.axisColor,t=a.axisAlpha,k=a.tickLength,h=a.gridAlpha,q=a.gridThickness,u=a.gridColor,A=a.dashLength,B=a.fillColor,y=a.fillAlpha,C=a.labelsEnabled;m=a.counter;var D=a.inside,E=a.gridType,s,H=a.labelOffset;b-=a.height;var x;p=a.x;var F=a.y;e?(C=!0,isNaN(e.tickLength)||
(k=e.tickLength),void 0!=e.lineColor&&(u=e.lineColor),isNaN(e.lineAlpha)||(h=e.lineAlpha),isNaN(e.dashLength)||(A=e.dashLength),isNaN(e.lineThickness)||(q=e.lineThickness),!0===e.inside&&(D=!0),void 0!==e.boldLabel&&(f=e.boldLabel)):c||(h/=3,k/=2);var G="end",z=-1;D&&(G="start",z=1);var v;C&&(v=AmCharts.text(r,c,g,n,l,G,f),v.translate(p+(k+3+H)*z,b),d.push(v),this.label=v,x=AmCharts.line(r,[p,p+k*z],[b,b],w,t,q),d.push(x));b=Math.round(a.y-b);f=[];n=[];if(0<h){if("polygons"==E){s=a.data.length;for(l=
0;l<s;l++)g=180-360/s*l,f.push(b*Math.sin(g/180*Math.PI)),n.push(b*Math.cos(g/180*Math.PI));f.push(f[0]);n.push(n[0]);h=AmCharts.line(r,f,n,u,h,q,A)}else h=AmCharts.circle(r,b,"#FFFFFF",0,q,u,h);h.translate(p,F);d.push(h)}if(1==m&&0<y&&!e&&""!==c){e=a.previousCoord;if("polygons"==E){for(l=s;0<=l;l--)g=180-360/s*l,f.push(e*Math.sin(g/180*Math.PI)),n.push(e*Math.cos(g/180*Math.PI));s=AmCharts.polygon(r,f,n,B,y)}else s=AmCharts.wedge(r,0,0,0,360,b,b,e,0,{fill:B,"fill-opacity":y,stroke:"#000","stroke-opacity":0,
"stroke-width":1});d.push(s);s.translate(p,F)}!1===a.visible&&(x&&x.hide(),v&&v.hide());""!==c&&(a.counter=0===m?1:0,a.previousCoord=b)},graphics:function(){return this.set},getLabel:function(){return this.label}});AmCharts.RadarFill=AmCharts.Class({construct:function(a,b,c,d){b-=a.axisWidth;c-=a.axisWidth;var m=Math.max(b,c);b=c=Math.min(b,c);c=a.chart.container;var p=d.fillAlpha,e=d.fillColor,m=Math.abs(m-a.y);b=Math.abs(b-a.y);var f=Math.max(m,b);b=Math.min(m,b);m=f;f=d.angle+90;d=d.toAngle+90;isNaN(f)&&(f=0);isNaN(d)&&(d=360);this.set=c.set();void 0===e&&(e="#000000");isNaN(p)&&(p=0);if("polygons"==a.gridType){d=[];var n=[],l=a.data.length,g;for(g=0;g<l;g++)f=180-360/l*g,d.push(m*Math.sin(f/180*Math.PI)),
n.push(m*Math.cos(f/180*Math.PI));d.push(d[0]);n.push(n[0]);for(g=l;0<=g;g--)f=180-360/l*g,d.push(b*Math.sin(f/180*Math.PI)),n.push(b*Math.cos(f/180*Math.PI));this.fill=AmCharts.polygon(c,d,n,e,p)}else this.fill=AmCharts.wedge(c,0,0,f,d-f,m,m,b,0,{fill:e,"fill-opacity":p,stroke:"#000","stroke-opacity":0,"stroke-width":1});this.set.push(this.fill);this.fill.translate(a.x,a.y)},graphics:function(){return this.set},getLabel:function(){}});