Module: TDriverReportDataPresentation
- Includes:
- TDriverReportWriter
- Defined in:
- lib/tdriver/report/report_data_presentation.rb
Instance Method Summary collapse
-
#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.
-
#insert_graph_css ⇒ Object
This method inserts the graph specific styles Returns String: String with the <stile> tag to be added to an html page including either the graph or the table provided by this module.
-
#insert_html_graph(data, filename = nil, title = nil, width = nil) ⇒ Object
- This method returns an html img tag to an image with a graph of the data provided 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.
-
#insert_html_table(data, width = nil) ⇒ Object
- This method will create an html table tag with the data provided Arguments data
- Hash: Data to be ploted in the form of => [ value 1, value 2, .., value n] , … width
-
String/Integer: desired width in number of pixels for the table.
Methods included from TDriverReportWriter
#behaviour_log_summary, #copy_code_file_to_test_case_report, #create_behaviour_links, #create_templates_links, #format_behaviour_log, #format_duration, #format_execution_log, #format_user_log_table, #get_java_script, #get_rdoc_for_method, #reporter_link_to_code, #scan_rdoc_file_for_method, #tog_list_begin, #tog_list_end, #write_duration_graph, #write_environment_body, #write_exit_body, #write_navigation_menu, #write_page_end, #write_page_navigation_div, #write_page_start, #write_stack_file_to_html, #write_style_sheet, #write_summary_body, #write_tdriver_log_body, #write_test_case_body, #write_test_case_summary_body
Instance Method Details
#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 |
#insert_graph_css ⇒ Object
This method inserts the graph specific styles Returns String: String with the <stile> tag to be added to an html page including either the graph or the table provided by this module
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/tdriver/report/report_data_presentation.rb', line 110 def insert_graph_css() css = ' <style> table.graph { text-align: center; font-family: Verdana; font-weight: normal; font-size: 11px; color: #404040; width: auto; background-color: #fafafa; border: 1px #6699CC solid; border-collapse: collapse; border-spacing: 0px; } td.tbl_header { border-bottom: 2px solid #6699CC; border-left: 1px solid #6699CC; background-color: #BEC8D1; text-align: left; text-indent: 5px; font-family: Verdana; font-weight: bold; font-size: 11px; color: #404040; } td.tbl_body { border-bottom: 1px solid #9CF; border-top: 0px; border-left: 1px solid #9CF; border-right: 0px; text-align: left; text-indent: 10px; font-family: Verdana, sans-serif, Arial; font-weight: normal; font-size: 11px; color: #404040; background-color: #fafafa; } img.graph {border: 1px solid #9CF; width:auto; height:auto} </style> ' end |
#insert_html_graph(data, filename = nil, title = nil, width = nil) ⇒ Object
This method returns an html img tag to an image with a graph of the data provided 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
- width
-
String/Integer: desired width in number of pixels for the image. Defaults to “auto”
Returns String: String with the <img> tag to be inserted into an html file Exceptions ArgumentError: Thown when data is either nil or the wrong types
74 75 76 77 78 79 |
# File 'lib/tdriver/report/report_data_presentation.rb', line 74 def insert_html_graph( data, filename = nil , title = nil, width = nil ) filename = "graph.png" if filename.nil? title = "Application Start Performance" if title.nil? create_graph_image(data, filename, title) html = "\n<img class='graph' src='#{File.basename(filename)}' style='width:#{ width.nil? ? 'auto' : width.to_s + 'px' }'/>\n" end |
#insert_html_table(data, width = nil) ⇒ Object
This method will create an html table tag with the data provided Arguments
- data
-
Hash: Data to be ploted in the form of => [ value 1, value 2, .., value n] , …
- width
-
String/Integer: desired width in number of pixels for the table. Defaults to “auto”
Returns String: String with the <table> tag to be inserted into an html file Exceptions
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/tdriver/report/report_data_presentation.rb', line 89 def insert_html_table( data, width = nil ) raise ArgumentError, "Data argument is either nul or not a Hash" if ( data.nil? or data.class.to_s != "Hash" ) html = "\n<table class='graph' style='width:#{ width.nil? ? 'auto' : width.to_s + 'px' }'>" # table headers ( data[data.keys[0]].length + 1).times do |i| html << ( i.zero? ? "\n<td class='tbl_header'>Signal/Event</td>" : "\n<td class='tbl_header'>#{i.to_s}</td>") end # table data data.each_key do |signal| html << "\n<tr>\n<td>#{signal}</td>" data[signal].each do |value| html << "\n<td class='tbl_body'>#{value.to_s}</td>" end html << "\n</tr>" end html << "\n</table>\n" end |