+class GraphController < ApplicationController
+ class GruffGraff
+
+ def initialize(options)
+ size = "700x400"
+ @graph = options[:graph_type].new(size)
+
+ @graph.theme = { :colors => ['#000000', '#00FFFF', '#FFCC00', '#990033'],
+ :background_colors => ['#74ce00', '#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].is_a?(Hash)
+ options[:data].each_pair do |name, array|
+ @graph.data( name, array)
+ end
+ #if each dataset nameless, will have only multiple arrays
+ elsif 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
+