summaryrefslogtreecommitdiff
path: root/media/visualize.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/visualize.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/visualize.js')
-rw-r--r--media/visualize.js22
1 files changed, 17 insertions, 5 deletions
diff --git a/media/visualize.js b/media/visualize.js
index c47033ab..d9196d4d 100644
--- a/media/visualize.js
+++ b/media/visualize.js
@@ -2,7 +2,14 @@ function packages_treemap(chart_id, orderings, default_order) {
var jq_div = $(chart_id),
color = d3.scale.category20();
var key_func = function(d) { return d.key; };
- var value_package_count = function(d) { return d.count; };
+ var value_package_count = function(d) { return d.count; },
+ value_flagged_count = function(d) { return d.flagged; },
+ value_compressed_size = function(d) { return d.csize; },
+ value_installed_size = function(d) { return d.isize; };
+
+ /* tag the function so when we display, we can format filesizes */
+ value_package_count.is_size = value_flagged_count.is_size = false;
+ value_compressed_size.is_size = value_installed_size.is_size = true;
var treemap = d3.layout.treemap()
.size([jq_div.width(), jq_div.height()])
@@ -15,7 +22,12 @@ function packages_treemap(chart_id, orderings, default_order) {
if (d.children) {
return "";
}
- return "<span>" + d.name + ": " + treemap.value()(d) + "</span>";
+ var valuefunc = treemap.value();
+ var value = valuefunc(d);
+ if (valuefunc.is_size && value !== undefined) {
+ value = format_filesize(value);
+ }
+ return "<span>" + d.name + ": " + value + "</span>";
};
var d3_div = d3.select(jq_div.get(0));
@@ -81,9 +93,9 @@ function packages_treemap(chart_id, orderings, default_order) {
/* each scale button tweaks our value, e.g. net size function */
make_scale_button("count", value_package_count);
- make_scale_button("flagged", function(d) { return d.flagged; });
- make_scale_button("csize", function(d) { return d.csize; });
- make_scale_button("isize", function(d) { return d.isize; });
+ make_scale_button("flagged", value_flagged_count);
+ make_scale_button("csize", value_compressed_size);
+ make_scale_button("isize", value_installed_size);
var make_group_button = function(name, order) {
var button_id = chart_id + "-" + name;