summaryrefslogtreecommitdiff
path: root/web/views/reports/characters_in_keys.erb
blob: 71f2470a48102a5a4f4eab2f145e78a39ff904f5 (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
<div class="pre">
    <h1><%= t.reports.characters_in_keys.name %></h1>
    <%= t.reports.characters_in_keys.intro %>
</div>
<div id="tabs">
    <ul>
        <li><a href="#statistics"><%= t.reports.characters_in_keys.statistics.tab %></a></li>
        <li><a href="#whitespace"><span style="background-color: #d62727;">&nbsp;&nbsp;&nbsp;</span> <%= t.reports.characters_in_keys.whitespace.tab %></a></li>
        <li><a href="#problematic"><span style="background-color: #ff9896;">&nbsp;&nbsp;&nbsp;</span> <%= t.reports.characters_in_keys.problematic.tab %></a></li>
    </ul>
    <div id="statistics">
        <h2><%= t.reports.characters_in_keys.statistics.title %></h2>
        <div class="canvas boxpre" id="canvas" style="margin-bottom: 20px;"></div>
        <table class="list">
            <tr>
                <th>&nbsp;</th>
                <th class="tr"><%= t.misc.count %></th>
                <th class="tr"><%= t.reports.characters_in_keys.statistics.fraction %></th>
                <th class="tl"><%= t.reports.characters_in_keys.statistics.characters %></th>
            </tr>
<% letter='A'
   colors = { :A => '#2ca02c', :B => '#98df8a', :C => '#dbdb8d', :D => '#d62728', :E => '#ff9896', :F => '#aec7e8' }
   %w(plain colon letters space problem rest).each_with_index do |type, n| c = (n%2!=0) ? ' even' : '' %>
            <tr>
                <td class="tc<%= c %>" style="background-color: <%= colors[letter.to_sym] %>;"><%= letter %></td>
                <td class="tr<%= c %>"><%= @db.stats('characters_in_keys_' + type) %></td>
                <td class="tr<%= c %>"><%= sprintf '%.2f', @db.stats('characters_in_keys_' + type) * 100.0 / @db.stats('num_keys') %>%</td>
                <td class="tl<%= c %>"><%= t.reports.characters_in_keys.statistics.characters_in_keys[type] %></td>
            </tr>
<% letter = letter.succ; end %>
            <tr>
                <td class="tc" style="border-top: 1px solid #000000;"></td>
                <td class="tr" style="border-top: 1px solid #000000;"><%= @db.stats('num_keys') %></td>
                <td class="tr" style="border-top: 1px solid #000000;">100%</td>
                <td class="tl" style="border-top: 1px solid #000000;">Total</td>
            </tr>
        </table>
    </div>
    <div id="whitespace">
        <h2><%= t.reports.characters_in_keys.whitespace.title %></h2>
        <div class="boxpre">
            <%= t.reports.characters_in_keys.whitespace.intro %>
        </div>
        <table id="grid-whitespace">
        </table>
    </div>
    <div id="problematic">
        <h2><%= t.reports.characters_in_keys.problematic.title %></h2>
        <div class="boxpre">
            <%= t.reports.characters_in_keys.problematic.intro %>
        </div>
        <table id="grid-problematic">
        </table>
    </div>
</div>

<% javascript do
    JQuery.ready do
        JS.raw(<<"JAVASCRIPT")

var tabs = jQuery('#tabs').tabs({
    show: function(event, ui) { 
        resize_wrapper();
        window.location.hash = ui.tab.hash;
        if (create_flexigrid_for.reports.characters_in_keys[ui.tab.hash.substring(1)]) {
            create_flexigrid_for.reports.characters_in_keys[ui.tab.hash.substring(1)]();
        }
    }
});

var 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 w=968, h=50;

var vis = new pv.Panel()
    .canvas('canvas')
    .width(w + 20)
    .height(h);

var colors = #{ colors.to_json };

var scale = pv.Scale.linear(0, #{ @db.stats('num_keys') }).range(0, w);

vis.add(pv.Layout.Stack)
    .orient('left-top')
    .left(10)
    .layers(data)
    .x(10)
    .y(function(d) { return scale(d.value); })
  .layer.add(pv.Bar)
    .fillStyle(function(d) { return colors[d.label]; })
    .height(20)
  .anchor('bottom')
    .add(pv.Label)
    .top(46)
    .text(function(d) { return d.label; });

vis.render();
JAVASCRIPT
    end
end
%>