fix #8056 - more refinements to checking data
[g.raphael] / g.pie.js
index 91fe8d5..e50e397 100644 (file)
--- a/g.pie.js
+++ b/g.pie.js
@@ -4,9 +4,29 @@
  * Copyright (c) 2009 Dmitry Baranovskiy (http://g.raphaeljs.com)
  * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
  */
+Raphael = typeof(Raphael) != 'undefined' ? Raphael :  (imports ? imports.seed.Raphael.Raphael : {});
+Roo = typeof(Roo) != 'undefined' ? Roo:  (imports ? imports.seed.Roo.Roo: {});
+//chartinst = typeof(chartinst) != 'undefined' ? chartinst:  (imports ? imports.chartinst.chartinst : {});
+
+
 (function () {
 
+    /**
+     * @param {Raphael} paper to draw on
+     * @param {int} cx - centre X
+     * @param {int} cy - centre Y
+     * @param {int} r - radius
+     * @param {Array} values
+     * @param {Object} opts options
+     *   cut : after this meany items - do not show a pie element?
+     *   
+     *   
+     * 
+     */
+
     function Piechart(paper, cx, cy, r, values, opts) {
+        
         opts = opts || {};
 
         var chartinst = this,
@@ -21,7 +41,7 @@
             others = 0,
             cut = opts.cut || 9,
             defcut = true;
-
+            
         function sector(cx, cy, r, startAngle, endAngle, fill) {
             var rad = Math.PI / 180,
                 x1 = cx + r * Math.cos(-startAngle * rad),
         }
         
         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 }));
+            series.push(paper.circle(cx, cy, r).attr({ fill: opts.colors && opts.colors[0] || chartinst.colors[0] || "#666", 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];
+            total = values[0] * 1;
             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; i < len; i++) {
-                total += values[i];
-                values[i] = { value: values[i], order: i, valueOf: function () { return this.value; } };
+                total += values[i] * 1;
+                values[i] = {
+                        value: values[i],
+                        order: i,
+                        valueOf: function () { return this.value; }
+                };
             }
+            //Roo.log(total);
             if (!opts.no_sort) {
                 values.sort(function (a, b) {
                     return b.value - a.value;
@@ -73,7 +98,7 @@
                     others = values[cut].value;
                 }
             }
-
+            
             len = Math.min(cut + 1, values.length);
             others && values.splice(len) && (values[cut].others = true);
 
                         angle = opts.start_angle;
                     }
                     
-                    Roo.log('start angle: ' + angle);
+                    //Roo.log('start angle: ' + angle);
                     mangle = angle - 360 * values[i] / total / 2;
                 }
 
             var x = cx + r + r / 5,
                 y = cy,
                 h = y + 10;
-
+            
             labels = labels || [];
             dir = (dir && dir.toLowerCase && dir.toLowerCase()) || "east";
             mark = paper[mark && mark.toLowerCase()] || "circle";
                     txt;
 
                 values[i].others && (labels[j] = otherslabel || "Others");
-                Roo.log(labels[j]);
                 labels[j] = chartinst.labelise(labels[j], values[i], total);
-                Roo.log(labels[j]);
                 chart.labels.push(paper.set());
                 chart.labels[i].push(paper[mark](x + 5, h, 5).attr({ fill: clr, stroke: "none" }));
-                chart.labels[i].push(txt = paper.text(x + 20, h, labels[j] || values[j]).attr(chartinst.txtattr).attr({ fill: opts.legendcolor || "#000", "text-anchor": "start"}));
+                chart.labels[i].push(
+                    txt = paper.text(x + 20, h, labels[j] || values[j]).attr(chartinst.txtattr).attr({ fill: opts.legendcolor || "#000", "text-anchor": "start"}));
                 covers[i].label = chart.labels[i];
+               // Roo.log(JSON.stringify(txt.getBBox()));
                 h += txt.getBBox().height * 1.2;
             }