X-Git-Url: https://projects.mako.cc/source/selectricity/blobdiff_plain/257d5a4c8c02d7b001fbfbce4aaced9f9937ff61..a8006b0bf9687f8882c3073eca2e8b4ebc7cde4a:/app/controllers/graph_controller.rb?ds=sidebyside diff --git a/app/controllers/graph_controller.rb b/app/controllers/graph_controller.rb index 442bb65..69577c6 100644 --- a/app/controllers/graph_controller.rb +++ b/app/controllers/graph_controller.rb @@ -99,6 +99,7 @@ class GraphController < ApplicationController 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} @@ -106,7 +107,6 @@ class GraphController < ApplicationController names[candidate]= (Candidate.find(candidate)).name end - ranked_candidates = @election.condorcet_result.ranked_candidates.flatten ranked_candidates.each_with_index \ {|candidate, index| legend[names[candidate]] = alldata[index]} @@ -119,6 +119,24 @@ class GraphController < ApplicationController 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) + + end + private def get_positions_info(election) buckets = Hash.new