1 class GraphsController < ApplicationController
3 # To make caching easier, add a line like this to config/routes.rb:
4 # map.graph "graph/:action/:id/image.png", :controller => "graph"
6 # Then reference it with the named route:
7 # image_tag graph_url(:action => 'show', :id => 42)
11 # Uncomment to use your own theme or font
12 # See http://colourlovers.com or http://www.firewheeldesign.com/widgets/ for color ideas
14 # :colors => ['#663366', '#cccc99', '#cc6633', '#cc9966', '#99cc99'],
15 # :marker_color => 'white',
16 # :background_colors => ['black', '#333333']
18 # g.font = File.expand_path('artwork/fonts/VeraBd.ttf', RAILS_ROOT)
20 g.title = "Gruff-o-Rama"
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])
27 g.labels = {0 => '2004', 2 => '2005', 4 => '2006'}
29 send_data(g.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "gruff.png")
32 #I've started to modify the following section to fit Selectricity, still
33 #desn't seem towork, issue seems tobe realted to path
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
46 send_data(line.to_blob,
47 :disposition => 'inline',
49 :filename => "dayvotes#{@poll.id}.png")
53 @election = Election.find(params[:id])
54 voter_times = Array.new
55 unique_days = Array.new
56 voters_per_day = Array.new
59 @election.votes.each do |vote|
60 voter_times << vote.time unless voter_times.any? {|utime| utime == vote.time}
65 voter_times.each_with_index do |time, index|
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
74 unique_days.each_with_index do |fmtdate, index|
75 days_hash[index] = fmtdate
77 return { "voters_per_day" => voters_per_day, "days_hash" => days_hash }