public
Description: Histograms, Linear Regression, Normal Distribution Analysis, Counting Occurances. I'm sure someone has made a better stats module than this one.
Clone URL: git://github.com/chriseppstein/lame_stats.git
Search Repo:
Ridiculous box code.
dustin (author)
Sat May 10 17:11:00 -0700 2008
commit  8530beff52d2b1521099cb86f8fc1fcd99a632a1
tree    4f906c7e346ebac0cefda557153c6f40aa7bf629
parent  0b455260dde49c2bccaecc9ebadb616013059776
...
188
189
190
191
 
192
193
194
195
 
196
197
198
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
200
201
...
188
189
190
 
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
0
@@ -188,14 +188,34 @@
0
     end
0
 
0
     def to_s(options = {})
0
- if options[:orientation] == :vertical
0
+ rv = if options[:orientation] == :vertical
0
         plot_vertically options
0
       else
0
         plot_horizontally options
0
       end
0
+ options[:box] ? box(rv, options) : rv
0
     end
0
 
0
     private
0
+
0
+ # Put a box around a histogram plot
0
+ def box(rv, options = {})
0
+ lines = rv.split("\n")
0
+ hspace = ' ' * options.fetch(:hspace, 2)
0
+ w = if options[:orientation] == :vertical
0
+ ((@counts.size * (hspace.size + 1)) - hspace.size)
0
+ else
0
+ raise "Boxes currently aren't supported for horizontal graphs"
0
+ [options.fetch(:max_width, @counts.size), @counts.size].min
0
+ end
0
+ h = lines.size
0
+ tb = [0x2500].pack("U") * w
0
+ rv = [ [0x256d].pack("U") + tb + [0x256e].pack("U") ]
0
+ e = [0x2502].pack("U")
0
+ rv += lines.map{|l| e + l + e}
0
+ rv << [0x2570].pack("U") + tb + [0x256f].pack("U")
0
+ rv.join("\n")
0
+ end
0
 
0
     def plot_vertically(options = {})
0
       char = options.fetch(:char, '*')

Comments

    No one has commented yet.