blob: 9931a82ce39dfcb442b053e46753a95824ed1897 (
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
|
<h1><%= @title %></h1>
<p>Tag keys can be between 0 and 255 (Unicode) characters long. Very short or very long keys are often, but not always, errors.</p>
<%
hist = Array.new
@db.execute('SELECT length(key) AS length, count(*) AS count FROM db.keys GROUP BY length(key) ORDER BY length(key)') do |row|
hist[row['length'].to_i] = row['count'].to_i
end
hist = hist.map{ |item| item.nil? ? 0 : item }
%>
<div id="tabs">
<ul>
<li><a href="#keys">Keys</a></li>
<li><a href="#histogram">Histogram</a></li>
</ul>
<div id="keys">
<h2>Keys</h2>
<table id="grid-keys">
</table>
</div>
<div id="histogram">
<h2>Histogram</h2>
<p>This histogram shows how many keys there are of each length.<p>
<div id="canvas"></div>
</div>
</div>
<script type="text/javascript">
jQuery(function() {
var tabs = jQuery('#tabs').tabs({
show: function(event, ui) {
window.location.hash = ui.tab.hash;
create_flexigrid_for.reports.key_lengths[ui.tab.hash.substring(1)]();
}
});
});
var data = <%= hist.to_json %>;
var w=900, h=400, bar_width=6;
var vis = new pv.Panel()
.canvas('canvas')
.fillStyle('#ffffff')
.width(w)
.height(h+4)
.top(10)
.right(15)
.bottom(40)
.left(60)
.strokeStyle('#cccccc')
.lineWidth(1);
vis.add(pv.Label)
.data(['Key length'])
.bottom(-36)
.left(w/2)
.textAlign('center');
vis.add(pv.Label)
.data(['Number of keys'])
.left(-48)
.bottom(h/2)
.textAlign('center')
.textAngle(-Math.PI/2);
var x = pv.Scale.linear(0, <%= hist.size %>).range(bar_width, w - bar_width);
var y = pv.Scale.linear(0, <%= hist.max %>).range(0, h);
var bar = vis.add(pv.Bar)
.data(data)
.bottom(1)
.left(function() { return x(this.index) - bar_width/2; })
.height(y)
.title(function(d) { return '' + d + ' keys of length ' + this.index; })
.width(bar_width);
vis.add(pv.Rule)
.data(y.ticks(10))
.bottom(y)
.left(-5)
.width(-5)
.anchor("left").add(pv.Label)
.textMargin(8)
.text(x.tickFormat);
vis.add(pv.Rule)
.data(x.ticks(10))
.left(x)
.bottom(-2)
.height(-5)
.anchor("bottom").add(pv.Label)
.textMargin(8)
.text(x.tickFormat);
vis.render();
</script>
|