- data, labels = get_votes_per_interval_data(@election)
-
- line = Gruff::Line.new("700x400")
- line.theme = { :background_colors => ['#73BF26', '#ffffff'] }
- line.title = "Voters Over Time"
- line.font = File.expand_path('/usr/X11R6/lib/X11/fonts/TTF/Vera.ttf',
- RAILS_ROOT)
-
- line.data("#{@election.name}", data )
- line.labels = labels
-
- line.x_axis_label = "Intervals"
- line.y_axis_label = "Number of Votes"
- line.minimum_value = 0.0
-
- line.draw
- send_data(line.to_blob, :disposition => 'inline', :type => 'image/png')
+ data, labels, scale = get_votes_per_interval_data(@election)
+
+ hide_legend = true
+
+ graph = GruffGraff.new( :graph_type => Gruff::Line,
+ :data_name => @election.name,
+ :data => data,
+ :interval_labels => labels,
+ :title => "Voters Over Time",
+ :size => "330x232",
+ :legend_font_size => 40,
+ :title_font_size => 50,
+ :marker_count => 2,
+ :marker_font_size => 30,
+ :marker_color => '#999999',
+ :x_axis_label => scale,
+ :y_axis_label => "Number of Votes")
+ send_data(*graph.output)
+ end
+
+ def borda_bar
+ @election = Election.find(params[:id])
+ @election.results unless @election.borda_result
+ data, labels = get_borda_points(@election.borda_result)
+
+ size = "400x300"
+ size = "580x300" if @election.candidates.size >= 5
+
+ if @election.candidates.size >= 5
+ marker_font_size = 17
+ else
+ marker_font_size = 20
+ end
+
+ graph = GruffGraff.new( :graph_type => Gruff::Bar,
+ :data_name => @election.name,
+ :data => data,
+ :interval_labels => labels,
+ :size => size,
+ :title => "Points Per Candidate",
+ :marker_color => '#999999',
+ :marker_font_size => marker_font_size,
+ :y_axis_label => "Points",
+ :x_axis_label => "Candidates")
+ send_data(*graph.output)
+ end
+ #Acording to Tufte, small, concomparitive, highly labeled data sets usually
+ #belong in tables. The following is a bar graph...but would it be better
+ #as a table?
+ def choices_positions
+ @election = Election.find(params[:id])
+ legend = Hash.new
+ alldata, labels = get_positions_info(@election)
+ @election.results unless @election.condorcet_result || @election.ssd_result
+ ranked_candidates = @election.condorcet_result.ranked_candidates.flatten
+
+ names = Hash.new
+ candidates = @election.candidates.sort.collect {|candidate| candidate.id}
+ candidates.each do |candidate|
+ names[candidate]= (Candidate.find(candidate)).name
+ end
+
+ ranked_candidates.each_with_index \
+ {|candidate, index| legend[names[candidate]] = alldata[index]}
+
+ graph = GruffGraff.new( :graph_type => Gruff::Bar,
+ :data => legend,
+ :interval_labels => labels,
+ :title => "Times Voted in Each Position",
+ :y_axis_label => "Number of Times Ranked",
+ :x_axis_label => "Rank")
+ send_data(*graph.output)
+ end
+
+ def plurality_pie
+ @election = Election.find(params[:id])
+ @election.results unless @election.plurality_result || @election.approval_result
+ votes = @election.votes.size
+ data = Hash.new
+ names = @election.names_by_id
+
+ @election.plurality_result.points.each do |candidate, votes|
+ data[names[candidate]] = votes
+ end
+
+ pie = GruffGraff.new( :graph_type => Gruff::Pie,
+ :title => "Percentage of First Place Votes",
+ :data => data)
+ send_data(*pie.output)
+