laipower/wp-content/plugins/easy-digital-downloads/assets/js/vendor/jquery.flot.pie.min.js

1 line
7.7 KiB
JavaScript
Raw Normal View History

!function(e){var i={series:{pie:{show:!1,radius:"auto",innerRadius:0,startAngle:1.5,tilt:1,shadow:{left:5,top:15,alpha:.02},offset:{top:0,left:"auto"},stroke:{color:"#fff",width:1},label:{show:"auto",formatter:function(e,i){return"<div style='font-size:x-small;text-align:center;padding:2px;color:"+i.color+";'>"+e+"<br/>"+Math.round(i.percent)+"%</div>"},radius:1,background:{color:null,opacity:0},threshold:0},combine:{threshold:-1,color:null,label:"Other"},highlight:{opacity:.5}}}};e.plot.plugins.push({init:function(s){var t=null,r=null,a=null,l=null,n=null,o=!1,p=null,h=[];function c(s,a,l){o||(o=!0,t=s.getCanvas(),r=e(t).parent(),i=s.getOptions(),s.setData(function(s){for(var t=0,r=0,a=0,l=i.series.pie.combine.color,n=[],o=0;o<s.length;++o){var p=s[o].data;e.isArray(p)?e.isNumeric(p[1])?p[1]=+p[1]:p[1]=0:p=e.isNumeric(p)?[1,+p]:[1,0],s[o].data=[p]}for(o=0;o<s.length;++o)t+=s[o].data[0][1];for(o=0;o<s.length;++o)(p=s[o].data[0][1])/t<=i.series.pie.combine.threshold&&(r+=p,a++,l||(l=s[o].color));for(o=0;o<s.length;++o)p=s[o].data[0][1],(a<2||p/t>i.series.pie.combine.threshold)&&n.push({data:[[1,p]],color:s[o].color,label:s[o].label,angle:p*Math.PI*2/t,percent:p/(t/100)});return a>1&&n.push({data:[[1,r]],color:l,label:i.series.pie.combine.label,angle:r*Math.PI*2/t,percent:r/(t/100)}),n}(s.getData())))}function g(s,t){if(r){var h=s.getPlaceholder().width(),c=s.getPlaceholder().height(),g=r.children().filter(".legend").children().width()||0;p=t,o=!1,a=Math.min(h,c/i.series.pie.tilt)/2,n=c/2+i.series.pie.offset.top,l=h/2,"auto"==i.series.pie.offset.left?i.legend.position.match("w")?l+=g/2:l-=g/2:l+=i.series.pie.offset.left,l<a?l=a:l>h-a&&(l=h-a);var d=s.getData(),f=0;do{f>0&&(a*=.95),f+=1,v(),i.series.pie.tilt<=.8&&b()}while(!w()&&f<10);f>=10&&(v(),r.prepend("<div class='error'>Could not draw pie with labels contained inside canvas</div>")),s.setSeries&&s.insertLegend&&(s.setSeries(d),s.insertLegend())}function v(){p.clearRect(0,0,h,c),r.children().filter(".pieLabel, .pieLabelBackground").remove()}function b(){var e=i.series.pie.shadow.left,s=i.series.pie.shadow.top,t=i.series.pie.shadow.alpha,r=i.series.pie.radius>1?i.series.pie.radius:a*i.series.pie.radius;if(!(r>=h/2-e||r*i.series.pie.tilt>=c/2-s||r<=10)){p.save(),p.translate(e,s),p.globalAlpha=t,p.fillStyle="#000",p.translate(l,n),p.scale(1,i.series.pie.tilt);for(var o=1;o<=10;o++)p.beginPath(),p.arc(0,0,r,0,2*Math.PI,!1),p.fill(),r-=o;p.restore()}}function w(){var s=Math.PI*i.series.pie.startAngle,t=i.series.pie.radius>1?i.series.pie.radius:a*i.series.pie.radius;p.save(),p.translate(l,n),p.scale(1,i.series.pie.tilt),p.save();for(var o=s,g=0;g<d.length;++g)d[g].startAngle=o,f(d[g].angle,d[g].color,!0);if(p.restore(),i.series.pie.stroke.width>0){for(p.save(),p.lineWidth=i.series.pie.stroke.width,o=s,g=0;g<d.length;++g)f(d[g].angle,i.series.pie.stroke.color,!1);p.restore()}return u(p),p.restore(),!i.series.pie.label.show||function(){for(var t=s,o=i.series.pie.label.radius>1?i.series.pie.label.radius:a*i.series.pie.label.radius,p=0;p<d.length;++p){if(d[p].percent>=100*i.series.pie.label.threshold&&!g(d[p],t,p))return!1;t+=d[p].angle}return!0;function g(s,t,a){if(0==s.data[0][1])return!0;var p,g=i.legend.labelFormatter,u=i.series.pie.label.formatter;p=g?g(s.label,s):s.label,u&&(p=u(p,s));var d=(t+s.angle+t)/2,f=l+Math.round(Math.cos(d)*o),v=n+Math.round(Math.sin(d)*o)*i.series.pie.tilt,b="<span class='pieLabel' id='pieLabel"+a+"' style='position:absolute;top:"+v+"px;left:"+f+"px;'>"+p+"</span>";r.append(b);var w=r.children("#pieLabel"+a),k=v-w.height()/2,M=f-w.width()/2;if(w.css("top",k),w.css("left",M),0-k>0||0-M>0||c-(k+w.height())<0||h-(M+w.width())<0)return!1;if(0!=i.series.pie.label.background.opacity){var P=i.series.pie.label.background.color;null==P&&(P=s.color);var m="top:"+k+"px;left:"+M+"px;";e("<div class='pieLabelBackground' style='position:absolute;width:"+w.width()+"px;height:"+w.height()+"px;"+m+"background-color:"+P+";'></div>").css("opacity",i.series.pie.label.background.opacity).insertBefore(w)}return!0}}();function f(e,i,s){e<=0||isNaN(e)||(s?p.fillStyle=i