format seconds as Dd:HH:MM:SS; #2745
Costa Tsaousis (ktsaou) committed
Oct 8, 2017 at 13:03 UTC
6cdad758896e3d149f1a6f41733e0223bf3ccefe
1 file changed
+74
-25
web/dashboard.js
+74
-25
@@ -1509,7 +1509,8 @@ var NETDATA = window.NETDATA || {};
1509
'MB': 1 / 1024,
1510
'GB': 1,
1511
'TB': 1024
1512
- },
1512
+ }
1513
+ /*
1514
'seconds': {
1515
'milliseconds': 0.001,
1516
'seconds': 1,
@@ -1517,6 +1518,7 @@ var NETDATA = window.NETDATA || {};
1518
'hours': 3600,
1519
'days': 86400
1520
}
1521
+ */
1522
},
1523
1524
convertibleUnits: {
@@ -1531,6 +1533,47 @@ var NETDATA = window.NETDATA || {};
1533
check: function() { return NETDATA.options.current.temperature === 'fahrenheit'; },
1534
convert: function(value) { return value * 9 / 5 + 32; }
1535
}
1536
+ },
1537
+ 'seconds': {
1538
+ 'time': {
1539
+ check: function () { return NETDATA.options.current.units === 'auto'; },
1540
+ convert: function (seconds) {
1541
+ seconds = Math.abs(seconds);
1542
+
1543
+ var days = Math.floor(seconds / 86400);
1544
+ seconds -= days * 86400;
1545
+
1546
+ var hours = Math.floor(seconds / 3600);
1547
+ seconds -= hours * 3600;
1548
+
1549
+ var minutes = Math.floor(seconds / 60);
1550
+ seconds -= minutes * 60;
1551
+
1552
+ seconds = Math.round(seconds);
1553
+
1554
+ var ms_txt = '';
1555
+ /*
1556
+ var ms = seconds - Math.floor(seconds);
1557
+ seconds -= ms;
1558
+ ms = Math.round(ms * 1000);
1559
+
1560
+ if(ms > 1) {
1561
+ if(ms < 10)
1562
+ ms_txt = '.00' + ms.toString();
1563
+ else if(ms < 100)
1564
+ ms_txt = '.0' + ms.toString();
1565
+ else
1566
+ ms_txt = '.' + ms.toString();
1567
+ }
1568
+ */
1569
+
1570
+ return ((days > 0)?days.toString() + 'd:':'').toString()
1571
+ + NETDATA.zeropad(hours) + ':'
1572
+ + NETDATA.zeropad(minutes) + ':'
1573
+ + NETDATA.zeropad(seconds)
1574
+ + ms_txt;
1575
+ }
1576
+ }
1577
}
1578
},
1579
@@ -1542,7 +1585,7 @@ var NETDATA = window.NETDATA || {};
1585
units = 'undefined';
1586
1587
// check if we support units conversion
1545
- if(typeof NETDATA.unitsConversion.scalableUnits[units] === 'undefined' && typeof NETDATA.unitsConversion.convertibleUnits[units] === 'undefined') {
1588
+ if(typeof this.scalableUnits[units] === 'undefined' && typeof this.convertibleUnits[units] === 'undefined') {
1589
// we can't convert these units
1590
//console.log('DEBUG: ' + uuid.toString() + ' can\'t convert units: ' + units.toString());
1591
return function(value) { return value; };
@@ -1562,11 +1605,11 @@ var NETDATA = window.NETDATA || {};
1605
var tdivider = 0;
1606
var x;
1607
1565
- if(typeof NETDATA.unitsConversion.scalableUnits[units] !== 'undefined') {
1608
+ if(typeof this.scalableUnits[units] !== 'undefined') {
1609
// units that can be scaled
1610
// we decide a divider
1611
1569
- // console.log('NETDATA.unitsConversion(' + units.toString() + ', ' + desired_units.toString() + ', function()) decide divider with min = ' + min.toString() + ', max = ' + max.toString());
1612
+ // console.log('NETDATA.unitsConversion.get(' + units.toString() + ', ' + desired_units.toString() + ', function()) decide divider with min = ' + min.toString() + ', max = ' + max.toString());
1613
1614
if (desired_units === 'auto') {
1615
// the caller wants to auto-scale the units
@@ -1578,14 +1621,13 @@ var NETDATA = window.NETDATA || {};
1621
if (min > max) max = min;
1622
1623
// find the smallest scale that provides integers
1581
- for (x in NETDATA.unitsConversion.scalableUnits[units]) {
1582
- if (!NETDATA.unitsConversion.scalableUnits[units].hasOwnProperty(x)) continue;
1583
-
1584
- var m = NETDATA.unitsConversion.scalableUnits[units][x];
1585
-
1586
- if (m <= max && m > tdivider) {
1587
- tunits = x;
1588
- tdivider = m;
1624
+ for (x in this.scalableUnits[units]) {
1625
+ if (this.scalableUnits[units].hasOwnProperty(x)) {
1626
+ var m = this.scalableUnits[units][x];
1627
+ if (m <= max && m > tdivider) {
1628
+ tunits = x;
1629
+ tdivider = m;
1630
+ }
1631
}
1632
}
1633
@@ -1619,10 +1661,10 @@ var NETDATA = window.NETDATA || {};
1661
}
1662
1663
// save our common_max to the latest keys
1622
- var latest = NETDATA.unitsConversion.latest[common_units_name];
1664
+ var latest = this.latest[common_units_name];
1665
if(typeof latest === 'undefined') {
1624
- NETDATA.unitsConversion.latest[common_units_name] = {};
1625
- latest = NETDATA.unitsConversion.latest[common_units_name];
1666
+ this.latest[common_units_name] = {};
1667
+ latest = this.latest[common_units_name];
1668
}
1669
latest.units = common_units.units;
1670
latest.divider = common_units.divider;
@@ -1659,9 +1701,9 @@ var NETDATA = window.NETDATA || {};
1701
else {
1702
// the caller wants specific units
1703
1662
- if(typeof NETDATA.unitsConversion.scalableUnits[units][desired_units] !== 'undefined') {
1704
+ if(typeof this.scalableUnits[units][desired_units] !== 'undefined') {
1705
// all good, set the new units
1664
- tdivider = NETDATA.unitsConversion.scalableUnits[units][desired_units];
1706
+ tdivider = this.scalableUnits[units][desired_units];
1707
// console.log('DEBUG: ' + uuid.toString() + ' converted units: ' + units.toString() + ' to units: ' + desired_units.toString() + ' with divider ' + tdivider.toString() + ', by reference');
1708
switch_units_callback(desired_units);
1709
return function (value) { return value / tdivider; };
@@ -1674,15 +1716,15 @@ var NETDATA = window.NETDATA || {};
1716
}
1717
}
1718
}
1677
- else if(typeof NETDATA.unitsConversion.convertibleUnits[units] !== 'undefined') {
1719
+ else if(typeof this.convertibleUnits[units] !== 'undefined') {
1720
// units that can be converted
1721
if(desired_units === 'auto') {
1680
- for(x in NETDATA.unitsConversion.convertibleUnits[units]) {
1681
- if (NETDATA.unitsConversion.convertibleUnits[units].hasOwnProperty(x)) {
1682
- if (NETDATA.unitsConversion.convertibleUnits[units][x].check()) {
1722
+ for(x in this.convertibleUnits[units]) {
1723
+ if (this.convertibleUnits[units].hasOwnProperty(x)) {
1724
+ if (this.convertibleUnits[units][x].check()) {
1725
//console.log('DEBUG: ' + uuid.toString() + ' converting ' + units.toString() + ' to: ' + x.toString());
1726
switch_units_callback(x);
1685
- return NETDATA.unitsConversion.convertibleUnits[units][x].convert;
1727
+ return this.convertibleUnits[units][x].convert;
1728
}
1729
}
1730
}
@@ -1692,9 +1734,9 @@ var NETDATA = window.NETDATA || {};
1734
switch_units_callback(units);
1735
return function (value) { return value; };
1736
}
1695
- else if(typeof NETDATA.unitsConversion.convertibleUnits[units][desired_units] !== 'undefined') {
1737
+ else if(typeof this.convertibleUnits[units][desired_units] !== 'undefined') {
1738
switch_units_callback(desired_units);
1697
- return NETDATA.unitsConversion.convertibleUnits[units][desired_units].convert;
1739
+ return this.convertibleUnits[units][desired_units].convert;
1740
}
1741
else {
1742
console.log('Units conversion from ' + units.toString() + ' to ' + desired_units.toString() + ' is not supported.');
@@ -2812,6 +2854,9 @@ var NETDATA = window.NETDATA || {};
2854
if(__unitsConversion !== null) {
2855
min = __unitsConversion(min);
2856
max = __unitsConversion(max);
2857
+
2858
+ if(typeof min !== 'number' || typeof max !== 'number')
2859
+ return;
2860
}
2861
2862
__legendFormatValueChartDecimalsLastMin = min;
@@ -2858,10 +2903,14 @@ var NETDATA = window.NETDATA || {};
2903
};
2904
2905
this.legendFormatValue = function(value) {
2861
- if(typeof value !== 'number') return '-';
2906
+ if(typeof value !== 'number')
2907
+ return '-';
2908
2909
value = __unitsConversion(value);
2910
2911
+ if(typeof value !== 'number')
2912
+ return value;
2913
+
2914
if(__intlNumberFormat !== null)
2915
return __intlNumberFormat.format(value);
2916