dealign with multiple data arrays being passed in. Next need to compensate for giving each set of data it's own name, possible a hash with "name" => data as the key, value pairs...
RAILS_ROOT)
# fill in the data with the optional data name
RAILS_ROOT)
# fill in the data with the optional data name
+ #Check to see if multiple datasets, if so, fill them all!
+ if options[:data].size > 1 && options[:data].all? {|i| i.is_a?(Array)}
+ options[:data].each do |array|
+ @graph.data( options.fetch(:data_name, "Data"), array)
+ end
+ else #one dimensional array, just pass it in
@graph.data( options.fetch(:data_name, "Data"), options[:data] )
@graph.data( options.fetch(:data_name, "Data"), options[:data] )
# set the labels or create an empty hash
@graph.labels = options[:interval_labels] \
if options.has_key?(:interval_labels) and \
# set the labels or create an empty hash
@graph.labels = options[:interval_labels] \
if options.has_key?(:interval_labels) and \
@election = Election.find(params[:id])
pref_tally = make_preference_tally(@election)
@election = Election.find(params[:id])
pref_tally = make_preference_tally(@election)
- fulldata = get_positions_info(@election)
- (0...@election.candidates.size).each do |i|
- sbar.data("Candidate#{i+1}", fulldata[i])
- end
-
- sbar = Gruff::Bar.new
- sbar.title = "Times Voted in Each Position"
- #sbar.theme = { :background_colors => ['#73BF26', '#ffffff'] }
- sbar.font = File.expand_path('/usr/X11R6/lib/X11/fonts/TTF/Vera.ttf',
- RAILS_ROOT)
-
+ fulldata, labels = get_positions_info(@election)
+ labels = @candidates
graph = GruffGraff.new( :graph_type => Gruff::Bar,
:data_name => @election.name,
graph = GruffGraff.new( :graph_type => Gruff::Bar,
:data_name => @election.name,
:interval_labels => labels,
:interval_labels => labels,
- :title => "Times Candidate Was Voted Each Position",
- :x_axis_label => "Rank",
- :y_axis_label => "Number of Times")
-
-
-
-
- sbar.x_axis_label = "Rank"
- sbar.y_axis_label = "Number of Times Ranked"
-
- sbar.minimum_value = 0.0
- send_data(sbar.to_blob, :disposition => 'inline', :type => 'image/png')
-
-
- #data, labels = get_positions_info(@election)
-
+ :title => "Times Voted in Each Position",
+ :y_axis_label => "Number of Times Ranked",
+ :x_axis_label => "Rank")
+ send_data(*graph.output)
private
def get_positions_info(election)
buckets = Hash.new
buckets2= Hash.new
private
def get_positions_info(election)
buckets = Hash.new
buckets2= Hash.new
election.candidates.each do |candidate|
buckets[candidate.id] = []
election.candidates.each do |candidate|
buckets[candidate.id] = []
+ election.votes.each do |vote|
+ vote.rankings.size.times do |i|
+ rank_labels[i] = (i+1).to_s
+ end
+ end
+
+ return buckets2.values, rank_labels
# Make a hash, buckets, indexed by time intervals and containing empty arrays
# The time object must come first in addition!
# Make a hash, buckets, indexed by time intervals and containing empty arrays
# The time object must come first in addition!
- # i would start at 0, i+1 goes from 0 up till numcols
+ # i would start at 0, i+1 goes from 1 up till numcols
numcols.times {|i| buckets[starttime + ((i+1)*interval_length)] = []}
# Put votes into bucket according to the time interval to which they belong,
numcols.times {|i| buckets[starttime + ((i+1)*interval_length)] = []}
# Put votes into bucket according to the time interval to which they belong,
<%= image_tag( graph_url( :action => 'votes_per_day', :id => @election ) ) %><br />
<%= image_tag( graph_url( :action => 'votes_per_interval', :id => @election ))%><br />
<%= image_tag( graph_url( :action => 'votes_per_day', :id => @election ) ) %><br />
<%= image_tag( graph_url( :action => 'votes_per_interval', :id => @election ))%><br />
-<%= image_tag( graph_url( :action => 'borda_bar', :id => @election ) ) %>
+<%= image_tag( graph_url( :action => 'borda_bar', :id => @election ) ) %><br />
<%= image_tag( graph_url( :action => 'choices_positions', :id => @election ) ) %>
<%= image_tag( graph_url( :action => 'choices_positions', :id => @election ) ) %>