fix #8056 - more refinements to checking data
[g.raphael] / g.pie.sector.js
index d7426c8..ded7dae 100644 (file)
@@ -31,6 +31,7 @@ Roo = typeof(Roo) != 'undefined' ? Roo:  (imports ? imports.seed.Roo.Roo: {});
      *   labelsize (number) : font size of the labels
      *   labelweight (string)(number) : font weight of the labels
      *   labelcolor (string) : font color of the labels
+     *   showlabel (number) : only show label if the value >= 'showlabel'% of total
      *   legend (array) : legend
      *   legendpos (string) : position of the legend ('right' / 'bottom')
      *   legendkeyshape (string) : shape of the legend keys ('circle' / 'rect')
@@ -43,7 +44,7 @@ Roo = typeof(Roo) != 'undefined' ? Roo:  (imports ? imports.seed.Roo.Roo: {});
      */
 
     function Piesectorchart(paper, width, height, cx, cy, r, values, opts) {
-        
+         
         opts = opts || {};
 
         var chartinst = this,
@@ -57,7 +58,8 @@ Roo = typeof(Roo) != 'undefined' ? Roo:  (imports ? imports.seed.Roo.Roo: {});
             labelFont = opts.labelfont || "'Fontin Sans', Fontin-Sans, sans-serif",
             labelSize = opts.labelsize || 18,
             labelWeight = opts.labelweight || 'normal',
-            labelColor = opts.labelcolor || '#FFFFFF';
+            labelColor = opts.labelcolor || '#FFFFFF',
+            showLabel = typeof(opts.showlabel) != 'undefined' ? opts.showlabel : 5; // default show label if value >= 5% of total
         
         opts.barwidth = opts.barwidth || 80;
         
@@ -99,17 +101,17 @@ Roo = typeof(Roo) != 'undefined' ? Roo:  (imports ? imports.seed.Roo.Roo: {});
             }
             
             for (i = 0; i < len; i++) {
-                // minimum degree of a pie shown
-                if (defcut && values[i] * 360 / total <= 1.5) {
-                    cut = i;
-                    defcut = false;
-                }
-
                 if (i > cut) {
                     defcut = false;
                     values[cut].value += values[i];
                     values[cut].others = true;
                 }
+
+                // minimum degree of a pie shown
+                if (defcut && values[i] * 360 / total <= 1.5) {
+                    cut = i;
+                    defcut = false;
+                }
             }
             
             len = Math.min(cut + 1, values.length);
@@ -135,11 +137,11 @@ Roo = typeof(Roo) != 'undefined' ? Roo:  (imports ? imports.seed.Roo.Roo: {});
             a -= 360 * values[i] / total;
 
             // show the label only if the values >= 5% of total
-            if(labels && values[i] / total >= 0.05) {
-                var text = labels[i];
+            if(labels && values[i] / total >= (showLabel / 100)) {
+                var text = labels[values[i].origin];
 
                 if(text.indexOf('#qty#') !== -1) {
-                    text = text.replace('#qty#', Math.round(values[i]));
+                    text = text.replace('#qty#', Roo.util.Format.number(Math.round(values[i]), 0));
                 }
 
                 if(text.indexOf('#%#') !== -1) {
@@ -171,7 +173,8 @@ Roo = typeof(Roo) != 'undefined' ? Roo:  (imports ? imports.seed.Roo.Roo: {});
     // draw legend
     function legend(paper, cx, cy, r, values, opts, total, len) 
     {
-        var legendPos = opts.legendpos || 'right',
+        var chartinst = this,
+            legendPos = opts.legendpos || 'right',
             legendKeyShape = opts.legendkeyshape || 'circle',
             legendKeySize = opts.legendkeysize || 12,
             legendFont = opts.legendfont || "'Fontin Sans', Fontin-Sans, sans-serif",
@@ -209,7 +212,7 @@ Roo = typeof(Roo) != 'undefined' ? Roo:  (imports ? imports.seed.Roo.Roo: {});
             var text = (values[i].others) ? opts.others : opts.legend[values[i].origin] || values[i];
             
             if(text.indexOf('#qty#') !== -1) {
-                text = text.replace('#qty#', Math.round(values[i]));
+                text = text.replace('#qty#', Roo.util.Format.number(Math.round(values[i]), 0));
             }
 
             if(text.indexOf('#%#') !== -1) {
@@ -218,7 +221,7 @@ Roo = typeof(Roo) != 'undefined' ? Roo:  (imports ? imports.seed.Roo.Roo: {});
 
             var ty = iy - legendFontSize / 10;
 
-            if(text.includes("\n")) {
+            if(text.indexOf("\n")> -1) {
                 var ty = iy - legendFontSize / 10 + legendFontSize / 2;
             }