From 989d703d1da92bf9e3e21c91b5f6af863adb3581 Mon Sep 17 00:00:00 2001 From: Ian Clark Date: Thu, 17 Jul 2014 16:52:12 -0700 Subject: [PATCH] Adding bps unit type for network gear --- src/app/components/kbn.js | 51 ++++++++++++++++++++++++++++ src/app/directives/grafanaGraph.js | 3 ++ src/app/panels/graph/axisEditor.html | 4 +-- src/app/panels/graph/module.js | 2 +- 4 files changed, 57 insertions(+), 3 deletions(-) diff --git a/src/app/components/kbn.js b/src/app/components/kbn.js index 5faeafeb1ff..4e64df92b47 100644 --- a/src/app/components/kbn.js +++ b/src/app/components/kbn.js @@ -396,6 +396,53 @@ function($, _, moment) { return (size.toFixed(decimals) + ext); }; + kbn.bpsFormat = 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 = " bps"; + break; + case 1: + ext = " Kbps"; + break; + case 2: + ext = " Mbps"; + break; + case 3: + ext = " Gbps"; + break; + case 4: + ext = " Tbps"; + break; + case 5: + ext = " Pbps"; + break; + case 6: + ext = " Ebps"; + break; + case 7: + ext = " Zbps"; + break; + case 8: + ext = " Ybps"; + break; + } + + return (size.toFixed(decimals) + ext); + }; + kbn.shortFormat = function(size, decimals) { var ext, steps = 0; @@ -457,6 +504,10 @@ function($, _, moment) { return function(val) { return kbn.bitFormat(val, decimals); }; + case 'bps': + return function(val) { + return kbn.bpsFormat(val, decimals); + }; case 's': return function(val) { return kbn.sFormat(val, decimals); diff --git a/src/app/directives/grafanaGraph.js b/src/app/directives/grafanaGraph.js index 4baaaa62fd2..f120ce5584b 100755 --- a/src/app/directives/grafanaGraph.js +++ b/src/app/directives/grafanaGraph.js @@ -367,6 +367,9 @@ function (angular, $, kbn, moment, _) { case 'bits': url += '&yUnitSystem=binary'; break; + case 'bps': + url += '&yUnitSystem=si'; + break; case 'short': url += '&yUnitSystem=si'; break; diff --git a/src/app/panels/graph/axisEditor.html b/src/app/panels/graph/axisEditor.html index eb8ac3fb081..fb70f791393 100644 --- a/src/app/panels/graph/axisEditor.html +++ b/src/app/panels/graph/axisEditor.html @@ -4,7 +4,7 @@
Left Y Axis
- +
@@ -23,7 +23,7 @@
Right Y Axis
- +
diff --git a/src/app/panels/graph/module.js b/src/app/panels/graph/module.js index 66994361d91..e300ee90751 100644 --- a/src/app/panels/graph/module.js +++ b/src/app/panels/graph/module.js @@ -86,7 +86,7 @@ function (angular, app, $, _, kbn, moment, timeSeries) { */ scale : 1, /** @scratch /panels/histogram/3 - * y_formats :: 'none','bytes','bits','short', 's', 'ms' + * y_formats :: 'none','bytes','bits','bps','short', 's', 'ms' */ y_formats : ['short', 'short'], /** @scratch /panels/histogram/5