diff options
author | Jochen Topf <jochen@topf.org> | 2015-05-12 18:20:38 +0200 |
---|---|---|
committer | Jochen Topf <jochen@topf.org> | 2015-05-12 18:20:38 +0200 |
commit | a338547eafeed14eae74befbe706eadcf6a9fb4e (patch) | |
tree | 3f6a30a61754e1d6c8b3559ce11cc4757d8561d1 /web/viewsjs | |
parent | dfb106fd58e2ff79ef9f035a135cc0f9492df7cf (diff) | |
download | taginfo-a338547eafeed14eae74befbe706eadcf6a9fb4e.tar taginfo-a338547eafeed14eae74befbe706eadcf6a9fb4e.tar.gz |
Add experimental new home page.
This could replace the current home page at some point.
Diffstat (limited to 'web/viewsjs')
-rw-r--r-- | web/viewsjs/test-index.js.erb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/web/viewsjs/test-index.js.erb b/web/viewsjs/test-index.js.erb new file mode 100644 index 0000000..8920c3c --- /dev/null +++ b/web/viewsjs/test-index.js.erb @@ -0,0 +1,53 @@ +<% +# This is the maximum number of keys/tags/relations in the lists. Javascript +# code will only show as many of them as will fit in the window. +tagcloud_number_of_keys = 100 +tagcloud_number_of_tags = 100 +tagcloud_number_of_rels = 100 +keys = @db.select("SELECT key FROM popular_keys ORDER BY scale1 DESC LIMIT #{ tagcloud_number_of_keys }").execute() +tags = @db.select("SELECT skey, svalue FROM top_tags WHERE skey NOT IN ('source', 'source_ref', 'attribution') ORDER BY count_all DESC LIMIT #{ tagcloud_number_of_tags }").execute() +rels = @db.select("SELECT rtype FROM db.relation_types WHERE count >= 1000 ORDER BY count DESC LIMIT #{ tagcloud_number_of_rels }").execute() +%> + +var data = { + 'keys': <%= keys.map{ |tag| tag['key'] }.to_json %>, + 'tags': <%= tags.map{ |entry| [ entry['skey'], entry['svalue'] ] }.to_json %>, + 'rels': <%= rels.map{ |row| row['rtype'] }.to_json %> +}; + +up = function() {}; + +function create_list(element, max_height, data, decrease, func) { + var i = 0, + size = 160; + + while (element.innerHeight() < max_height && data[i]) { + element.append(func(data[i], size)); + element.append('<span style="font-size: ' + size + '%;"> • </span>'); + i++; + size -= decrease; + } + + element.append('...'); +} + +function resize_home() { + + create_list(jQuery('#key_list').empty(), 120, data.keys, 1, function(d, size) { + return link_to_key(d, { 'style': 'font-size: ' + size + "%;" }); + }); + + create_list(jQuery('#tag_list').empty(), 120, data.tags, 2, function(d, size) { + return '<span style="font-size: ' + size + '%;"> ' + link_to_tag(d[0], d[1]) + ' </span>' + }); + + create_list(jQuery('#relation_list').empty(), 120, data.rels, 5, function(d, size) { + return link_to_rtype(d, { 'style': 'font-size: ' + size + "%;" }); + }); + +} + +function page_init() { + jQuery(window).resize(resize_home); + resize_home(); +} |