Method: TDriverReportDataPresentation#create_graph_image
- Defined in:
- lib/tdriver/report/report_data_presentation.rb
#create_graph_image(data, filename, title = nil) ⇒ Object
This method will create a .png image with a graph Arguments
- data
-
Hash: Data to be ploted in the form of => [ value 1, value 2, .., value n] , …
- filename
-
String: filname for the image that will be generated. Should have .png extension
- title
-
String: Title for the graph
Returns String: String with the <img> tag to be inserted into an html file Exceptions ArgumentError: Thown when data or filname provided are either nil or the wrong types
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/tdriver/report/report_data_presentation.rb', line 34 def create_graph_image( data, filename, title = nil) begin require 'gruff' rescue Exception => e puts "Can't load the Gruff gem. If its missing from your system please run 'gem install gruff' to install it." puts e.inspect end begin raise TypeError, "ERROR create_graph_image: Data argument is either nil or not a Hash" if ( data.nil? or !data.kind_of? Hash ) raise ArgumentError, "ERROR create_graph_image: Values of the data Hash need to be arrays of minimum length 2" if ( !data.values[0].kind_of? Array or data.values[0].length < 2 ) raise TypeError, "ERROR create_graph_image: Filename argument is either missing or not a String" if ( filename.nil? or !filename.kind_of? String ) g = Gruff::Line.new g.title = title unless title.nil? data.each_key do |signal| g.data( signal, data[signal]) end # boring labels for now #data[data.keys[0]].length.times do |i| # g.labels[i] = (i + 1).to_s #end g.write(filename) rescue ArgumentError => e puts e. end end |