diff options
author | Jelle van der Waa <jelle@vdwaa.nl> | 2018-08-11 19:40:06 +0200 |
---|---|---|
committer | Jelle van der Waa <jelle@vdwaa.nl> | 2018-11-18 22:49:25 +0100 |
commit | 6451de66862b843742d1c712a150ea8aa49aec0d (patch) | |
tree | 1fc77a7db085336f8be3bf4dcc2cc2928ca379f5 /visualize | |
parent | afff4eea77a64f53a9bd1138b2724a431a0ea457 (diff) | |
download | archweb-6451de66862b843742d1c712a150ea8aa49aec0d.tar.gz archweb-6451de66862b843742d1c712a150ea8aa49aec0d.zip |
Move format_filesize to the visualize.js
The only user of format_filesize is visualize.js, move the code there to
reduce archewb.js which is loaded on multiple pages.
Diffstat (limited to 'visualize')
-rw-r--r-- | visualize/static/visualize.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/visualize/static/visualize.js b/visualize/static/visualize.js index 5254c26b..47d75f6e 100644 --- a/visualize/static/visualize.js +++ b/visualize/static/visualize.js @@ -1,3 +1,19 @@ +function format_filesize(size, decimals) { + /*var labels = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];*/ + var labels = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], + label = 0; + + while (size > 2048.0 && label < labels.length - 1) { + label++; + size /= 1024.0; + } + if (decimals === undefined) { + decimals = 2; + } + + return size.toFixed(decimals) + ' ' + labels[label]; +} + function packages_treemap(chart_id, orderings, default_order) { var jq_div = jQuery(chart_id), color = d3.scale.category20(); |