%
osm = @trans.t.osm
misc = @trans.t.misc
taginfo = @trans.t.taginfo
page = @trans.t.pages.key
%>
var create_flexigrid_for = {
overview: function(key, filter_type) {
create_flexigrid('grid-overview', {
url: '/api/4/key/stats?key=' + encodeURIComponent(key),
colModel: [
{ display: '<%= h(misc.object_type) %>', name: 'type', width: 100, sortable: true },
{ display: '<%= h(page.number_objects) %>', name: 'count', width: 260, sortable: true, align: 'center' },
{ display: '<%= h(page.number_values) %>', name: 'value', width: 140, sortable: true, align: 'right' }
],
usepager: false,
useRp: false,
preProcess: function(data) {
return {
total: 4,
page: 1,
rows: jQuery.map(data.data, function(row, i) {
return { 'cell': [
fmt_type_image(row.type),
fmt_value_with_percent(row.count, row.count_fraction),
fmt_with_ts(row.values)
]};
})
};
}
});
},
values: function(key, filter_type, lang) {
create_flexigrid('grid-values', {
url: '/api/4/key/values?key=' + encodeURIComponent(key) + '&filter=' + encodeURIComponent(filter_type) + '&lang=' + encodeURIComponent(lang),
colModel: [
{ display: '<%= h(osm.value) %>', name: 'value', width: 200, sortable: true },
{ display: '<%= h(misc.count) %>', name: 'count', width: 260, sortable: true, align: 'center' },
{ display: '', name: 'in_wiki', width: 20, sortable: true, align: 'center' },
{ display: '<%= h(misc.description) %>', name: 'description', width: 600, sortable: false, align: 'left' }
],
searchitems: [
{ display: '<%= h(osm.value) %>', name: 'value' }
],
sortname: 'count',
sortorder: 'desc',
preProcess: function(data) {
data.rows = jQuery.map(data.data, function(row, i) {
return { 'cell': [
hover_expand(link_to_value(key, row.value)),
fmt_value_with_percent(row.count, row.fraction),
fmt_checkmark(row.in_wiki),
html_escape(row.description)
] };
});
delete data.data;
return data;
}
});
},
combinations: function(key, filter_type) {
create_flexigrid('grid-keys', {
url: '/api/4/key/combinations?key=' + encodeURIComponent(key) + '&filter=' + encodeURIComponent(filter_type),
colModel: [
{ display: '<%= h(misc.count) %> →', name: 'to_count', width: 260, sortable: true, align: 'center' },
{ display: '<%= h(page.other_keys_used.other) %>', name: 'other_key', width: 400, sortable: true },
{ display: '→ <%= h(misc.count) %>', name: 'from_count', width: 260, sortable: true, align: 'center' }
],
searchitems: [
{ display: '<%= h(page.other_keys_used.other) %>', name: 'other_key' }
],
sortname: 'to_count',
sortorder: 'desc',
preProcess: function(data) {
data.rows = jQuery.map(data.data, function(row, i) {
return { 'cell': [
fmt_value_with_percent(row.together_count, row.to_fraction),
link_to_key(row.other_key),
fmt_value_with_percent(row.together_count, row.from_fraction),
] };
});
return data;
}
});
},
similar: function(key) {
create_flexigrid('grid-similar', {
url: '/api/4/key/similar?key=' + encodeURIComponent(key),
colModel: [
{ display: '<%= h(page.similar.other) %>', name: 'other_key', width: 500, sortable: true },
{ display: '<%= h(misc.count) %>', name: 'count_all', width: 160, sortable: true, align: 'right' },
{ display: '<%= h(page.similar.similarity) %>', name: 'similarity', width: 100, sortable: true, align: 'right' }
],
searchitems: [
{ display: '<%= h(page.similar.other) %>', name: 'other_key' }
],
sortname: 'other_key',
sortorder: 'asc',
preProcess: function(data) {
data.rows = jQuery.map(data.data, function(row, i) {
return { 'cell': [
link_to_key_with_highlight(row.other_key, key),
row.count_all,
row.similarity
] };
});
return data;
}
});
},
wiki: function(key, filter_type) {
create_flexigrid('grid-wiki', {
url: '/api/4/key/wiki_pages?key=' + encodeURIComponent(key),
colModel: [
{ display: '<%= h(misc.language) %>', name: 'lang', width: 150, sortable: false },
{ display: '<%= h(page.wiki_pages.wiki_page) %>', name: 'title', width: 160, sortable: false, align: 'right' },
{ display: '<%= h(misc.description) %>', name: 'description', width: 400, sortable: false },
{ display: '<%= h(misc.image) %>', name: 'image', width: 120, sortable: false },
{ display: '<%= h(osm.objects) %>', name: 'objects', width: 80, sortable: false },
{ display: '<%= h(page.wiki_pages.implied_tags) %>', name: 'tags_implied', width: 120, sortable: false },
{ display: '<%= h(page.wiki_pages.combined_tags) %>', name: 'tags_combination', width: 120, sortable: false },
{ display: '<%= h(page.wiki_pages.linked_tags) %>', name: 'tags_linked', width: 220, sortable: false }
],
usepager: false,
useRp: false,
preProcess: function(data) {
return {
total: data.size,
page: 1,
rows: jQuery.map(data, function(row, i) {
return { 'cell': [
fmt_language(row.lang, row.language, row.language_en),
link_to_wiki(row.title),
html_escape(row.description),
fmt_wiki_image_popup(row.image),
fmt_type_icon('node', row.on_node) +
fmt_type_icon('way', row.on_way) +
fmt_type_icon('area', row.on_area) +
fmt_type_icon('relation', row.on_relation),
fmt_key_or_tag_list(row.tags_implies),
fmt_key_or_tag_list(row.tags_combination),
fmt_key_or_tag_list(row.tags_linked)
]};
})
};
}
});
},
projects: function(key, filter_type) {
create_flexigrid('grid-projects', {
url: '/api/4/key/projects?key=' + encodeURIComponent(key) + '&filter=' + encodeURIComponent(filter_type),
colModel: [
{ display: '<%= h(taginfo.project) %>', name: 'project_name', width: 280, sortable: true },
{ display: '<%= h(osm.tag) %>', name: 'tag', width: 220, sortable: true },
{ display: '<%= h(osm.objects) %>', name: 'objects', width: 80, sortable: false },
{ display: '<%= h(page.projects.description) %>', name: 'description', width: 600, sortable: false, align: 'left' }
],
searchitems: [
{ display: '<%= h(taginfo.project) %>/<%= h(osm.value) %>', name: 'project_value' }
],
sortname: 'tag',
sortorder: 'asc',
preProcess: function(data) {
data.rows = jQuery.map(data.data, function(row, i) {
return { 'cell': [
link_to_project(row.project_id, row.project_name, row.project_icon_url),
row.value ? link_to_tag(row.key, row.value) : (link_to_key(row.key) + '=*'),
fmt_type_icon('node', row.on_node) +
fmt_type_icon('way', row.on_way) +
fmt_type_icon('area', row.on_area) +
fmt_type_icon('relation', row.on_relation),
project_tag_desc(row.description, row.icon_url, row.doc_url)
] };
});
return data;
}
});
}
};
function create_chart(params) {
var y = 0;
params.data.forEach(function(d) {
d['y'] = y;
y += d['count'];
});
var scale = d3.scale.linear()
.domain([0, params.max])
.range([0, params.height]);
var color = d3.scale.ordinal()
.range(d3_colors());
var chart = d3.select('#canvas-values').append('svg')
.attr("width", params.width)
.attr("height", params.height);
chart.selectAll("rect")
.data(params.data)
.enter()
.append("svg:a")
.attr('xlink:href', function(d) { return url_for_tag(params.key, d['value']); })
.attr('transform', function(d) { return 'translate(10, ' + scale(d['y']) + ')'; })
.call(function(c) {
c.append("rect")
.attr('width', 20)
.attr('height', function(d) { return scale(d['count']); })
.style('fill', function(d, i) { return color(i); });
})
.append("text")
.attr('x', 25)
.attr('y', function(d) { return scale(d['count'] / 2); })
.attr('dy', '0.5em')
.text(function(d) { return d['value']; });
}
function page_init() {
up = function() { window.location = '/keys'; }
activate_josm_button();
jQuery('#filter').bind('change', function() {
var value = this.value;
var qs = jQuery.getQueryString;
qs['filter'] = value;
window.location.search = jQuery.param(qs);
});
page_init2();
}