فهرست منبع

Graph: fix for downscaling y-axis format, never downscale when value is zero, Fixes #826

Torkel Ödegaard 11 سال پیش
والد
کامیت
563dd898c1
3فایلهای تغییر یافته به همراه15 افزوده شده و 4 حذف شده
  1. 4 4
      src/app/components/kbn.js
  2. 5 0
      src/app/directives/grafanaGraph.js
  3. 6 0
      src/test/specs/kbn-format-specs.js

+ 4 - 4
src/app/components/kbn.js

@@ -567,8 +567,8 @@ function($, _, moment) {
 
   kbn.msFormat = function(size, decimals) {
     // Less than 1 milli, downscale to micro
-    if (Math.abs(size) < 1) {
-      return kbn.microsFormat(size * 1000,decimals);
+    if (size !== 0 && Math.abs(size) < 1) {
+      return kbn.microsFormat(size * 1000, decimals);
     }
     else if (Math.abs(size) < 1000) {
       return size.toFixed(decimals) + " ms";
@@ -595,7 +595,7 @@ function($, _, moment) {
 
   kbn.sFormat = function(size, decimals) {
     // Less than 1 sec, downscale to milli
-    if (Math.abs(size) < 1) {
+    if (size !== 0 && Math.abs(size) < 1) {
       return kbn.msFormat(size * 1000, decimals);
     }
     // Less than 10 min, use seconds
@@ -624,7 +624,7 @@ function($, _, moment) {
 
   kbn.microsFormat = function(size, decimals) {
     // Less than 1 micro, downscale to nano
-    if (Math.abs(size) < 1) {
+    if (size !== 0 && Math.abs(size) < 1) {
       return kbn.nanosFormat(size * 1000, decimals);
     }
     else if (Math.abs(size) < 1000) {

+ 5 - 0
src/app/directives/grafanaGraph.js

@@ -110,6 +110,11 @@ function (angular, $, kbn, moment, _) {
 
           // Populate element
           var options = {
+            hooks: {
+              drawSeries: [function() {
+                console.log('drawSeries', arguments);
+              }]
+            },
             legend: { show: false },
             series: {
               stackpercent: panel.stack ? panel.percentage : false,

+ 6 - 0
src/test/specs/kbn-format-specs.js

@@ -15,6 +15,12 @@ define([
       expect(str).to.be('1.02 hour');
     });
 
+    it('should not downscale when value is zero', function() {
+      var str = kbn.msFormat(0, 2);
+      expect(str).to.be('0.00 ms');
+    });
+
+
     it('should translate 365445 as 6.09 min', function() {
       var str = kbn.msFormat(365445, 2);
       expect(str).to.be('6.09 min');