From 5ec525a4303b07226f912d70058b89c927eb05f0 Mon Sep 17 00:00:00 2001 From: Markus Linnala Date: Sat, 1 Mar 2014 20:20:42 +0200 Subject: [PATCH] add bits format for Y-Axis --- src/app/components/kbn.js | 51 +++++++++++++++++++++++++ src/app/directives/grafanaGraph.js | 3 ++ src/app/panels/graphite/axisEditor.html | 6 +-- src/app/panels/graphite/module.js | 2 +- 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/app/components/kbn.js b/src/app/components/kbn.js index 44033ca7b5f..be8065ce57d 100644 --- a/src/app/components/kbn.js +++ b/src/app/components/kbn.js @@ -458,6 +458,53 @@ function($, _, moment) { return (size.toFixed(decimals) + ext); }; + kbn.bitFormat = function(size, decimals) { + var ext, steps = 0; + + if(_.isUndefined(decimals)) { + decimals = 2; + } else if (decimals === 0) { + decimals = undefined; + } + + while (Math.abs(size) >= 1024) { + steps++; + size /= 1024; + } + + switch (steps) { + case 0: + ext = " b"; + break; + case 1: + ext = " Kb"; + break; + case 2: + ext = " Mb"; + break; + case 3: + ext = " Gb"; + break; + case 4: + ext = " Tb"; + break; + case 5: + ext = " Pb"; + break; + case 6: + ext = " Eb"; + break; + case 7: + ext = " Zb"; + break; + case 8: + ext = " Yb"; + break; + } + + return (size.toFixed(decimals) + ext); + }; + kbn.shortFormat = function(size, decimals) { var ext, steps = 0; @@ -515,6 +562,10 @@ function($, _, moment) { return function(val) { return kbn.byteFormat(val, decimals); }; + case 'bits': + return function(val) { + return kbn.bitFormat(val, decimals); + }; case 'ms': return function(val) { return kbn.msFormat(val, decimals); diff --git a/src/app/directives/grafanaGraph.js b/src/app/directives/grafanaGraph.js index 1e5d20c8f7c..ac6beed8fa3 100644 --- a/src/app/directives/grafanaGraph.js +++ b/src/app/directives/grafanaGraph.js @@ -336,6 +336,9 @@ function (angular, $, kbn, moment, _) { case 'bytes': url += '&yUnitSystem=binary'; break; + case 'bits': + url += '&yUnitSystem=binary'; + break; case 'short': url += '&yUnitSystem=si'; break; diff --git a/src/app/panels/graphite/axisEditor.html b/src/app/panels/graphite/axisEditor.html index 4ce3232411b..1a91fe6bcb2 100644 --- a/src/app/panels/graphite/axisEditor.html +++ b/src/app/panels/graphite/axisEditor.html @@ -10,11 +10,11 @@
- +
- +
@@ -102,4 +102,4 @@
- \ No newline at end of file + diff --git a/src/app/panels/graphite/module.js b/src/app/panels/graphite/module.js index 05a609192c7..d04e0576f0d 100644 --- a/src/app/panels/graphite/module.js +++ b/src/app/panels/graphite/module.js @@ -84,7 +84,7 @@ function (angular, app, $, _, kbn, moment, timeSeries) { */ scale : 1, /** @scratch /panels/histogram/3 - * y_formats :: 'none','bytes','short', 'ms' + * y_formats :: 'none','bytes','bits','short', 'ms' */ y_formats : ['short', 'short'], /** @scratch /panels/histogram/5