Commit e78c4862 by Torkel Ödegaard

Trying to improve yaxis precision

parent 563dd898
......@@ -7,6 +7,7 @@ function($, _, moment) {
'use strict';
var kbn = {};
kbn.formatFunctions = {};
kbn.round_interval = function(interval) {
switch (true) {
......@@ -497,52 +498,7 @@ function($, _, moment) {
return (size.toFixed(decimals) + ext);
};
kbn.getFormatFunction = function(formatName, decimals) {
switch(formatName) {
case 'short':
return function(val) {
return kbn.shortFormat(val, decimals);
};
case 'bytes':
return function(val) {
return kbn.byteFormat(val, decimals);
};
case 'bits':
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);
};
case 'ms':
return function(val) {
return kbn.msFormat(val, decimals);
};
case 'µs':
return function(val) {
return kbn.microsFormat(val, decimals);
};
case 'ns':
return function(val) {
return kbn.nanosFormat(val, decimals);
};
case 'percent':
return function(val, axis) {
return kbn.noneFormat(val, axis ? axis.tickDecimals : null) + ' %';
};
default:
return function(val, axis) {
return kbn.noneFormat(val, axis ? axis.tickDecimals : null);
};
}
};
kbn.noneFormat = function(value, decimals) {
kbn.toFixed = function(value, decimals) {
var factor = decimals ? Math.pow(10, decimals) : 1;
var formatted = String(Math.round(value * factor) / factor);
......@@ -553,7 +509,6 @@ function($, _, moment) {
// If tickDecimals was specified, ensure that we have exactly that
// much precision; otherwise default to the value's own precision.
if (decimals != null) {
var decimalPos = formatted.indexOf(".");
var precision = decimalPos === -1 ? 0 : formatted.length - decimalPos - 1;
......@@ -565,17 +520,13 @@ function($, _, moment) {
return formatted;
};
kbn.msFormat = function(size, decimals) {
// Less than 1 milli, downscale to micro
if (size !== 0 && Math.abs(size) < 1) {
return kbn.microsFormat(size * 1000, decimals);
}
else if (Math.abs(size) < 1000) {
return size.toFixed(decimals) + " ms";
kbn.formatFunctions.ms = function(size, decimals) {
if (Math.abs(size) < 1000) {
return kbn.toFixed(size, decimals) + " ms";
}
// Less than 1 min
else if (Math.abs(size) < 60000) {
return (size / 1000).toFixed(decimals) + " s";
return kbn.toFixed(size / 1000, decimals) + " s";
}
// Less than 1 hour, devide in minutes
else if (Math.abs(size) < 3600000) {
......@@ -594,12 +545,7 @@ function($, _, moment) {
};
kbn.sFormat = function(size, decimals) {
// Less than 1 sec, downscale to milli
if (size !== 0 && Math.abs(size) < 1) {
return kbn.msFormat(size * 1000, decimals);
}
// Less than 10 min, use seconds
else if (Math.abs(size) < 600) {
if (Math.abs(size) < 600) {
return size.toFixed(decimals) + " s";
}
// Less than 1 hour, devide in minutes
......@@ -623,12 +569,8 @@ function($, _, moment) {
};
kbn.microsFormat = function(size, decimals) {
// Less than 1 micro, downscale to nano
if (size !== 0 && Math.abs(size) < 1) {
return kbn.nanosFormat(size * 1000, decimals);
}
else if (Math.abs(size) < 1000) {
return size.toFixed(decimals) + " µs";
if (Math.abs(size) < 1000) {
return kbn.toFixed(size, decimals) + " µs";
}
else if (Math.abs(size) < 1000000) {
return (size / 1000).toFixed(decimals) + " ms";
......
......@@ -100,21 +100,21 @@ function (_, kbn) {
}
if (result.length) {
this.info.avg = (this.info.total / result.length);
this.info.current = result[result.length-1][1];
var formater = kbn.getFormatFunction(yFormats[this.yaxis - 1], 2);
this.info.avg = this.info.avg != null ? formater(this.info.avg) : null;
this.info.current = this.info.current != null ? formater(this.info.current) : null;
this.info.min = this.info.min != null ? formater(this.info.min) : null;
this.info.max = this.info.max != null ? formater(this.info.max) : null;
this.info.total = this.info.total != null ? formater(this.info.total) : null;
}
return result;
};
TimeSeries.prototype.updateLegendValues = function(formater, decimals) {
this.info.avg = this.info.avg != null ? formater(this.info.avg, decimals) : null;
this.info.current = this.info.current != null ? formater(this.info.current, decimals) : null;
this.info.min = this.info.min != null ? formater(this.info.min, decimals) : null;
this.info.max = this.info.max != null ? formater(this.info.max, decimals) : null;
this.info.total = this.info.total != null ? formater(this.info.total, decimals) : null;
};
return TimeSeries;
});
......@@ -88,6 +88,18 @@ function (angular, $, kbn, moment, _) {
}
}
function updateLegendValues(plot) {
var yaxis = plot.getYAxes();
console.log('drawSeries', yaxis);
for (var i = 0; i < data.length; i++) {
var series = data[i];
var formater = kbn.formatFunctions[scope.panel.y_formats[series.yaxis - 1]];
series.updateLegendValues(formater, yaxis[series.yaxis - 1].tickDecimals);
}
}
// Function for rendering panel
function render_panel() {
if (shouldAbortRender()) {
......@@ -110,11 +122,7 @@ function (angular, $, kbn, moment, _) {
// Populate element
var options = {
hooks: {
drawSeries: [function() {
console.log('drawSeries', arguments);
}]
},
hooks: { draw: [updateLegendValues] },
legend: { show: false },
series: {
stackpercent: panel.stack ? panel.percentage : false,
......@@ -318,7 +326,9 @@ function (angular, $, kbn, moment, _) {
}
function configureAxisMode(axis, format) {
axis.tickFormatter = kbn.getFormatFunction(format, 1);
axis.tickFormatter = function(val, axis) {
return kbn.formatFunctions[format](val, axis.tickDecimals);
};
}
function time_format(interval, ticks, min, max) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment