Files
aportil/modules/lib/flot/jquery.flot.pie.min.js

1 line
7.7 KiB
JavaScript

(function(r){var c={series:{pie:{show:!1,radius:"auto",innerRadius:0,startAngle:1.5,tilt:1,offset:{top:0,left:"auto"},stroke:{color:"#FFF",width:1},label:{show:"auto",formatter:function(c,r){return'<div style="font-size:x-small;text-align:center;padding:2px;color:'+r.color+';">'+c+"<br/>"+Math.round(r.percent)+"%</div>"},radius:1,background:{color:null,opacity:0},threshold:0},combine:{threshold:-1,color:null,label:"Other"},highlight:{opacity:0.5}}}};r.plot.plugins.push({init:function(s){function F(a){A|| (A=!0,k=a.getCanvas(),t=r(k).parent(),c=a.getOptions(),a.setData(G(a.getData())))}function G(a){for(var b=0;b<a.length;++b)if("number"==typeof a[b].data)a[b].data=[[1,a[b].data]];else if("undefined"==typeof a[b].data||"undefined"==typeof a[b].data[0])"undefined"!=typeof a[b].data&&"undefined"!=typeof a[b].data.label&&(a[b].label=a[b].data.label),a[b].data=[[1,0]];for(var b=a,h=0;h<b.length;++h){var f=parseFloat(b[h].data[0][1]);f&&(m+=f)}for(var h=b=0,f=c.series.pie.combine.color,e=[],d=0;d<a.length;++d)a[d].data[0][1]= parseFloat(a[d].data[0][1]),a[d].data[0][1]||(a[d].data[0][1]=0),a[d].data[0][1]/m<=c.series.pie.combine.threshold?(b+=a[d].data[0][1],h++,f||(f=a[d].color)):e.push({data:[[1,a[d].data[0][1]]],color:a[d].color,label:a[d].label,angle:2*a[d].data[0][1]*Math.PI/m,percent:100*(a[d].data[0][1]/m)});0<h&&e.push({data:[[1,b]],color:f,label:c.series.pie.combine.label,angle:2*b*Math.PI/m,percent:100*(b/m)});return e}function H(a,b){function h(){ctx.clearRect(0,0,k.width,k.height);t.children().filter(".pieLabel, .pieLabelBackground").remove()} function f(){var a=1<c.series.pie.radius?c.series.pie.radius:n*c.series.pie.radius;if(!(a>=k.width/2-5||a*c.series.pie.tilt>=k.height/2-15||10>=a)){ctx.save();ctx.translate(5,15);ctx.globalAlpha=0.02;ctx.fillStyle="#000";ctx.translate(l,v);ctx.scale(1,c.series.pie.tilt);for(var b=1;10>=b;b++)ctx.beginPath(),ctx.arc(0,0,a,0,2*Math.PI,!1),ctx.fill(),a-=b;ctx.restore()}}function e(){function a(b,c,d){0>=b||(d?ctx.fillStyle=c:(ctx.strokeStyle=c,ctx.lineJoin="round"),ctx.beginPath(),1.0E-9<Math.abs(b- 2*Math.PI)?ctx.moveTo(0,0):r.browser.msie&&(b-=1.0E-4),ctx.arc(0,0,h,e,e+b,!1),ctx.closePath(),e+=b,d?ctx.fill():ctx.stroke())}function b(){for(var a=startAngle,h=1<c.series.pie.label.radius?c.series.pie.label.radius:n*c.series.pie.label.radius,e=0;e<d.length;++e){if(d[e].percent>=100*c.series.pie.label.threshold){var f=d[e],g=a,q=e;if(0!=f.data[0][1]){var o=c.legend.labelFormatter,j=void 0,p=c.series.pie.label.formatter,j=o?o(f.label,f):f.label;p&&(j=p(j,f));o=(g+f.angle+g)/2;g=l+Math.round(Math.cos(o)* h);o=v+Math.round(Math.sin(o)*h)*c.series.pie.tilt;t.append('<span class="pieLabel" id="pieLabel'+q+'" style="position:absolute;top:'+o+"px;left:"+g+'px;">'+j+"</span>");q=t.children("#pieLabel"+q);j=o-q.height()/2;o=g-q.width()/2;q.css("top",j);q.css("left",o);if(0<0-j||0<0-o||0>k.height-(j+q.height())||0>k.width-(o+q.width()))w=!0;0!=c.series.pie.label.background.opacity&&(g=c.series.pie.label.background.color,null==g&&(g=f.color),f="top:"+j+"px;left:"+o+"px;",r('<div class="pieLabelBackground" style="position:absolute;width:'+ q.width()+"px;height:"+q.height()+"px;"+f+"background-color:"+g+';"> </div>').insertBefore(q).css("opacity",c.series.pie.label.background.opacity))}}a+=d[e].angle}}startAngle=Math.PI*c.series.pie.startAngle;var h=1<c.series.pie.radius?c.series.pie.radius:n*c.series.pie.radius;ctx.save();ctx.translate(l,v);ctx.scale(1,c.series.pie.tilt);ctx.save();for(var e=startAngle,f=0;f<d.length;++f)d[f].startAngle=e,a(d[f].angle,d[f].color,!0);ctx.restore();ctx.save();ctx.lineWidth=c.series.pie.stroke.width;e= startAngle;for(f=0;f<d.length;++f)a(d[f].angle,c.series.pie.stroke.color,!1);ctx.restore();B(ctx);c.series.pie.label.show&&b();ctx.restore()}if(t){ctx=b;z=t.children().filter(".legend").children().width();n=Math.min(k.width,k.height/c.series.pie.tilt)/2;v=k.height/2+c.series.pie.offset.top;l=k.width/2;l="auto"==c.series.pie.offset.left?c.legend.position.match("w")?l+z/2:l-z/2:l+c.series.pie.offset.left;l<n?l=n:l>k.width-n&&(l=k.width-n);var d=a.getData(),j=0;for(w=!0;w&&j<C;)w=!1,0<j&&(n*=I),j+=1, h(),0.8>=c.series.pie.tilt&&f(),e();j>=C&&(h(),t.prepend('<div class="error">Could not draw pie with labels contained inside canvas</div>'));a.setSeries&&a.insertLegend&&(a.setSeries(d),a.insertLegend())}}function B(a){0<c.series.pie.innerRadius&&(a.save(),innerRadius=1<c.series.pie.innerRadius?c.series.pie.innerRadius:n*c.series.pie.innerRadius,a.globalCompositeOperation="destination-out",a.beginPath(),a.fillStyle=c.series.pie.stroke.color,a.arc(0,0,innerRadius,0,2*Math.PI,!1),a.fill(),a.closePath(), a.restore(),a.save(),a.beginPath(),a.strokeStyle=c.series.pie.stroke.color,a.arc(0,0,innerRadius,0,2*Math.PI,!1),a.stroke(),a.closePath(),a.restore())}function J(a){D("plothover",a)}function K(a){D("plotclick",a)}function D(a,b){var h=s.offset(),f=parseInt(b.pageX-h.left);a:{for(var h=parseInt(b.pageY-h.top),e=s.getData(),d=s.getOptions(),d=1<d.series.pie.radius?d.series.pie.radius:n*d.series.pie.radius,j=0;j<e.length;++j){var g=e[j];if(g.pie.show){ctx.save();ctx.beginPath();ctx.moveTo(0,0);ctx.arc(0, 0,d,g.startAngle,g.startAngle+g.angle,!1);ctx.closePath();x=f-l;y=h-v;if(ctx.isPointInPath){if(ctx.isPointInPath(f-l,h-v)){ctx.restore();f={datapoint:[g.percent,g.data],dataIndex:0,series:g,seriesIndex:j};break a}}else{p1X=d*Math.cos(g.startAngle);p1Y=d*Math.sin(g.startAngle);p2X=d*Math.cos(g.startAngle+g.angle/4);p2Y=d*Math.sin(g.startAngle+g.angle/4);p3X=d*Math.cos(g.startAngle+g.angle/2);p3Y=d*Math.sin(g.startAngle+g.angle/2);p4X=d*Math.cos(g.startAngle+g.angle/1.5);p4Y=d*Math.sin(g.startAngle+ g.angle/1.5);p5X=d*Math.cos(g.startAngle+g.angle);p5Y=d*Math.sin(g.startAngle+g.angle);arrPoly=[[0,0],[p1X,p1Y],[p2X,p2Y],[p3X,p3Y],[p4X,p4Y],[p5X,p5Y]];arrPoint=[x,y];for(var k=!1,u=-1,r=arrPoly.length,m=r-1;++u<r;m=u)(arrPoly[u][1]<=arrPoint[1]&&arrPoint[1]<arrPoly[m][1]||arrPoly[m][1]<=arrPoint[1]&&arrPoint[1]<arrPoly[u][1])&&arrPoint[0]<(arrPoly[m][0]-arrPoly[u][0])*(arrPoint[1]-arrPoly[u][1])/(arrPoly[m][1]-arrPoly[u][1])+arrPoly[u][0]&&(k=!k);if(k){ctx.restore();f={datapoint:[g.percent,g.data], dataIndex:0,series:g,seriesIndex:j};break a}}ctx.restore()}}f=null}if(c.grid.autoHighlight)for(h=0;h<p.length;++h)if(e=p[h],e.auto==a&&!(f&&e.series==f.series)&&(e=e.series,null==e&&(p=[],s.triggerRedrawOverlay()),"number"==typeof e&&(e=series[e]),e=E(e),-1!=e))p.splice(e,1),s.triggerRedrawOverlay();f&&(h=f.series,"number"==typeof h&&(h=series[h]),e=E(h),-1==e?(p.push({series:h,auto:a}),s.triggerRedrawOverlay()):a||(p[e].auto=!1));t.trigger(a,[{pageX:b.pageX,pageY:b.pageY},f])}function E(a){for(var b= 0;b<p.length;++b)if(p[b].series==a)return b;return-1}function L(a,b){var c=a.getOptions(),f=1<c.series.pie.radius?c.series.pie.radius:n*c.series.pie.radius;b.save();b.translate(l,v);b.scale(1,c.series.pie.tilt);for(i=0;i<p.length;++i){var e=p[i].series;0>e.angle||(b.fillStyle="rgba(255, 255, 255, "+c.series.pie.highlight.opacity+")",b.beginPath(),1.0E-9<Math.abs(e.angle-2*Math.PI)&&b.moveTo(0,0),b.arc(0,0,f,e.startAngle,e.startAngle+e.angle,!1),b.closePath(),b.fill())}B(b);b.restore()}var k=null, t=null,n=null,l=null,v=null,m=0,w=!0,C=10,I=0.95,z=0,A=!1,p=[];s.hooks.processOptions.push(function(a,b){b.series.pie.show&&(b.grid.show=!1,"auto"==b.series.pie.label.show&&(b.series.pie.label.show=b.legend.show?!1:!0),"auto"==b.series.pie.radius&&(b.series.pie.radius=b.series.pie.label.show?0.75:1),1<b.series.pie.tilt&&(b.series.pie.tilt=1),0>b.series.pie.tilt&&(b.series.pie.tilt=0),a.hooks.processDatapoints.push(F),a.hooks.drawOverlay.push(L),a.hooks.draw.push(H))});s.hooks.bindEvents.push(function(a, b){var c=a.getOptions();c.series.pie.show&&c.grid.hoverable&&b.unbind("mousemove").mousemove(J);c.series.pie.show&&c.grid.clickable&&b.unbind("click").click(K)})},options:c,name:"pie",version:"1.0"})})(jQuery);