add support for label under 5%
authorAlan <alan@roojs.com>
Thu, 15 Jun 2023 02:53:10 +0000 (10:53 +0800)
committerAlan <alan@roojs.com>
Thu, 15 Jun 2023 02:53:10 +0000 (10:53 +0800)
g.bar.overlay.js
g.pie.sector.js

index 221a81a..0fa8f26 100644 (file)
@@ -297,7 +297,7 @@ if (typeof(Raphael) == 'undefined') {
             
             if(i != 0) {
                 // 6 pixels away from bottom of the line
-                paper.text(x + (axisYWidth / 2), Y + axisFontSize / 2 + 6, label).attr({ 
+                paper.text(x + (axisYWidth / 2), Y + axisFontSize / 2 + 6, Roo.util.Format.number(label, 0)).attr({ 
                     "font-size": axisFontSize,
                     "font-family": axisFont,
                     "font-weight": axisFontWeight,
index 01ddd27..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;
         
@@ -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) {
@@ -210,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) {