summaryrefslogtreecommitdiff
path: root/web/viewsjs/reports/characters_in_keys.js.erb
blob: 2d9a5c36058fc9e895f891a84443aa683cd8c9e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<%
    osm = @trans.t.osm
    misc = @trans.t.misc
 %>
var create_flexigrid_for = {
    whitespace: function() {
        create_flexigrid('grid-whitespace', {
            url: '/api/2/db/keys?filters=characters_space&include=prevalent_values',
            colModel: [
                { display: '<%= osm.key %>', name: 'key', width: 250, sortable: true },
                { display: '<span title="<%= misc.objects_tooltip %>"><img src="/img/types/all.16.png" width="16" height="16" alt=""/> <%= osm.objects %></span>', name: 'count_all', width: 250, sortable: true, align: 'center' },
                { display: '<span title="<%= misc.users_tooltip %>"><%= osm.users %></span>', name: 'users_all', width: 44, sortable: true, align: 'right' },
                { display: '<img src="/img/sources/wiki.16.png" width="16" height="16" alt="Wiki" title="<%= misc.in_wiki_tooltip %>"/>', name: 'in_wiki', width: 20, sortable: true, align: 'center' },
                { display: '<img src="/img/sources/josm.16.png" width="16" height="16" alt="JOSM" title="<%= misc.in_josm_tooltip %>"/>', name: 'in_josm', width: 20, sortable: true, align: 'center' },
                { display: '<span title="<%= misc.values_tooltip %>"><%= osm.values %></span>', name: 'values_all', width: 70, sortable: true, align: 'right' },
                { display: '<span title="<%= misc.prevalent_values_tooltip %>"><%= misc.prevalent_values %></span>', name: 'prevalent_values', width: 500, sortable: true }
            ],
            searchitems: [
                { display: '<%= osm.key %>', name: 'key' }
            ],
            sortname: 'count_all',
            sortorder: 'desc',
            preProcess: function(data) {
                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_with_ts(row.users_all),
                        row.in_wiki       ? '&#x2714;' : '-',
                        row.in_josm       ? '&#x2714;' : '-',
                        print_with_ts(row.values_all),
                        print_prevalent_value_list(row.key, row.prevalent_values)
                    ] };
                });
                return data;
            }
        });
    },
    problematic: function() {
        create_flexigrid('grid-problematic', {
            url: '/api/2/db/keys?filters=characters_problematic&include=prevalent_values',
            colModel: [
                { display: '<%= osm.key %>', name: 'key', width: 250, sortable: true },
                { display: '<span title="<%= misc.objects_tooltip %>"><img src="/img/types/all.16.png" width="16" height="16" alt=""/> <%= osm.objects %></span>', name: 'count_all', width: 250, sortable: true, align: 'center' },
                { display: '<span title="<%= misc.users_tooltip %>"><%= osm.users %></span>', name: 'users_all', width: 44, sortable: true, align: 'right' },
                { display: '<img src="/img/sources/wiki.16.png" width="16" height="16" alt="Wiki" title="<%= misc.in_wiki_tooltip %>"/>', name: 'in_wiki', width: 20, sortable: true, align: 'center' },
                { display: '<img src="/img/sources/josm.16.png" width="16" height="16" alt="JOSM" title="<%= misc.in_josm_tooltip %>"/>', name: 'in_josm', width: 20, sortable: true, align: 'center' },
                { display: '<span title="<%= misc.values_tooltip %>"><%= osm.values %></span>', name: 'values_all', width: 70, sortable: true, align: 'right' },
                { display: '<span title="<%= misc.prevalent_values_tooltip %>"><%= misc.prevalent_values %></span>', name: 'prevalent_values', width: 500, sortable: true }
            ],
            searchitems: [
                { display: '<%= osm.key %>', name: 'key' }
            ],
            sortname: 'count_all',
            sortorder: 'desc',
            preProcess: function(data) {
                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_with_ts(row.users_all),
                        row.in_wiki       ? '&#x2714;' : '-',
                        row.in_josm       ? '&#x2714;' : '-',
                        print_with_ts(row.values_all),
                        print_prevalent_value_list(row.key, row.prevalent_values)
                    ] };
                });
                return data;
            }
        });
    }
};

function page_init() {
    init_tabs([]);

    var w = 968,
        h = 50,
        max = <%= @db.stats('num_keys') %>,
        data = <%= i = '@'; %w(plain colon letters space problem rest).map{ |type| i=i.next; { :label => i, :value => @db.stats('characters_in_keys_' + type) } }.to_json %>;

    var colors = { 'A': '#2ca02c', 'B': '#98df8a', 'C': '#dbdb8d', 'D': '#d62728', 'E': '#ff9896', 'F': '#aec7e8' };

    var y = 0;
    data.forEach(function(d) {
        d['y'] = y;
        y += d['value'];
    });

    var scale = d3.scale.linear()
                    .domain([0, max])
                    .range([0, w]);
        
    var chart = d3.select('#canvas').append('svg')
                    .attr("width", w)
                    .attr("height", h);

    chart.selectAll("rect")
        .data(data)
        .enter()
        .append("svg:g")
            .attr('transform', function(d) { return 'translate(' + scale(d['y']) + ', 0)'; })
            .call(function(c) {
                c.append("rect")
                    .attr('height', 20)
                    .attr('width', function(d) { return scale(d['value']); })
                    .style('fill', function(d) { return colors[d['label']]; });
            })
            .append("text")
                .attr('x', function(d) { return scale(d['value'] / 2); })
                .attr('y', 34)
                .style('text-anchor', 'middle')
                .text(function(d) { return d['label']; });

}