added kbn.byteFormat to format other numbers outside of flot

This commit is contained in:
Rashid Khan 2013-11-19 14:22:52 -07:00
parent 583b1c66f3
commit eecf74c1fd
2 changed files with 50 additions and 8 deletions

View File

@ -479,5 +479,47 @@ function($, _, moment) {
});
};
kbn.byteFormat = function(size, decimals) {
var ext, steps = 0;
decimals = decimals || 2;
while (Math.abs(size) >= 1024) {
steps++;
size /= 1024;
}
switch (steps) {
case 0:
ext = " B";
break;
case 1:
ext = " KB";
break;
case 2:
ext = " MB";
break;
case 3:
ext = " GB";
break;
case 4:
ext = " TB";
break;
case 5:
ext = " PB";
break;
case 6:
ext = " EB";
break;
case 7:
ext = " ZB";
break;
case 8:
ext = " YB";
break;
}
return (size.toFixed(decimals) + ext);
};
return kbn;
});

View File

@ -76,14 +76,14 @@
switch (steps) {
case 0: ext = " B"; break;
case 1: ext = " KiB"; break;
case 2: ext = " MiB"; break;
case 3: ext = " GiB"; break;
case 4: ext = " TiB"; break;
case 5: ext = " PiB"; break;
case 6: ext = " EiB"; break;
case 7: ext = " ZiB"; break;
case 8: ext = " YiB"; break;
case 1: ext = " KB"; break;
case 2: ext = " MB"; break;
case 3: ext = " GB"; break;
case 4: ext = " TB"; break;
case 5: ext = " PB"; break;
case 6: ext = " EB"; break;
case 7: ext = " ZB"; break;
case 8: ext = " YB"; break;
}