Browse Source

removed y_as_bytes, replaced with y_format

Rashid Khan 12 years ago
parent
commit
a4e74ad34f

+ 1 - 1
docs/kibana/panels/histogram.asciidoc

@@ -28,7 +28,7 @@ y-axis:: Show the y-axis
 scale:: Scale the y-axis by this factor
 // src/app/panels/histogram/module.js:88
 
-y_as_bytes:: Show the y-axis scale as bytes, automatically round to KB, MB, GB, etc.
+y_format:: 'none','bytes','short '
 // src/app/panels/histogram/module.js:92
 
 ==== Annotations

+ 53 - 1
src/app/components/kbn.js

@@ -501,7 +501,12 @@ function($, _, moment) {
 
   kbn.byteFormat = function(size, decimals) {
     var ext, steps = 0;
-    decimals = decimals || 2;
+
+    if(_.isUndefined(decimals)) {
+      decimals = 2;
+    } else if (decimals === 0) {
+      decimals = undefined;
+    }
 
     while (Math.abs(size) >= 1024) {
       steps++;
@@ -541,5 +546,52 @@ function($, _, moment) {
     return (size.toFixed(decimals) + ext);
   };
 
+  kbn.shortFormat = function(size, decimals) {
+    var ext, steps = 0;
+
+    if(_.isUndefined(decimals)) {
+      decimals = 2;
+    } else if (decimals === 0) {
+      decimals = undefined;
+    }
+
+    while (Math.abs(size) >= 1000) {
+      steps++;
+      size /= 1000;
+    }
+
+    switch (steps) {
+    case 0:
+      ext = "";
+      break;
+    case 1:
+      ext = " K";
+      break;
+    case 2:
+      ext = " Mil";
+      break;
+    case 3:
+      ext = " Bil";
+      break;
+    case 4:
+      ext = " Tri";
+      break;
+    case 5:
+      ext = " Quadr";
+      break;
+    case 6:
+      ext = " Quint";
+      break;
+    case 7:
+      ext = " Sext";
+      break;
+    case 8:
+      ext = " Sept";
+      break;
+    }
+
+    return (size.toFixed(decimals) + ext);
+  };
+
   return kbn;
 });

+ 0 - 3
src/app/panels/histogram/editor.html

@@ -16,9 +16,6 @@
       <label class="small">Scale</label>
         <input type="text" class="input-mini" ng-model="panel.scale">
     </div>
-    <div class="editor-option">
-      <label class="small">Bytes <tip>Y-axis as bytes, eg 4 Mib instead of 4000000</tip></label><input type="checkbox" ng-model="panel.y_as_bytes" ng-checked="panel.y_as_bytes">
-    </div>
     <div class="editor-option">
       <label class="small">Seconds <tip>Normalize intervals to per-second</tip></label><input type="checkbox" ng-model="panel.scaleSeconds" ng-checked="panel.scaleSeconds">
     </div>

+ 13 - 4
src/app/panels/histogram/module.js

@@ -90,9 +90,9 @@ function (angular, app, $, _, kbn, moment, timeSeries) {
        */
       scale         : 1,
       /** @scratch /panels/histogram/3
-       * y_as_bytes:: Show the y-axis scale as bytes, automatically round to KB, MB, GB, etc.
+       * y_format:: 'none','bytes','short '
        */
-      y_as_bytes    : false,
+      y_format    : 'none',
       /** @scratch /panels/histogram/5
        * grid object:: Min and max y-axis values
        * grid.min::: Minimum y-axis value
@@ -632,10 +632,16 @@ function (angular, app, $, _, kbn, moment, timeSeries) {
               }
             };
 
-            if(scope.panel.y_as_bytes) {
+            if(scope.panel.y_format === 'bytes') {
               options.yaxis.mode = "byte";
             }
 
+            if(scope.panel.y_format === 'short') {
+              options.yaxis.tickFormatter = function(val) {
+                return kbn.shortFormat(val,0);
+              };
+            }
+
             if(scope.panel.annotate.enable) {
               options.events = {
                 levels: 1,
@@ -724,9 +730,12 @@ function (angular, app, $, _, kbn, moment, timeSeries) {
             value = (scope.panel.stack && scope.panel.tooltip.value_type === 'individual') ?
               item.datapoint[1] - item.datapoint[2] :
               item.datapoint[1];
-            if(scope.panel.y_as_bytes) {
+            if(scope.panel.y_format === 'bytes') {
               value = kbn.byteFormat(value,2);
             }
+            if(scope.panel.y_format === 'short') {
+              value = kbn.shortFormat(value,2);
+            }
             timestamp = scope.panel.timezone === 'browser' ?
               moment(item.datapoint[0]).format('YYYY-MM-DD HH:mm:ss') :
               moment.utc(item.datapoint[0]).format('YYYY-MM-DD HH:mm:ss');

+ 4 - 0
src/app/panels/histogram/styleEditor.html

@@ -29,6 +29,10 @@
       <label class="small">Point Radius</label>
       <select class="input-mini" ng-model="panel.pointradius" ng-options="f for f in [1,2,3,4,5,6,7,8,9,10]"></select>
     </div>
+    <div class="editor-option">
+      <label class="small">Y Format <tip>Y-axis formatting</tip></label>
+      <select class="input-small" ng-model="panel.y_format" ng-options="f for f in ['none','short','bytes']"></select>
+    </div>
   </div>
   <div class="section">
     <h5>Multiple Series</h5>