fix #8056 - more refinements to checking data
[g.raphael] / g.circular.js
index 6553bee..d5a32cc 100644 (file)
@@ -42,21 +42,14 @@ Roo = typeof(Roo) != 'undefined' ? Roo:  (imports ? imports.seed.Roo.Roo: {});
             '#eeeeee'
         ];
         
-        if(opts.colors){
-            colors = opts.colors;
-        }
-        
         paper.customAttributes.circularPath = function (cx, cy, value, maxvalue, maxangle, color, R) {
             var alpha = maxangle / maxvalue * value,
                 a = (90 - alpha) * Math.PI / 180,
                 x = cx + R * Math.cos(a),
                 y = cy - R * Math.sin(a),
                 path;
-            if (total == value) {
-                path = [["M", cx, cy - R], ["A", R, R, 0, 1, 1, cx - 1, cy - R]];
-            } else {
-                path = [["M", cx, cy - R], ["A", R, R, 0, +(alpha > 180), 1, x, y]];
-            }
+            
+            path = [["M", cx, cy - R], ["A", R, R, 0, +(alpha > 180), 1, x, y]];
 
             return {path: path, stroke: color};
         };
@@ -71,9 +64,19 @@ Roo = typeof(Roo) != 'undefined' ? Roo:  (imports ? imports.seed.Roo.Roo: {});
             maxangle = opts.maxangle || 270,
             maxvalue = 0,
             total = 0,
-            cut = opts.cut || 10;
+            cut = opts.cut || 8;
             
-        var barwidth = Math.min(Math.floor(r / cut), 12);
+        var barwidth = opts.barwidth || Math.min(Math.floor(r / cut), 12);
+        
+        if(len < 8){
+            colors = colors.slice(8 - len);
+        }
+        
+        if(opts.colors){
+            colors = opts.colors;
+        }
+    
+        var tempVal = [];
         
         for (var i = 0; i < len; i++){
             
@@ -82,7 +85,7 @@ Roo = typeof(Roo) != 'undefined' ? Roo:  (imports ? imports.seed.Roo.Roo: {});
             total += values[i];
             
             if(i <= cut){
-                values[i] = {
+                tempVal[i] = {
                     value : values[i],
                     order : i,
                     others : false,
@@ -91,13 +94,12 @@ Roo = typeof(Roo) != 'undefined' ? Roo:  (imports ? imports.seed.Roo.Roo: {});
                 continue;
             }
             
-            values[cut].value += values[i];
-            values[cut].others = true;
-            
-            values.splice(i, 1);
+            tempVal[cut].value += values[i] * 1;
+            tempVal[cut].others = true;
             
         }
         
+        values = tempVal;
         len = values.length;
                 
         if (!opts.no_sort) {
@@ -133,75 +135,45 @@ Roo = typeof(Roo) != 'undefined' ? Roo:  (imports ? imports.seed.Roo.Roo: {});
         
         paper.text(cx - r + 20, cy + r + 30, (opts.totalmsg || 'Total:') + ' ' + total ).attr(opts.txtattr || chartinst.txtattr).attr({ fill: "#000", "text-anchor": "start"});
         
-        var legend = function (labels, otherslabel, mark, dir) {
+        var legend = function (labels, otherslabel, mark) {
             var x = cx + r  + r / 3,
-                y = cy,
+                y = cy - r,
                 labels = labels || [];
         
-            dir = (dir && dir.toLowerCase && dir.toLowerCase()) || "east";
             mark = paper[mark && mark.toLowerCase()] || "circle";
-            chart.labels = paper.set();
-
-//            for (var i = 0; i < len; i++) {
-//                var j = values[i].order,
-//                    txt;
-//
-//                var l = values[i].others ? (otherslabel || "Others") : labels[j];
-//                
-//                chart.labels.push(paper.set());
-//                chart.labels[i].push(paper[mark](x + 5, y, 5).attr({ fill: colors[i] || chartinst.colors[i], stroke: "none" }));
-//                chart.labels[i].push(
-//                    txt = paper.text(x + 20, y, l || values[i]).attr(opts.txtattr || chartinst.txtattr).attr({ fill: opts.legendcolor || "#000", "text-anchor": "start"}));
-//                
-//                y += txt.getBBox().height * 1.2;
-//            }
             
             for (var i = 0; i < len; i++) {
                 var j = values[i].order,
                     txt;
 
                 if(values[i].others){
-                    //continue;
+                    continue;
                 }
                 
-                chart.labels.push(paper.set());
-                chart.labels[i].push(paper[mark](x + 5, y, 5).attr({ fill: colors[i] || chartinst.colors[i], stroke: "none" }));
-                chart.labels[i].push(
-                    txt = paper.text(x + 20, y, labels[j] || values[i]).attr(opts.txtattr || chartinst.txtattr).attr({ fill: opts.legendcolor || "#000", "text-anchor": "start"}));
+                paper[mark](x + 5, y, 5).attr({ fill: colors[i] || chartinst.colors[i], stroke: "none" })
+                txt = paper.text(x + 20, y, labels[j] || values[i]).attr(opts.txtattr || chartinst.txtattr).attr({ fill: opts.legendcolor || "#000", "text-anchor": "start"})
                 
                 y += txt.getBBox().height * 1.2;
             }
             
-//            for (var i = 0; i < len; i++) {
-//                var j = values[i].order,
-//                    txt;
-//
-//                if(!values[i].others){
-//                    continue;
-//                }
-//                
-//                chart.labels.push(paper.set());
-//                chart.labels[len - 1].push(paper[mark](x + 5, y, 5).attr({ fill: colors[i] || chartinst.colors[i], stroke: "none" }));
-//                chart.labels[len - 1].push(
-//                    txt = paper.text(x + 20, y, otherslabel || 'Others').attr(opts.txtattr || chartinst.txtattr).attr({ fill: opts.legendcolor || "#000", "text-anchor": "start"}));
-//                
-//                y += txt.getBBox().height * 1.2;
-//            }
+            for (var i = 0; i < len; i++) {
+                var j = values[i].order,
+                    txt;
 
-            var bb = chart.labels.getBBox(),
-                tr = {
-                    east: [0, -bb.height / 2],
-                    west: [-bb.width - 2 * r - 20, -bb.height / 2],
-                    north: [-r - bb.width / 2, -r - bb.height - 10],
-                    south: [-r - bb.width / 2, r + 10]
-                }[dir];
+                if(!values[i].others){
+                    continue;
+                }
+                
+                paper[mark](x + 5, y, 5).attr({ fill: colors[i] || chartinst.colors[i], stroke: "none" })
+                txt = paper.text(x + 20, y, otherslabel || 'Others').attr(opts.txtattr || chartinst.txtattr).attr({ fill: opts.legendcolor || "#000", "text-anchor": "start"})
+                
+                y += txt.getBBox().height * 1.2;
+            }
 
-            chart.labels.translate.apply(chart.labels, tr);
-            chart.push(chart.labels);
         };
 
         if (opts.legend) {
-            legend(opts.legend, opts.legendothers, opts.legendmark, opts.legendpos);
+            legend(opts.legend, opts.legendothers, opts.legendmark);
         }
 
         chart.sectors = sectors;