+
+ class GruffGraff
+
+ def initialize(options)
+ size = "700x400"
+ @graph = options[:graph_type].new(size)
+
+ @graph.theme = { :background_colors => ['#73BF26', '#ffffff'] }
+ @graph.font = File.expand_path('/usr/X11R6/lib/X11/fonts/TTF/Vera.ttf',
+ 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] )
+ end
+
+ # set the labels or create an empty hash
+ @graph.labels = options[:interval_labels] \
+ if options.has_key?(:interval_labels) and \
+ options[:interval_labels].class == Hash
+ @graph.x_axis_label = options[:x_axis_label] \
+ if options.has_key?(:x_axis_label)
+ @graph.y_axis_label = options[:y_axis_label] \
+ if options.has_key?(:y_axis_label)
+ @graph.title = options[:title] if options.has_key?(:title)
+
+ @graph.minimum_value = 0.0
+
+ end
+
+ def output
+ return([@graph.to_blob, {:disposition => 'inline', :type => 'image/png'}])
+ end
+
+ end
+