summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJochen Topf <jochen@topf.org>2013-01-17 11:28:49 +0100
committerJochen Topf <jochen@topf.org>2013-01-17 11:28:49 +0100
commita759c7680dfb41b366fb1bad8efc2a19c1ff82f6 (patch)
tree24caeb6c5a4c8f46436fc9cbf1f09e47f0304ee7
parent809c94f3623c8b56dfaa5ee40d094615621f9ecb (diff)
downloadtaginfo-a759c7680dfb41b366fb1bad8efc2a19c1ff82f6.tar
taginfo-a759c7680dfb41b366fb1bad8efc2a19c1ff82f6.tar.gz
More fmt function cleanups
-rw-r--r--web/public/js/taginfo.js21
-rw-r--r--web/viewsjs/key.js.erb2
-rw-r--r--web/viewsjs/keys.js.erb8
-rw-r--r--web/viewsjs/relations.js.erb4
-rw-r--r--web/viewsjs/reports/characters_in_keys.js.erb16
-rw-r--r--web/viewsjs/reports/frequently_used_keys_without_wiki_page.js.erb6
-rw-r--r--web/viewsjs/reports/key_lengths.js.erb6
-rw-r--r--web/viewsjs/reports/name_tags.js.erb4
-rw-r--r--web/viewsjs/reports/wiki_pages_about_non_existing_keys.js.erb4
-rw-r--r--web/viewsjs/search.js.erb6
10 files changed, 38 insertions, 39 deletions
diff --git a/web/public/js/taginfo.js b/web/public/js/taginfo.js
index 3a22bc9..2fb8e5a 100644
--- a/web/public/js/taginfo.js
+++ b/web/public/js/taginfo.js
@@ -5,11 +5,6 @@ String.prototype.capitalize = function() {
return this.substr(0, 1).toUpperCase() + this.substr(1);
}
-// print a number as percent value with two digits after the decimal point
-Number.prototype.print_as_percent = function() {
- return (this * 100).toFixed(2) + '%';
-};
-
/* ============================ */
var grids = {},
@@ -358,8 +353,8 @@ function fmt_image(type) {
});
}
-// print a number with thousand separator
-function print_with_ts(value) {
+// format a number with thousand separator
+function fmt_with_ts(value) {
if (value === null) {
return '-';
} else {
@@ -367,7 +362,11 @@ function print_with_ts(value) {
}
}
-function print_checkmark(value) {
+function fmt_as_percent(value) {
+ return (value * 100).toFixed(2) + '%';
+}
+
+function fmt_checkmark(value) {
return value ? '&#x2714;' : '-';
}
@@ -389,7 +388,7 @@ function print_prevalent_value_list(key, list) {
return empty(texts.misc.values_less_than_one_percent);
}
return jQuery.map(list, function(item, i) {
- return link_to_value(key, item.value, { tipsy: 'e', title: '(' + item.fraction.print_as_percent() + ')' });
+ return link_to_value(key, item.value, { tipsy: 'e', title: '(' + fmt_as_percent(item.fraction) + ')' });
}).join(' &bull; ');
}
@@ -398,8 +397,8 @@ function html_escape(text) {
}
function print_value_with_percent(value, fraction) {
- return '<div class="value">' + print_with_ts(value) +
- '</div><div class="fraction">' + fraction.print_as_percent() +
+ return '<div class="value">' + fmt_with_ts(value) +
+ '</div><div class="fraction">' + fmt_as_percent(fraction) +
'</div><div class="bar" style="width: ' + (fraction*100).toFixed() + 'px;"></div>';
}
diff --git a/web/viewsjs/key.js.erb b/web/viewsjs/key.js.erb
index fc433cc..2f5c81c 100644
--- a/web/viewsjs/key.js.erb
+++ b/web/viewsjs/key.js.erb
@@ -22,7 +22,7 @@ var create_flexigrid_for = {
return { 'cell': [
fmt_image(row.type) + ' ' + texts.osm[row.type],
print_value_with_percent(row.count, row.count_fraction),
- print_with_ts(row.values)
+ fmt_with_ts(row.values)
]};
})
};
diff --git a/web/viewsjs/keys.js.erb b/web/viewsjs/keys.js.erb
index 2facbd1..503a39f 100644
--- a/web/viewsjs/keys.js.erb
+++ b/web/viewsjs/keys.js.erb
@@ -30,10 +30,10 @@ function page_init() {
print_value_with_percent(row.count_nodes, row.count_nodes_fraction),
print_value_with_percent(row.count_ways, row.count_ways_fraction),
print_value_with_percent(row.count_relations, row.count_relations_fraction),
- print_with_ts(row.users_all),
- print_checkmark(row.in_wiki),
- print_checkmark(row.in_josm),
- print_with_ts(row.values_all),
+ fmt_with_ts(row.users_all),
+ fmt_checkmark(row.in_wiki),
+ fmt_checkmark(row.in_josm),
+ fmt_with_ts(row.values_all),
print_prevalent_value_list(row.key, row.prevalent_values)
] };
});
diff --git a/web/viewsjs/relations.js.erb b/web/viewsjs/relations.js.erb
index 147d590..36906ca 100644
--- a/web/viewsjs/relations.js.erb
+++ b/web/viewsjs/relations.js.erb
@@ -39,9 +39,9 @@ function print_prevalent_role_list(list) {
}
return jQuery.map(list, function(item, i) {
if (item.role) {
- return tag('span', item.role, { tipsy: 'e', title: html_escape(item.role) + ' (' + item.fraction.print_as_percent() + ')' });
+ return tag('span', item.role, { tipsy: 'e', title: html_escape(item.role) + ' (' + fmt_as_percent(item.fraction) + ')' });
} else {
- return tag('span', empty('<%= page.empty_role %>'), { tipsy: 'e', title: '(' + item.fraction.print_as_percent() + ')' });
+ return tag('span', empty('<%= page.empty_role %>'), { tipsy: 'e', title: '(' + fmt_as_percent(item.fraction) + ')' });
}
}).join(' &bull; ');
}
diff --git a/web/viewsjs/reports/characters_in_keys.js.erb b/web/viewsjs/reports/characters_in_keys.js.erb
index 900b155..21fcb3a 100644
--- a/web/viewsjs/reports/characters_in_keys.js.erb
+++ b/web/viewsjs/reports/characters_in_keys.js.erb
@@ -25,10 +25,10 @@ var create_flexigrid_for = {
return { 'cell': [
link_to_key(row.key),
print_value_with_percent(row.count_all, row.count_all_fraction),
- print_with_ts(row.users_all),
- print_checkmark(row.in_wiki),
- print_checkmark(row.in_josm),
- print_with_ts(row.values_all),
+ fmt_with_ts(row.users_all),
+ fmt_checkmark(row.in_wiki),
+ fmt_checkmark(row.in_josm),
+ fmt_with_ts(row.values_all),
print_prevalent_value_list(row.key, row.prevalent_values)
] };
});
@@ -58,10 +58,10 @@ var create_flexigrid_for = {
return { 'cell': [
link_to_key(row.key),
print_value_with_percent(row.count_all, row.count_all_fraction),
- print_with_ts(row.users_all),
- print_checkmark(row.in_wiki),
- print_checkmark(row.in_josm),
- print_with_ts(row.values_all),
+ fmt_with_ts(row.users_all),
+ fmt_checkmark(row.in_wiki),
+ fmt_checkmark(row.in_josm),
+ fmt_with_ts(row.values_all),
print_prevalent_value_list(row.key, row.prevalent_values)
] };
});
diff --git a/web/viewsjs/reports/frequently_used_keys_without_wiki_page.js.erb b/web/viewsjs/reports/frequently_used_keys_without_wiki_page.js.erb
index 0eac359..7819a17 100644
--- a/web/viewsjs/reports/frequently_used_keys_without_wiki_page.js.erb
+++ b/web/viewsjs/reports/frequently_used_keys_without_wiki_page.js.erb
@@ -24,9 +24,9 @@ function create_flexigrid_with_option(english) {
return { 'cell': [
link_to_wiki('Key:' + row.key, { edit: true }),
link_to_key(row.key),
- print_with_ts(row.count_all),
- print_with_ts(row.users_all),
- print_with_ts(row.values_all),
+ fmt_with_ts(row.count_all),
+ fmt_with_ts(row.users_all),
+ fmt_with_ts(row.values_all),
print_prevalent_value_list(row.key, row.prevalent_values)
] };
});
diff --git a/web/viewsjs/reports/key_lengths.js.erb b/web/viewsjs/reports/key_lengths.js.erb
index af13615..908405c 100644
--- a/web/viewsjs/reports/key_lengths.js.erb
+++ b/web/viewsjs/reports/key_lengths.js.erb
@@ -27,9 +27,9 @@ var create_flexigrid_for = {
row.key.length,
link_to_key(row.key),
print_value_with_percent(row.count_all, row.count_all_fraction),
- print_checkmark(row.in_wiki),
- print_checkmark(row.in_josm),
- print_with_ts(row.values_all),
+ fmt_checkmark(row.in_wiki),
+ fmt_checkmark(row.in_josm),
+ fmt_with_ts(row.values_all),
print_prevalent_value_list(row.key, row.prevalent_values)
] };
});
diff --git a/web/viewsjs/reports/name_tags.js.erb b/web/viewsjs/reports/name_tags.js.erb
index 62b953e..bd672ed 100644
--- a/web/viewsjs/reports/name_tags.js.erb
+++ b/web/viewsjs/reports/name_tags.js.erb
@@ -31,8 +31,8 @@ var create_flexigrid_for = {
data.rows = jQuery.map(data.data, function(row, i) {
return { 'cell': [
link_to_key(row.key),
- print_with_ts(row.count_all),
- print_checkmark(row.in_wiki),
+ fmt_with_ts(row.count_all),
+ fmt_checkmark(row.in_wiki),
row.prefix,
row.type,
row.langtag,
diff --git a/web/viewsjs/reports/wiki_pages_about_non_existing_keys.js.erb b/web/viewsjs/reports/wiki_pages_about_non_existing_keys.js.erb
index 69330e7..fa8023c 100644
--- a/web/viewsjs/reports/wiki_pages_about_non_existing_keys.js.erb
+++ b/web/viewsjs/reports/wiki_pages_about_non_existing_keys.js.erb
@@ -28,8 +28,8 @@ function page_init() {
wikilinks.push(w);
});
return { 'cell': [
- print_checkmark(row.in_wiki),
- print_checkmark(row.in_josm),
+ fmt_checkmark(row.in_wiki),
+ fmt_checkmark(row.in_josm),
link_to_key(row.key),
wikilinks.join(' &nbsp;&bull;&nbsp; ')
] };
diff --git a/web/viewsjs/search.js.erb b/web/viewsjs/search.js.erb
index aa717b5..5ce7e72 100644
--- a/web/viewsjs/search.js.erb
+++ b/web/viewsjs/search.js.erb
@@ -30,7 +30,7 @@ var create_flexigrid_for = {
preProcess: function(data) {
data.rows = jQuery.map(data.data, function(row, i) {
return { 'cell': [
- print_with_ts(row.count_all),
+ fmt_with_ts(row.count_all),
link_to_key_with_highlight(row.key, query)
] };
});
@@ -51,7 +51,7 @@ var create_flexigrid_for = {
preProcess: function(data) {
data.rows = jQuery.map(data.data, function(row, i) {
return { 'cell': [
- print_with_ts(row.count_all),
+ fmt_with_ts(row.count_all),
link_to_key(row.key),
link_to_value_with_highlight(row.key, row.value, query)
] };
@@ -74,7 +74,7 @@ var create_flexigrid_for = {
preProcess: function(data) {
data.rows = jQuery.map(data.data, function(row, i) {
return { 'cell': [
- print_with_ts(row.count_all),
+ fmt_with_ts(row.count_all),
link_to_key_with_highlight(row.key, q[0]),
link_to_value_with_highlight(row.key, row.value, q[1])
] };