- 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)
+
+ graph = GruffGraff.new( :graph_type => Gruff::Line,
+ :data_name => @election.name,
+ :data => data,
+ :interval_labels => labels,
+ :title => "Voters Over Time",
+ :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)
+
+ graph = GruffGraff.new( :graph_type => Gruff::Bar,
+ :data_name => @election.name,
+ :data => data,
+ :interval_labels => labels,
+ :title => "Points Per Candidate",
+ :y_axis_label => "Points",
+ :x_axis_label => "Candidate")
+ 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])
+ pref_tally = make_preference_tally(@election)
+
+ fulldata, labels = get_positions_info(@election)
+ legend = Hash.new
+
+ @election.candidates.each_with_index do |candidate, index|
+ legend[candidate.name] = fulldata[index]
+ end
+
+ 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)