+ #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
+ size = "400x300"
+ size = "520x300" if @election.candidates.size >= 8
+
+ if @election.candidates.size >= 8
+ marker_font_size = 20
+ legend_font_size = 17
+ else
+ marker_font_size = 17
+ legend_font_size = 17
+ end