From a4e74ad34f63805fcde1cc2791751d8015201e50 Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Tue, 3 Dec 2013 16:12:56 -0700 Subject: [PATCH] removed y_as_bytes, replaced with y_format --- docs/kibana/panels/histogram.asciidoc | 2 +- src/app/components/kbn.js | 54 ++++++++++++++++++++++- src/app/panels/histogram/editor.html | 3 -- src/app/panels/histogram/module.js | 17 +++++-- src/app/panels/histogram/styleEditor.html | 4 ++ 5 files changed, 71 insertions(+), 9 deletions(-) diff --git a/docs/kibana/panels/histogram.asciidoc b/docs/kibana/panels/histogram.asciidoc index 0cde6be0ef9..d2d7d1951fb 100644 --- a/docs/kibana/panels/histogram.asciidoc +++ b/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 diff --git a/src/app/components/kbn.js b/src/app/components/kbn.js index 8a7bb392b74..372424305d6 100644 --- a/src/app/components/kbn.js +++ b/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; }); \ No newline at end of file diff --git a/src/app/panels/histogram/editor.html b/src/app/panels/histogram/editor.html index d3192e6914d..15490701bb4 100644 --- a/src/app/panels/histogram/editor.html +++ b/src/app/panels/histogram/editor.html @@ -16,9 +16,6 @@ -
- -
diff --git a/src/app/panels/histogram/module.js b/src/app/panels/histogram/module.js index 217c69bf64f..720ca36fb6f 100644 --- a/src/app/panels/histogram/module.js +++ b/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'); diff --git a/src/app/panels/histogram/styleEditor.html b/src/app/panels/histogram/styleEditor.html index f53a9ec3876..874a22640b5 100644 --- a/src/app/panels/histogram/styleEditor.html +++ b/src/app/panels/histogram/styleEditor.html @@ -29,6 +29,10 @@ +
+ + +
Multiple Series