Modified the methods in graphs controller so they would work for Selectricity, but...
[selectricity] / app / controllers / graphs_controller.rb
1 class GraphsController < ApplicationController
2
3   # To make caching easier, add a line like this to config/routes.rb:
4   # map.graph "graph/:action/:id/image.png", :controller => "graph"
5   #
6   # Then reference it with the named route:
7   #   image_tag graph_url(:action => 'show', :id => 42)
8
9   def show
10     g = Gruff::Line.new
11     # Uncomment to use your own theme or font
12     # See http://colourlovers.com or http://www.firewheeldesign.com/widgets/ for color ideas
13 #     g.theme = {
14 #       :colors => ['#663366', '#cccc99', '#cc6633', '#cc9966', '#99cc99'],
15 #       :marker_color => 'white',
16 #       :background_colors => ['black', '#333333']
17 #     }
18 #     g.font = File.expand_path('artwork/fonts/VeraBd.ttf', RAILS_ROOT)
19
20     g.title = "Gruff-o-Rama"
21     
22     g.data("Apples", [1, 2, 3, 4, 4, 3])
23     g.data("Oranges", [4, 8, 7, 9, 8, 9])
24     g.data("Watermelon", [2, 3, 1, 5, 6, 8])
25     g.data("Peaches", [9, 9, 10, 8, 7, 9])
26
27     g.labels = {0 => '2004', 2 => '2005', 4 => '2006'}
28
29     send_data(g.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "gruff.png")
30   end
31   
32   #I've started to modify the following section to fit Selectricity, still 
33   #desn't seem towork, issue seems tobe realted to path
34   def day_votes
35   
36     @election = Election.find(params[:id])
37     line = Gruff::Line.new
38     line.title = "Voters Per Day"
39     line.font = File.expand_path('/usr/X11R6/lib/X11/fonts/TTF/Vera.ttf', RAILS_ROOT)
40     line.data("#{@election.name}", voter_days["voters_per_day"] )
41     line.labels = voter_days["days_hash"]
42     line.x_axis_label = "Date"
43     line.y_axis_label = "Number of Votes"
44     line.minimum_value = 0.0
45     line.draw
46     send_data(line.to_blob,
47               :disposition => 'inline',
48               :type => 'image/png',
49               :filename => "dayvotes#{@poll.id}.png")
50   end
51   
52   def voter_days
53     @election = Election.find(params[:id])
54     voter_times = Array.new
55     unique_days = Array.new
56     voters_per_day = Array.new
57     days_hash = Hash.new
58     
59     @election.votes.each do |vote|
60         voter_times << vote.time unless voter_times.any? {|utime| utime == vote.time}
61     end
62     
63     voter_times.sort!
64   
65     voter_times.each_with_index do |time, index| 
66       count = 1
67       unless unique_days.any? { |d1| d1.eql?(time.mon.to_s+"/"+time.day.to_s) }
68         unique_days << (time.mon.to_s+"/"+time.day.to_s)
69         count += (voter_times[(index+1)..-1].find_all {|t| t.mon == time.mon && t.day == time.day}).size
70         voters_per_day << count
71       end      
72     end
73     
74     unique_days.each_with_index do |fmtdate, index|
75       days_hash[index] = fmtdate
76     end    
77   return { "voters_per_day" => voters_per_day, "days_hash" => days_hash }
78    
79   end
80   #end section
81
82
83 end

Benjamin Mako Hill || Want to submit a patch?