summaryrefslogtreecommitdiff
path: root/media/archweb.js
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-10-27 12:06:47 -0500
committerDan McGee <dan@archlinux.org>2011-10-27 12:06:47 -0500
commitf5c7b419cdda049ea8d9bfb0137fb53296ceef55 (patch)
treeb687e909b292394d0b35dbd49f25332607c8b96c /media/archweb.js
parent2c8b7ad07b63a3048089be78c26c1574f15dd582 (diff)
Prettify filesizes in package visualization chart
Add a general purpose formatter and mark up each value function with an 'is_size' attribute so we can add additional display formatting if asked for. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'media/archweb.js')
-rw-r--r--media/archweb.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/media/archweb.js b/media/archweb.js
index 2414331d..a51ae460 100644
--- a/media/archweb.js
+++ b/media/archweb.js
@@ -232,3 +232,20 @@ function signoff_package() {
});
return false;
}
+
+/* visualizations */
+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'];
+ var 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];
+}