rrd charts: render 3 decimal points for small values

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2020-05-29 19:15:08 +02:00
parent 9f1b3a70cb
commit c58d410099

View File

@ -10,6 +10,8 @@ Ext.define('Proxmox.widget.RRDChart', {
convertToUnits: function(value) { convertToUnits: function(value) {
var units = ['', 'k','M','G','T', 'P']; var units = ['', 'k','M','G','T', 'P'];
var si = 0; var si = 0;
let format = '0.##';
if (value < 0.1) format += '#';
while(value >= 1000 && si < (units.length -1)){ while(value >= 1000 && si < (units.length -1)){
value = value / 1000; value = value / 1000;
si++; si++;
@ -18,15 +20,14 @@ Ext.define('Proxmox.widget.RRDChart', {
// javascript floating point weirdness // javascript floating point weirdness
value = Ext.Number.correctFloat(value); value = Ext.Number.correctFloat(value);
// limit to 2 decimal points // limit decimal points
value = Ext.util.Format.number(value, "0.##"); value = Ext.util.Format.number(value, format);
return value.toString() + " " + units[si]; return value.toString() + " " + units[si];
}, },
leftAxisRenderer: function(axis, label, layoutContext) { leftAxisRenderer: function(axis, label, layoutContext) {
var me = this; var me = this;
return me.convertToUnits(label); return me.convertToUnits(label);
}, },