Commit eecf74c1 by Rashid Khan

added kbn.byteFormat to format other numbers outside of flot

parent 583b1c66
...@@ -479,5 +479,47 @@ function($, _, moment) { ...@@ -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; return kbn;
}); });
\ No newline at end of file
...@@ -76,14 +76,14 @@ ...@@ -76,14 +76,14 @@
switch (steps) { switch (steps) {
case 0: ext = " B"; break; case 0: ext = " B"; break;
case 1: ext = " KiB"; break; case 1: ext = " KB"; break;
case 2: ext = " MiB"; break; case 2: ext = " MB"; break;
case 3: ext = " GiB"; break; case 3: ext = " GB"; break;
case 4: ext = " TiB"; break; case 4: ext = " TB"; break;
case 5: ext = " PiB"; break; case 5: ext = " PB"; break;
case 6: ext = " EiB"; break; case 6: ext = " EB"; break;
case 7: ext = " ZiB"; break; case 7: ext = " ZB"; break;
case 8: ext = " YiB"; break; case 8: ext = " YB"; break;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment