From 4337ad5b7457939ced4aceee64ffc3b6c1505ee3 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Thu, 15 Apr 2021 19:02:33 +0200 Subject: [PATCH] rrd chart: add option to render values as power of two base Signed-off-by: Thomas Lamprecht --- src/panel/RRDChart.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/panel/RRDChart.js b/src/panel/RRDChart.js index b4f89a4..3cea635 100644 --- a/src/panel/RRDChart.js +++ b/src/panel/RRDChart.js @@ -4,16 +4,23 @@ Ext.define('Proxmox.widget.RRDChart', { unit: undefined, // bytes, bytespersecond, percent + powerOfTwo: false, + controller: { xclass: 'Ext.app.ViewController', + init: function(view) { + this.powerOfTwo = view.powerOfTwo; + }, + convertToUnits: function(value) { let units = ['', 'k', 'M', 'G', 'T', 'P']; let si = 0; let format = '0.##'; if (value < 0.1) format += '#'; - while (value >= 1000 && si < units.length -1) { - value = value / 1000; + const baseValue = this.powerOfTwo ? 1024 : 1000; + while (value >= baseValue && si < units.length -1) { + value = value / baseValue; si++; } @@ -23,7 +30,10 @@ Ext.define('Proxmox.widget.RRDChart', { // limit decimal points 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) { -- 2.39.5