mirror of
https://git.proxmox.com/git/proxmox-widget-toolkit
synced 2025-05-29 17:16:11 +00:00
rrd chart: add option to render values as power of two base
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
c3b900f958
commit
4337ad5b74
@ -4,16 +4,23 @@ Ext.define('Proxmox.widget.RRDChart', {
|
|||||||
|
|
||||||
unit: undefined, // bytes, bytespersecond, percent
|
unit: undefined, // bytes, bytespersecond, percent
|
||||||
|
|
||||||
|
powerOfTwo: false,
|
||||||
|
|
||||||
controller: {
|
controller: {
|
||||||
xclass: 'Ext.app.ViewController',
|
xclass: 'Ext.app.ViewController',
|
||||||
|
|
||||||
|
init: function(view) {
|
||||||
|
this.powerOfTwo = view.powerOfTwo;
|
||||||
|
},
|
||||||
|
|
||||||
convertToUnits: function(value) {
|
convertToUnits: function(value) {
|
||||||
let units = ['', 'k', 'M', 'G', 'T', 'P'];
|
let units = ['', 'k', 'M', 'G', 'T', 'P'];
|
||||||
let si = 0;
|
let si = 0;
|
||||||
let format = '0.##';
|
let format = '0.##';
|
||||||
if (value < 0.1) format += '#';
|
if (value < 0.1) format += '#';
|
||||||
while (value >= 1000 && si < units.length -1) {
|
const baseValue = this.powerOfTwo ? 1024 : 1000;
|
||||||
value = value / 1000;
|
while (value >= baseValue && si < units.length -1) {
|
||||||
|
value = value / baseValue;
|
||||||
si++;
|
si++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,7 +30,10 @@ Ext.define('Proxmox.widget.RRDChart', {
|
|||||||
// limit decimal points
|
// limit decimal points
|
||||||
value = Ext.util.Format.number(value, format);
|
value = Ext.util.Format.number(value, format);
|
||||||
|
|
||||||
return value.toString() + " " + units[si];
|
let unit = units[si];
|
||||||
|
if (this.powerOfTwo) unit += 'i';
|
||||||
|
|
||||||
|
return `${value.toString()} ${unit}`;
|
||||||
},
|
},
|
||||||
|
|
||||||
leftAxisRenderer: function(axis, label, layoutContext) {
|
leftAxisRenderer: function(axis, label, layoutContext) {
|
||||||
|
Loading…
Reference in New Issue
Block a user