From f5c7b419cdda049ea8d9bfb0137fb53296ceef55 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 27 Oct 2011 12:06:47 -0500 Subject: 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 --- media/archweb.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'media/archweb.js') diff --git a/media/archweb.js b/media/archweb.js index 2414331..a51ae46 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]; +} -- cgit v1.2.3-24-g4f1b