diff options
author | Jochen Topf <jochen@topf.org> | 2013-01-17 11:36:37 +0100 |
---|---|---|
committer | Jochen Topf <jochen@topf.org> | 2013-01-17 11:36:37 +0100 |
commit | 5e05d84eef8b07958dbc9a0dfc8cbba10f8d3a4b (patch) | |
tree | be924c3769ba4f57a3c34b97e394744075670c66 | |
parent | a759c7680dfb41b366fb1bad8efc2a19c1ff82f6 (diff) | |
download | taginfo-5e05d84eef8b07958dbc9a0dfc8cbba10f8d3a4b.tar taginfo-5e05d84eef8b07958dbc9a0dfc8cbba10f8d3a4b.tar.gz |
Cleanup js function print_value_with_percent
-rw-r--r-- | web/public/js/taginfo.js | 20 | ||||
-rw-r--r-- | web/viewsjs/key.js.erb | 8 | ||||
-rw-r--r-- | web/viewsjs/keys.js.erb | 8 | ||||
-rw-r--r-- | web/viewsjs/relation.js.erb | 8 | ||||
-rw-r--r-- | web/viewsjs/relations.js.erb | 2 | ||||
-rw-r--r-- | web/viewsjs/reports/characters_in_keys.js.erb | 4 | ||||
-rw-r--r-- | web/viewsjs/reports/key_lengths.js.erb | 2 | ||||
-rw-r--r-- | web/viewsjs/reports/languages.js.erb | 4 | ||||
-rw-r--r-- | web/viewsjs/tag.js.erb | 6 | ||||
-rw-r--r-- | web/viewsjs/tags.js.erb | 8 |
10 files changed, 35 insertions, 35 deletions
diff --git a/web/public/js/taginfo.js b/web/public/js/taginfo.js index 2fb8e5a..61fc206 100644 --- a/web/public/js/taginfo.js +++ b/web/public/js/taginfo.js @@ -211,6 +211,10 @@ function link_to_wiki(title, options) { /* ============================ */ +function html_escape(text) { + return String(text).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, '''); +} + function tag(element, text, attrs) { var attributes = ''; if (attrs !== undefined) { @@ -370,6 +374,12 @@ function fmt_checkmark(value) { return value ? '✔' : '-'; } +function fmt_value_with_percent(value, fraction) { + return tag('div', fmt_with_ts(value), { 'class': 'value' }) + + tag('div', fmt_as_percent(fraction), { 'class': 'fraction' }) + + tag('div', '', { 'class': 'bar', style: style({ width: (fraction*100).toFixed() + 'px' }) }); +} + /* ============================ */ function print_key_or_tag_list(list) { @@ -392,16 +402,6 @@ function print_prevalent_value_list(key, list) { }).join(' • '); } -function html_escape(text) { - return String(text).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, '''); -} - -function print_value_with_percent(value, fraction) { - 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>'; -} - /* ============================ */ var flexigrid_defaults = { diff --git a/web/viewsjs/key.js.erb b/web/viewsjs/key.js.erb index 2f5c81c..a251669 100644 --- a/web/viewsjs/key.js.erb +++ b/web/viewsjs/key.js.erb @@ -21,7 +21,7 @@ var create_flexigrid_for = { rows: jQuery.map(data.data, function(row, i) { return { 'cell': [ fmt_image(row.type) + ' ' + texts.osm[row.type], - print_value_with_percent(row.count, row.count_fraction), + fmt_value_with_percent(row.count, row.count_fraction), fmt_with_ts(row.values) ]}; }) @@ -46,7 +46,7 @@ var create_flexigrid_for = { data.rows = jQuery.map(data.data, function(row, i) { return { 'cell': [ hover_expand(link_to_value(key, row.value)), - print_value_with_percent(row.count, row.fraction), + fmt_value_with_percent(row.count, row.fraction), row.description ] }; }); @@ -71,9 +71,9 @@ var create_flexigrid_for = { preProcess: function(data) { data.rows = jQuery.map(data.data, function(row, i) { return { 'cell': [ - print_value_with_percent(row.together_count, row.to_fraction), + fmt_value_with_percent(row.together_count, row.to_fraction), link_to_key(row.other_key), - print_value_with_percent(row.together_count, row.from_fraction), + fmt_value_with_percent(row.together_count, row.from_fraction), ] }; }); return data; diff --git a/web/viewsjs/keys.js.erb b/web/viewsjs/keys.js.erb index 503a39f..0cecb9e 100644 --- a/web/viewsjs/keys.js.erb +++ b/web/viewsjs/keys.js.erb @@ -26,10 +26,10 @@ function page_init() { data.rows = jQuery.map(data.data, function(row, i) { return { 'cell': [ link_to_key(row.key), - print_value_with_percent(row.count_all, row.count_all_fraction), - 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), + fmt_value_with_percent(row.count_all, row.count_all_fraction), + fmt_value_with_percent(row.count_nodes, row.count_nodes_fraction), + fmt_value_with_percent(row.count_ways, row.count_ways_fraction), + fmt_value_with_percent(row.count_relations, row.count_relations_fraction), fmt_with_ts(row.users_all), fmt_checkmark(row.in_wiki), fmt_checkmark(row.in_josm), diff --git a/web/viewsjs/relation.js.erb b/web/viewsjs/relation.js.erb index 3682da1..26b83fa 100644 --- a/web/viewsjs/relation.js.erb +++ b/web/viewsjs/relation.js.erb @@ -22,10 +22,10 @@ var create_flexigrid_for = { data.rows = jQuery.map(data.data, function(row, i) { return { 'cell': [ fmt_role(row.role), - print_value_with_percent(row.count_all_members, row.count_all_members_fraction), - print_value_with_percent(row.count_node_members, row.count_node_members_fraction), - print_value_with_percent(row.count_way_members, row.count_way_members_fraction), - print_value_with_percent(row.count_relation_members, row.count_relation_members_fraction) + fmt_value_with_percent(row.count_all_members, row.count_all_members_fraction), + fmt_value_with_percent(row.count_node_members, row.count_node_members_fraction), + fmt_value_with_percent(row.count_way_members, row.count_way_members_fraction), + fmt_value_with_percent(row.count_relation_members, row.count_relation_members_fraction) ] }; }); return data; diff --git a/web/viewsjs/relations.js.erb b/web/viewsjs/relations.js.erb index 36906ca..52fef33 100644 --- a/web/viewsjs/relations.js.erb +++ b/web/viewsjs/relations.js.erb @@ -20,7 +20,7 @@ function page_init() { data.rows = jQuery.map(data.data, function(row, i) { return { 'cell': [ link_to_rtype(row.relation_type), - print_value_with_percent(row.count, row.count_fraction), + fmt_value_with_percent(row.count, row.count_fraction), link_to_tag('type', row.relation_type), print_prevalent_role_list(row.prevalent_roles) ] }; diff --git a/web/viewsjs/reports/characters_in_keys.js.erb b/web/viewsjs/reports/characters_in_keys.js.erb index 21fcb3a..012b699 100644 --- a/web/viewsjs/reports/characters_in_keys.js.erb +++ b/web/viewsjs/reports/characters_in_keys.js.erb @@ -24,7 +24,7 @@ var create_flexigrid_for = { data.rows = jQuery.map(data.data, function(row, i) { return { 'cell': [ link_to_key(row.key), - print_value_with_percent(row.count_all, row.count_all_fraction), + fmt_value_with_percent(row.count_all, row.count_all_fraction), fmt_with_ts(row.users_all), fmt_checkmark(row.in_wiki), fmt_checkmark(row.in_josm), @@ -57,7 +57,7 @@ var create_flexigrid_for = { data.rows = jQuery.map(data.data, function(row, i) { return { 'cell': [ link_to_key(row.key), - print_value_with_percent(row.count_all, row.count_all_fraction), + fmt_value_with_percent(row.count_all, row.count_all_fraction), fmt_with_ts(row.users_all), fmt_checkmark(row.in_wiki), fmt_checkmark(row.in_josm), diff --git a/web/viewsjs/reports/key_lengths.js.erb b/web/viewsjs/reports/key_lengths.js.erb index 908405c..7aea4e5 100644 --- a/web/viewsjs/reports/key_lengths.js.erb +++ b/web/viewsjs/reports/key_lengths.js.erb @@ -26,7 +26,7 @@ var create_flexigrid_for = { return { 'cell': [ row.key.length, link_to_key(row.key), - print_value_with_percent(row.count_all, row.count_all_fraction), + fmt_value_with_percent(row.count_all, row.count_all_fraction), fmt_checkmark(row.in_wiki), fmt_checkmark(row.in_josm), fmt_with_ts(row.values_all), diff --git a/web/viewsjs/reports/languages.js.erb b/web/viewsjs/reports/languages.js.erb index 9d8bd04..23e02be 100644 --- a/web/viewsjs/reports/languages.js.erb +++ b/web/viewsjs/reports/languages.js.erb @@ -24,8 +24,8 @@ function page_init() { span(row.code, 'lang'), row.native_name, row.english_name, - print_value_with_percent(row.wiki_key_pages, row.wiki_key_pages_fraction), - print_value_with_percent(row.wiki_tag_pages, row.wiki_tag_pages_fraction) + fmt_value_with_percent(row.wiki_key_pages, row.wiki_key_pages_fraction), + fmt_value_with_percent(row.wiki_tag_pages, row.wiki_tag_pages_fraction) ]}; }) }; diff --git a/web/viewsjs/tag.js.erb b/web/viewsjs/tag.js.erb index 03525f5..c763c90 100644 --- a/web/viewsjs/tag.js.erb +++ b/web/viewsjs/tag.js.erb @@ -30,7 +30,7 @@ var create_flexigrid_for = { rows: jQuery.map(data.data, function(row, i) { return { 'cell': [ fmt_image(row.type) + ' ' + texts.osm[row.type], - print_value_with_percent(row.count, row.count_fraction) + fmt_value_with_percent(row.count, row.count_fraction) ]}; }) }; @@ -53,9 +53,9 @@ var create_flexigrid_for = { preProcess: function(data) { data.rows = jQuery.map(data.data, function(row, i) { return { 'cell': [ - print_value_with_percent(row.together_count, row.to_fraction), + fmt_value_with_percent(row.together_count, row.to_fraction), link_to_key_or_tag(row.other_key, row.other_value), - print_value_with_percent(row.together_count, row.from_fraction), + fmt_value_with_percent(row.together_count, row.from_fraction), ] }; }); return data; diff --git a/web/viewsjs/tags.js.erb b/web/viewsjs/tags.js.erb index 11cfde7..9dd971e 100644 --- a/web/viewsjs/tags.js.erb +++ b/web/viewsjs/tags.js.erb @@ -21,10 +21,10 @@ function page_init() { data.rows = jQuery.map(data.data, function(row, i) { return { 'cell': [ hover_expand(link_to_tag(row.key, row.value, {}, { 'class': 'pref' })), - print_value_with_percent(row.count_all, row.count_all_fraction), - 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) + fmt_value_with_percent(row.count_all, row.count_all_fraction), + fmt_value_with_percent(row.count_nodes, row.count_nodes_fraction), + fmt_value_with_percent(row.count_ways, row.count_ways_fraction), + fmt_value_with_percent(row.count_relations, row.count_relations_fraction) ] }; }); return data; |