summaryrefslogtreecommitdiff
path: root/web/viewsjs/reports/characters_in_keys.js.erb
blob: 3dbc7c0b684b3dae2fd2aa9127dfd56fcd4e486c (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
<%
    osm = @trans.t.osm
    misc = @trans.t.misc
 %>
var create_flexigrid_for = {
    whitespace: function() {
        create_flexigrid('grid-whitespace', {
            url: '/api/4/keys/all?filter=characters_space&include=prevalent_values',
            colModel: [
                { display: '<%= h(osm.key) %>', name: 'key', width: 250, sortable: true },
                { display: '<span title="<%= h(misc.objects_tooltip) %>"><img src="/img/types/all.16.png" width="16" height="16" alt=""/> <%= h(osm.objects) %></span>', name: 'count_all', width: 150, sortable: true, align: 'center' },
                { display: '<span title="<%= h(misc.users_tooltip) %>"><%= h(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="<%= h(misc.in_wiki_tooltip) %>"/>', name: 'in_wiki', width: 20, sortable: true, align: 'center' },
                { display: '<span title="<%= h(misc.values_tooltip) %>"><%= h(osm.values) %></span>', name: 'values_all', width: 70, sortable: true, align: 'right' },
                { display: '<span title="<%= h(misc.prevalent_values_tooltip) %>"><%= h(misc.prevalent_values) %></span>', name: 'prevalent_values', width: 600, sortable: true }
            ],
            searchitems: [
                { display: '<%= h(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),
                        fmt_value_with_percent(row.count_all, row.count_all_fraction),
                        fmt_with_ts(row.users_all),
                        fmt_checkmark(row.in_wiki),
                        fmt_with_ts(row.values_all),
                        fmt_prevalent_value_list(row.key, row.prevalent_values)
                    ] };
                });
                return data;
            }
        });
    },
    problematic: function() {
        create_flexigrid('grid-problematic', {
            url: '/api/4/keys/all?filter=characters_problematic&include=prevalent_values',
            colModel: [
                { display: '<%= h(osm.key) %>', name: 'key', width: 250, sortable: true },
                { display: '<span title="<%= h(misc.objects_tooltip) %>"><img src="/img/types/all.16.png" width="16" height="16" alt=""/> <%= h(osm.objects) %></span>', name: 'count_all', width: 150, sortable: true, align: 'center' },
                { display: '<span title="<%= h(misc.users_tooltip) %>"><%= h(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="<%= h(misc.in_wiki_tooltip) %>"/>', name: 'in_wiki', width: 20, sortable: true, align: 'center' },
                { display: '<span title="<%= h(misc.values_tooltip) %>"><%= h(osm.values) %></span>', name: 'values_all', width: 70, sortable: true, align: 'right' },
                { display: '<span title="<%= h(misc.prevalent_values_tooltip) %>"><%= h(misc.prevalent_values) %></span>', name: 'prevalent_values', width: 600, sortable: true }
            ],
            searchitems: [
                { display: '<%= h(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),
                        fmt_value_with_percent(row.count_all, row.count_all_fraction),
                        fmt_with_ts(row.users_all),
                        fmt_checkmark(row.in_wiki),
                        fmt_with_ts(row.values_all),
                        fmt_prevalent_value_list(row.key, row.prevalent_values)
                    ] };
                });
                return data;
            }
        });
    }
};

function page_init() {
    up = function() { window.location = '/reports'; };
    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']; });

}