From 563dd898c1761b2aa80f559a6909da9e682119c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 19 Sep 2014 12:16:00 +0200 Subject: [PATCH] Graph: fix for downscaling y-axis format, never downscale when value is zero, Fixes #826 --- src/app/components/kbn.js | 8 ++++---- src/app/directives/grafanaGraph.js | 5 +++++ src/test/specs/kbn-format-specs.js | 6 ++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/app/components/kbn.js b/src/app/components/kbn.js index 374d2f561b8..7c61b22c83b 100644 --- a/src/app/components/kbn.js +++ b/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) { diff --git a/src/app/directives/grafanaGraph.js b/src/app/directives/grafanaGraph.js index 15f1556aa62..ee6b0fb7dd7 100755 --- a/src/app/directives/grafanaGraph.js +++ b/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, diff --git a/src/test/specs/kbn-format-specs.js b/src/test/specs/kbn-format-specs.js index a44475556b0..85807c277ec 100644 --- a/src/test/specs/kbn-format-specs.js +++ b/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');