diff --git a/g.pie.js b/g.pie.js index df2afb3..3f82cb7 100644 --- a/g.pie.js +++ b/g.pie.js @@ -78,26 +78,38 @@ others && values.splice(len) && (values[cut].others = true); for (i = 0; i < len; i++) { - var mangle = angle - 360 * values[i] / total / 2; - - if (!i) { - angle = 90 - mangle; - mangle = angle - 360 * values[i] / total / 2; - } - - if (opts.init) { - var ipath = sector(cx, cy, 1, angle, angle - 360 * values[i] / total).join(","); + //if all votes are in only one option must draw a circle + if (values[i] / total === 1) { + var circle = paper.circle(cx, cy, r).attr({ fill: chartinst.colors[i], stroke: opts.stroke || "#fff", "stroke-width": opts.strokewidth == null ? 1 : opts.strokewidth }); + circle.value = values[i]; + series.push(circle); + sectors.push(circle); + covers.push(paper.circle(cx, cy, r).attr(chartinst.shim)); + total = values[i]; + series[i].middle = {x: cx, y: cy}; + series[i].mangle = 180; + } else { + var mangle = angle - 360 * values[i] / total / 2; + + if (!i) { + angle = 90 - mangle; + mangle = angle - 360 * values[i] / total / 2; + } + + if (opts.init) { + var ipath = sector(cx, cy, 1, angle, angle - 360 * values[i] / total).join(","); + } + + var path = sector(cx, cy, r, angle, angle -= 360 * values[i] / total); + var p = paper.path(opts.init ? ipath : path).attr({ fill: opts.colors && opts.colors[i] || chartinst.colors[i] || "#666", stroke: opts.stroke || "#fff", "stroke-width": (opts.strokewidth == null ? 1 : opts.strokewidth), "stroke-linejoin": "round" }); + + p.value = values[i]; + p.middle = path.middle; + p.mangle = mangle; + sectors.push(p); + series.push(p); + opts.init && p.animate({ path: path.join(",") }, (+opts.init - 1) || 1000, ">"); } - - var path = sector(cx, cy, r, angle, angle -= 360 * values[i] / total); - var p = paper.path(opts.init ? ipath : path).attr({ fill: opts.colors && opts.colors[i] || chartinst.colors[i] || "#666", stroke: opts.stroke || "#fff", "stroke-width": (opts.strokewidth == null ? 1 : opts.strokewidth), "stroke-linejoin": "round" }); - - p.value = values[i]; - p.middle = path.middle; - p.mangle = mangle; - sectors.push(p); - series.push(p); - opts.init && p.animate({ path: path.join(",") }, (+opts.init - 1) || 1000, ">"); } for (i = 0; i < len; i++) { diff --git a/min/g.pie-min.js b/min/g.pie-min.js index 624adeb..dc3c982 100644 --- a/min/g.pie-min.js +++ b/min/g.pie-min.js @@ -1 +1 @@ -(function(){function b(n,h,g,t,e,o){o=o||{};var c=this,q=[],k=n.set(),s=n.set(),m=n.set(),x=[],z=e.length,A=0,D=0,C=0,f=9,B=true;function w(I,H,i,K,G,P){var M=Math.PI/180,E=I+i*Math.cos(-K*M),p=I+i*Math.cos(-G*M),J=I+i/2*Math.cos(-(K+(G-K)/2)*M),O=H+i*Math.sin(-K*M),N=H+i*Math.sin(-G*M),F=H+i/2*Math.sin(-(K+(G-K)/2)*M),L=["M",I,H,"L",E,O,"A",i,i,0,+(Math.abs(G-K)>180),1,p,N,"z"];L.middle={x:J,y:F};return L}s.covers=k;if(z==1){m.push(n.circle(h,g,t).attr({fill:c.colors[0],stroke:o.stroke||"#fff","stroke-width":o.strokewidth==null?1:o.strokewidth}));k.push(n.circle(h,g,t).attr(c.shim));D=e[0];e[0]={value:e[0],order:0,valueOf:function(){return this.value}};m[0].middle={x:h,y:g};m[0].mangle=180}else{for(var y=0;yf){B=false;e[f].value+=e[y];e[f].others=true;C=e[f].value}}z=Math.min(f+1,e.length);C&&e.splice(z)&&(e[f].others=true);for(y=0;y")}for(y=0;y180),1,x2,y2,"z"];res.middle={x:xm,y:ym};return res}chart.covers=covers;if(len==1){series.push(paper.circle(cx,cy,r).attr({fill:chartinst.colors[0],stroke:opts.stroke||"#fff","stroke-width":opts.strokewidth==null?1:opts.strokewidth}));covers.push(paper.circle(cx,cy,r).attr(chartinst.shim));total=values[0];values[0]={value:values[0],order:0,valueOf:function(){return this.value}};series[0].middle={x:cx,y:cy};series[0].mangle=180}else{for(var i=0;icut){defcut=false;values[cut].value+=values[i];values[cut].others=true;others=values[cut].value}}len=Math.min(cut+1,values.length);others&&values.splice(len)&&(values[cut].others=true);for(i=0;i")}}for(i=0;i