mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Closes #97, legend values now use selected y axis formater for precision and formating
This commit is contained in:
@@ -132,35 +132,13 @@ function (angular, $, kbn, moment, _) {
|
||||
}
|
||||
};
|
||||
|
||||
if (panel.grid.threshold1) {
|
||||
var limit1 = panel.grid.thresholdLine ? panel.grid.threshold1 : (panel.grid.threshold2 || null);
|
||||
options.grid.markings = [];
|
||||
options.grid.markings.push({
|
||||
yaxis: { from: panel.grid.threshold1, to: limit1 },
|
||||
color: panel.grid.threshold1Color
|
||||
});
|
||||
|
||||
if (panel.grid.threshold2) {
|
||||
var limit2;
|
||||
if (panel.grid.thresholdLine) {
|
||||
limit2 = panel.grid.threshold2;
|
||||
} else {
|
||||
limit2 = panel.grid.threshold1 > panel.grid.threshold2 ? -Infinity : +Infinity;
|
||||
}
|
||||
options.grid.markings.push({
|
||||
yaxis: { from: panel.grid.threshold2, to: limit2 },
|
||||
color: panel.grid.threshold2Color
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
addAnnotations(options);
|
||||
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var _d = data[i].getFlotPairs(panel.nullPointMode);
|
||||
var _d = data[i].getFlotPairs(panel.nullPointMode, panel.y_formats);
|
||||
data[i].data = _d;
|
||||
}
|
||||
|
||||
addGridThresholds(options, panel);
|
||||
addAnnotations(options);
|
||||
configureAxisOptions(data, options);
|
||||
|
||||
plot = $.plot(elem, data, options);
|
||||
@@ -210,6 +188,30 @@ function (angular, $, kbn, moment, _) {
|
||||
elem.html('<img src="' + url + '"></img>');
|
||||
}
|
||||
|
||||
function addGridThresholds(options, panel) {
|
||||
if (panel.grid.threshold1) {
|
||||
var limit1 = panel.grid.thresholdLine ? panel.grid.threshold1 : (panel.grid.threshold2 || null);
|
||||
options.grid.markings = [];
|
||||
options.grid.markings.push({
|
||||
yaxis: { from: panel.grid.threshold1, to: limit1 },
|
||||
color: panel.grid.threshold1Color
|
||||
});
|
||||
|
||||
if (panel.grid.threshold2) {
|
||||
var limit2;
|
||||
if (panel.grid.thresholdLine) {
|
||||
limit2 = panel.grid.threshold2;
|
||||
} else {
|
||||
limit2 = panel.grid.threshold1 > panel.grid.threshold2 ? -Infinity : +Infinity;
|
||||
}
|
||||
options.grid.markings.push({
|
||||
yaxis: { from: panel.grid.threshold2, to: limit2 },
|
||||
color: panel.grid.threshold2Color
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addAnnotations(options) {
|
||||
if(!data.annotations || data.annotations.length === 0) {
|
||||
return;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
define([
|
||||
'underscore'
|
||||
'underscore',
|
||||
'kbn'
|
||||
],
|
||||
function (_) {
|
||||
function (_, kbn) {
|
||||
'use strict';
|
||||
|
||||
var ts = {};
|
||||
@@ -12,7 +13,7 @@ function (_) {
|
||||
this.label = opts.info.alias;
|
||||
};
|
||||
|
||||
ts.ZeroFilled.prototype.getFlotPairs = function (fillStyle) {
|
||||
ts.ZeroFilled.prototype.getFlotPairs = function (fillStyle, yFormats) {
|
||||
var result = [];
|
||||
|
||||
this.color = this.info.color;
|
||||
@@ -50,13 +51,39 @@ function (_) {
|
||||
}, this);
|
||||
|
||||
if (result.length) {
|
||||
this.info.avg = (this.info.total / result.length).toFixed(2);
|
||||
this.info.avg = (this.info.total / result.length);
|
||||
this.info.current = result[result.length-1][1];
|
||||
|
||||
var formater = getFormater(yFormats[this.yaxis - 1]);
|
||||
this.info.avg = formater(this.info.avg);
|
||||
this.info.current = formater(this.info.current);
|
||||
this.info.min = formater(this.info.min);
|
||||
this.info.max = formater(this.info.max);
|
||||
this.info.total = formater(this.info.total);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
function getFormater(yformat) {
|
||||
switch(yformat) {
|
||||
case 'bytes':
|
||||
return kbn.byteFormat;
|
||||
case 'short':
|
||||
return kbn.shortFormat;
|
||||
case 'ms':
|
||||
return kbn.msFormat;
|
||||
default:
|
||||
return function(val) {
|
||||
if (val % 1 === 0) {
|
||||
return val;
|
||||
}
|
||||
else {
|
||||
return val.toFixed(2);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return ts;
|
||||
});
|
||||
Reference in New Issue
Block a user