@cryptotaxi247 / netdata-1 / commits / 9d2b93708

unit scaling improvements; fixes #3176

Costa Tsaousis (ktsaou) committed Jan 15, 2018 at 00:39 UTC 9d2b93708f224beb4c00821eeeb45e4a9abdd9de
1 file changed +91 -39
web/dashboard.js
+91 -39
@@ -2000,17 +2000,22 @@ var NETDATA = window.NETDATA || {};
2000 'GB': 1024 * 1024
2001 },
2002 'MB': {
2003 + 'B': 1 / (1024 * 1024),
2004 'KB': 1 / 1024,
2005 'MB': 1,
2006 'GB': 1024,
2007 'TB': 1024 * 1024
2008 },
2009 'GB': {
2010 + 'KB': 1 / (1024 * 1024),
2011 'MB': 1 / 1024,
2012 'GB': 1,
2013 'TB': 1024
2012 - }
2014 + },
2015 /*
2016 + 'milliseconds': {
2017 + 'seconds': 1000
2018 + },
2019 'seconds': {
2020 'milliseconds': 0.001,
2021 'seconds': 1,
@@ -2024,59 +2029,106 @@ var NETDATA = window.NETDATA || {};
2029 convertibleUnits: {
2030 'Celsius': {
2031 'Fahrenheit': {
2027 - check: function() { return NETDATA.options.current.temperature === 'fahrenheit'; },
2032 + check: function(max) { void(max); return NETDATA.options.current.temperature === 'fahrenheit'; },
2033 convert: function(value) { return value * 9 / 5 + 32; }
2034 }
2035 },
2036 'celsius': {
2037 'fahrenheit': {
2033 - check: function() { return NETDATA.options.current.temperature === 'fahrenheit'; },
2038 + check: function(max) { void(max); return NETDATA.options.current.temperature === 'fahrenheit'; },
2039 convert: function(value) { return value * 9 / 5 + 32; }
2040 }
2041 },
2042 'seconds': {
2043 'time': {
2039 - check: function () { return NETDATA.options.current.seconds_as_time; },
2040 - convert: function (seconds) {
2041 - seconds = Math.abs(seconds);
2042 -
2043 - var days = Math.floor(seconds / 86400);
2044 - seconds -= days * 86400;
2045 -
2046 - var hours = Math.floor(seconds / 3600);
2047 - seconds -= hours * 3600;
2048 -
2049 - var minutes = Math.floor(seconds / 60);
2050 - seconds -= minutes * 60;
2051 -
2052 - seconds = Math.round(seconds);
2053 -
2054 - var ms_txt = '';
2055 - /*
2056 - var ms = seconds - Math.floor(seconds);
2057 - seconds -= ms;
2058 - ms = Math.round(ms * 1000);
2059 -
2060 - if(ms > 1) {
2061 - if(ms < 10)
2062 - ms_txt = '.00' + ms.toString();
2063 - else if(ms < 100)
2064 - ms_txt = '.0' + ms.toString();
2065 - else
2066 - ms_txt = '.' + ms.toString();
2067 - }
2068 - */
2044 + check: function (max) { void(max); return NETDATA.options.current.seconds_as_time; },
2045 + convert: function(seconds) { return NETDATA.unitsConversion.seconds2time(seconds); }
2046 + }
2047 + },
2048 + 'milliseconds': {
2049 + 'milliseconds': {
2050 + check: function (max) { return NETDATA.options.current.seconds_as_time && max < 1000; },
2051 + convert: function(milliseconds) {
2052 + tms = Math.round(milliseconds * 10);
2053 + milliseconds = Math.floor(tms / 10);
2054 +
2055 + tms -= milliseconds * 10;
2056 +
2057 + return (milliseconds).toString() + '.' + tms.toString();
2058 + }
2059 + },
2060 + 'seconds': {
2061 + check: function (max) { return NETDATA.options.current.seconds_as_time && max > 1000 && max < 60000; },
2062 + convert: function(milliseconds) {
2063 + milliseconds = Math.round(milliseconds);
2064 +
2065 + var seconds = Math.floor(milliseconds / 1000);
2066 + milliseconds -= seconds * 1000;
2067 +
2068 + milliseconds = Math.round(milliseconds / 10);
2069 +
2070 + return seconds.toString() + '.'
2071 + + NETDATA.zeropad(milliseconds);
2072 + }
2073 + },
2074 + 'M:SS.ms': {
2075 + check: function (max) { return NETDATA.options.current.seconds_as_time && max >= 60000; },
2076 + convert: function(milliseconds) {
2077 + milliseconds = Math.round(milliseconds);
2078
2070 - return ((days > 0)?days.toString() + 'd:':'').toString()
2071 - + NETDATA.zeropad(hours) + ':'
2072 - + NETDATA.zeropad(minutes) + ':'
2073 - + NETDATA.zeropad(seconds)
2074 - + ms_txt;
2079 + var minutes = Math.floor(milliseconds / 60000);
2080 + milliseconds -= minutes * 60000;
2081 +
2082 + var seconds = Math.floor(milliseconds / 1000);
2083 + milliseconds -= seconds * 1000;
2084 +
2085 + milliseconds = Math.round(milliseconds / 10);
2086 +
2087 + return minutes.toString() + ':'
2088 + + NETDATA.zeropad(seconds) + '.'
2089 + + NETDATA.zeropad(milliseconds);
2090 }
2091 }
2092 }
2093 },
2094
2095 + seconds2time: function(seconds) {
2096 + seconds = Math.abs(seconds);
2097 +
2098 + var days = Math.floor(seconds / 86400);
2099 + seconds -= days * 86400;
2100 +
2101 + var hours = Math.floor(seconds / 3600);
2102 + seconds -= hours * 3600;
2103 +
2104 + var minutes = Math.floor(seconds / 60);
2105 + seconds -= minutes * 60;
2106 +
2107 + seconds = Math.round(seconds);
2108 +
2109 + var ms_txt = '';
2110 + /*
2111 + var ms = seconds - Math.floor(seconds);
2112 + seconds -= ms;
2113 + ms = Math.round(ms * 1000);
2114 +
2115 + if(ms > 1) {
2116 + if(ms < 10)
2117 + ms_txt = '.00' + ms.toString();
2118 + else if(ms < 100)
2119 + ms_txt = '.0' + ms.toString();
2120 + else
2121 + ms_txt = '.' + ms.toString();
2122 + }
2123 + */
2124 +
2125 + return ((days > 0)?days.toString() + 'd:':'').toString()
2126 + + NETDATA.zeropad(hours) + ':'
2127 + + NETDATA.zeropad(minutes) + ':'
2128 + + NETDATA.zeropad(seconds)
2129 + + ms_txt;
2130 + },
2131 +
2132 // get a function that converts the units
2133 // + every time units are switched call the callback
2134 get: function(uuid, min, max, units, desired_units, common_units_name, switch_units_callback) {
@@ -2223,7 +2275,7 @@ var NETDATA = window.NETDATA || {};
2275 if(desired_units === 'auto') {
2276 for(x in this.convertibleUnits[units]) {
2277 if (this.convertibleUnits[units].hasOwnProperty(x)) {
2226 - if (this.convertibleUnits[units][x].check()) {
2278 + if (this.convertibleUnits[units][x].check(max)) {
2279 //console.log('DEBUG: ' + uuid.toString() + ' converting ' + units.toString() + ' to: ' + x.toString());
2280 switch_units_callback(x);
2281 return this.convertibleUnits[units][x].convert;