Skip to content

Commit

Permalink
removed y_as_bytes, replaced with y_format
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashid Khan committed Dec 3, 2013
1 parent f72687b commit a4e74ad
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/kibana/panels/histogram.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 53 additions & 1 deletion src/app/components/kbn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down Expand Up @@ -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;
});
3 changes: 0 additions & 3 deletions src/app/panels/histogram/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ <h5>Transform Series</h5>
<label class="small">Scale</label>
<input type="text" class="input-mini" ng-model="panel.scale">
</div>
<div class="editor-option">
<label class="small">Bytes <tip>Y-axis as bytes, eg 4 Mib instead of 4000000</tip></label><input type="checkbox" ng-model="panel.y_as_bytes" ng-checked="panel.y_as_bytes">
</div>
<div class="editor-option">
<label class="small">Seconds <tip>Normalize intervals to per-second</tip></label><input type="checkbox" ng-model="panel.scaleSeconds" ng-checked="panel.scaleSeconds">
</div>
Expand Down
17 changes: 13 additions & 4 deletions src/app/panels/histogram/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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');
Expand Down
4 changes: 4 additions & 0 deletions src/app/panels/histogram/styleEditor.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ <h5>Chart Options</h5>
<label class="small">Point Radius</label>
<select class="input-mini" ng-model="panel.pointradius" ng-options="f for f in [1,2,3,4,5,6,7,8,9,10]"></select>
</div>
<div class="editor-option">
<label class="small">Y Format <tip>Y-axis formatting</tip></label>
<select class="input-small" ng-model="panel.y_format" ng-options="f for f in ['none','short','bytes']"></select>
</div>
</div>
<div class="section">
<h5>Multiple Series</h5>
Expand Down

0 comments on commit a4e74ad

Please sign in to comment.