Class: Report_html
- Inherits:
-
Object
- Object
- Report_html
- Defined in:
- lib/report_html/report_html.rb
Instance Method Summary collapse
- #add_canvas_attr(hash_attr, attr2add) ⇒ Object
- #add_header_row_names(data, options) ⇒ Object
-
#add_sample_attributes(data_structure, options) ⇒ Object
CANVASXPRESS METHODS ————————————————————————————-.
- #assign_rgb(link_data) ⇒ Object
- #barplot(user_options = {}, &block) ⇒ Object
- #boxplot(user_options = {}, &block) ⇒ Object
- #build(template) ⇒ Object
- #build_body ⇒ Object
- #canvasXpress_main(user_options, block = nil) {|options, config, samples, vars, values, object_id, x, z| ... } ⇒ Object
- #circular(user_options = {}, &block) ⇒ Object
- #circular_genome(user_options = {}, &block) ⇒ Object
- #corplot(user_options = {}, &block) ⇒ Object
- #dotplot(user_options = {}, &block) ⇒ Object
-
#embed_img(img_file, img_attribs = nil) ⇒ Object
EMBED FILES.
- #embed_pdf(pdf_file, pdf_attribs = nil) ⇒ Object
- #extract_data(options) ⇒ Object
- #extract_fields(id, fields, del_fields = [], del_rows = []) ⇒ Object
- #extract_rows(id, rows) ⇒ Object
- #get_cell_align(align_vector, position) ⇒ Object
- #get_col_n_row_span(table) ⇒ Object
-
#get_data(options) ⇒ Object
DATA MANIPULATION METHODS ————————————————————————————-.
-
#get_report ⇒ Object
return all html string.
- #get_span(colspan, rowspan, row, col) ⇒ Object
- #heatmap(user_options = {}, &block) ⇒ Object
-
#initialize(hash_vars, title = "report", data_from_files = false) ⇒ Report_html
constructor
A new instance of Report_html.
- #line(user_options = {}, &block) ⇒ Object
- #load_css(css_files) ⇒ Object
- #load_js_libraries(js_libraries) ⇒ Object
- #make_head ⇒ Object
- #pie(user_options = {}, &block) ⇒ Object
- #prepare_table_attribs(attribs) ⇒ Object
- #process_attributes(attribs, delete_items, aggregated = false) ⇒ Object
- #scatterbubble2D(user_options = {}, &block) ⇒ Object
- #sccater2D(user_options = {}, &block) ⇒ Object (also: #scatter2D)
- #segregate_data(obj_id, segregate) ⇒ Object
- #set_tree(options, config) ⇒ Object
- #stacked(user_options = {}, &block) ⇒ Object
-
#table(user_options = {}, &block) ⇒ Object
TABLE METHODS ————————————————————————————-.
- #tree_from_file(file) ⇒ Object
- #write(file) ⇒ Object
Constructor Details
#initialize(hash_vars, title = "report", data_from_files = false) ⇒ Report_html
Returns a new instance of Report_html.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/report_html/report_html.rb', line 9 def initialize(hash_vars, title = "report", data_from_files = false) @all_report = "" @title = title @hash_vars = hash_vars @data_from_files = data_from_files @plots_data = [] @count_objects = 0 @dt_tables = [] #Tables to be styled with the DataTables js lib" @bs_tables = [] #Tables to be styled with the bootstrap js lib" end |
Instance Method Details
#add_canvas_attr(hash_attr, attr2add) ⇒ Object
509 510 511 512 513 514 515 516 |
# File 'lib/report_html/report_html.rb', line 509 def add_canvas_attr(hash_attr, attr2add) attr2add.each do |attrs| attr_name = attrs.shift canvas_attr = [] attrs.each{|at| canvas_attr << "#{attr_name} : #{at}" } hash_attr[attr_name] = canvas_attr end end |
#add_header_row_names(data, options) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/report_html/report_html.rb', line 167 def add_header_row_names(data, ) if [:add_header_row_names] # This check if html object needs a default header/row_names or not if ![:header] range = 0..(data.first.length - 1) data.unshift(range.to_a) end if ![:row_names] data.each_with_index do |row, i| row.unshift(i) end end end end |
#add_sample_attributes(data_structure, options) ⇒ Object
CANVASXPRESS METHODS
375 376 377 378 379 380 381 382 383 |
# File 'lib/report_html/report_html.rb', line 375 def add_sample_attributes(data_structure, ) parsed_sample_attributes = {} [:sample_attributes].each do |key, col| data, _, _ = get_data({id: [:id], fields: [col], text: true}) data.shift if [:header] parsed_sample_attributes[key] = data.flatten end data_structure['x'] = parsed_sample_attributes end |
#assign_rgb(link_data) ⇒ Object
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 |
# File 'lib/report_html/report_html.rb', line 717 def assign_rgb(link_data) colors = { 'red' => [255, 0, 0], 'green' => [0, 255, 0], 'black' => [0, 0, 0], 'yellow' => [255, 255, 0], 'blue' => [0, 0, 255], 'gray' => [128, 128, 128], 'orange' => [255, 165, 0], 'cyan' => [0, 255, 255], 'magenta' => [255, 0, 255] } link_data.each do |link| code = colors[link[0]] if !code.nil? link[0] = "rgb(#{code.join(',')})" else raise "Color link #{link} is not allowed. The allowed color names are: #{colors.keys.join(' ')}" end end end |
#barplot(user_options = {}, &block) ⇒ Object
538 539 540 541 542 543 544 545 546 |
# File 'lib/report_html/report_html.rb', line 538 def ( = {}, &block) = { row_names: true }.merge!() html_string = canvasXpress_main(, block) do |, config, samples, vars, values, object_id, x, z| config['graphType'] = 'Bar' end return html_string end |
#boxplot(user_options = {}, &block) ⇒ Object
574 575 576 577 578 579 580 581 582 583 584 585 586 587 |
# File 'lib/report_html/report_html.rb', line 574 def boxplot( = {}, &block) = { row_names: true, header: true }.merge!() html_string = canvasXpress_main(, block) do |, config, samples, vars, values, object_id, x, z| config['graphType'] = 'Boxplot' [:mod_data_structure] = 'boxplot' if [:extracode].nil? [:extracode] = "C#{object_id}.groupSamples([\"Factor\"]);" end end return html_string end |
#build(template) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/report_html/report_html.rb', line 20 def build(template) renderered_template = ERB.new(template).result(binding) @all_report = "<HTML>\n" make_head build_body do renderered_template end @all_report << "\n</HTML>" end |
#build_body ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/report_html/report_html.rb', line 30 def build_body if !@plots_data.empty? @all_report << "<body onload=\"initPage();\">\n#{yield}\n</body>\n" else @all_report << "<body>\n#{yield}\n</body>\n" end end |
#canvasXpress_main(user_options, block = nil) {|options, config, samples, vars, values, object_id, x, z| ... } ⇒ Object
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
# File 'lib/report_html/report_html.rb', line 401 def canvasXpress_main(, block = nil) # Handle arguments #------------------------------------------ = { id: nil, fields: [], smp_attr: [], var_attr: [], segregate: [], data_format: 'one_axis', responsive: true, height: '600px', width: '600px', header: false, row_names: false, add_header_row_names: true, transpose: true, x_label: 'x_axis', title: 'Title', sample_attributes: {}, config: {}, after_render: [], treeBy: 's' } .merge!() config = { 'toolbarType' => 'under', 'xAxisTitle' => [:x_label], 'title' => [:title] } if ![:tree].nil? set_tree(, config) end config.merge!([:config]) # Data manipulation #------------------------------------------ no_data_string = ERB.new("<div width=\"#{[:width]}\" height=\"#{[:height]}\" > <p>NO DATA<p></div>").result(binding) data_array, smp_attr, var_attr = get_data() return no_data_string if data_array.empty? block.call(data_array) if !block.nil? object_id = "obj_#{@count_objects}_" raise("ID #{[:id]} has not data") if data_array.nil? row_length = data_array.first.length samples = data_array.shift[1..row_length] return no_data_string if data_array.empty? vars = [] data_array.each do |row| vars << row.shift end values = data_array x = {} z = {} add_canvas_attr(x, var_attr) if !var_attr.nil? && !var_attr.empty? add_canvas_attr(z, smp_attr) if !smp_attr.nil? && !smp_attr.empty? yield(, config, samples, vars, values, object_id, x, z) # Build JSON objects and Javascript code #----------------------------------------------- @count_objects += 1 data_structure = { 'y' => { 'vars' => vars, 'smps' => samples, 'data' => values }, 'x' => x, 'z' => z } events = false info = false afterRender = [:after_render] if [:mod_data_structure] == 'boxplot' data_structure['y']['smps'] = nil data_structure.merge!({ 'x' => {'Factor' => samples}}) elsif [:mod_data_structure] == 'circular' data_structure.merge!({ 'z' => {'Ring' => [:ring_assignation]}}) end add_sample_attributes(data_structure, ) if ![:sample_attributes].empty? extracode = "#{[:extracode]}\n" extracode << segregate_data("C#{object_id}", [:segregate]) if ![:segregate].empty? extracode << "C#{object_id}.groupSamples(#{[:group_samples]})\n" if ![:group_samples].nil? plot_data = " var data = #{data_structure.to_json}; var conf = #{config.to_json}; var events = #{events.to_json}; var info = #{info.to_json}; var afterRender = #{afterRender.to_json}; var C#{object_id} = new CanvasXpress(\"#{object_id}\", data, conf, events, info, afterRender);\n#{extracode}" @plots_data << plot_data responsive = '' responsive = "responsive='true'" if [:responsive] html = "<canvas id=\"#{object_id}\" width=\"#{[:width]}\" height=\"#{[:height]}\" aspectRatio='1:1' #{responsive}></canvas>" return ERB.new(html).result(binding) end |
#circular(user_options = {}, &block) ⇒ Object
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 |
# File 'lib/report_html/report_html.rb', line 681 def circular( = {}, &block) = { ring_assignation: [], ringsType: [], ringsWeight: [] }.merge!() html_string = canvasXpress_main(, block) do |, config, samples, vars, values, object_id, x, z| [:mod_data_structure] = 'circular' config['graphType'] = 'Circular' config['segregateVariablesBy'] = ['Ring'] if [:ringsType].empty? config['ringGraphType'] = Array.new(vars.length, 'heatmap') else config['ringGraphType'] = [:ringsType] end if [:ringsWeight].empty? size = 100/vars.length config['ringGraphWeight'] = Array.new(vars.length, size) else config['ringGraphWeight'] = [:ringsWeight] end if [:ring_assignation].empty? [:ring_assignation] = Array.new(vars.length) {|index| (index + 1).to_s} else [:ring_assignation] = [:ring_assignation].map{|item| item.to_s} end if ![:links].nil? if !@hash_vars[[:links]].nil? && !@hash_vars[[:links]].empty? link_data, _, _ = get_data({id: [:links], fields: [], add_header_row_names: false, text: true, transpose: false}) config['connections'] = assign_rgb(link_data) end end end return html_string end |
#circular_genome(user_options = {}, &block) ⇒ Object
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 |
# File 'lib/report_html/report_html.rb', line 739 def circular_genome( = {}, &block) = {}.merge!() coordinates = [:genomic_coordinates] html_string = canvasXpress_main(, block) do |, config, samples, vars, values, object_id, x, z| config['graphType'] = 'Circular' config["arcSegmentsSeparation"] = 3 config["colorScheme"] = "Tableau" config["colors"] = ["#332288","#6699CC","#88CCEE","#44AA99","#117733","#999933","#DDCC77","#661100","#CC6677","#AA4466","#882255","#AA4499"] config["showIdeogram"] = true chr = [] pos = [] = [] vars.each_with_index do |var, i| coord = coordinates[var] if !coord.nil? tag = coord.first.gsub(/[^\dXY]/,'') if tag == 'X' || tag == 'Y' || (tag.to_i > 0 && tag.to_i <= 22) chr << coord.first.gsub(/[^\dXY]/,'') pos << coord.last - 1 else << i end else << i end end .reverse_each{|i| ent = vars.delete_at(i); warn("Feature #{ent} has not valid coordinates")} # Remove entities with invalid coordinates z['chr'] = chr z['pos'] = pos end return html_string end |
#corplot(user_options = {}, &block) ⇒ Object
605 606 607 608 609 610 611 612 613 614 615 |
# File 'lib/report_html/report_html.rb', line 605 def corplot( = {}, &block) = { transpose: false, correlationAxis: 'samples' }.merge!() html_string = canvasXpress_main(, block) do |, config, samples, vars, values, object_id, x, z| config['graphType'] = 'Correlation' config['correlationAxis'] = [:correlationAxis] end return html_string end |
#dotplot(user_options = {}, &block) ⇒ Object
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 |
# File 'lib/report_html/report_html.rb', line 548 def dotplot( = {}, &block) = { row_names: true, connect: false }.merge!() html_string = canvasXpress_main(, block) do |, config, samples, vars, values, object_id, x, z| config['graphType'] = 'Dotplot' if [:connect] config['dotplotType'] = "stacked" config['connectBy'] = "Connect" z[:Connect] = Array.new(vars.length, 1) end end return html_string end |
#embed_img(img_file, img_attribs = nil) ⇒ Object
EMBED FILES
775 776 777 778 779 780 781 |
# File 'lib/report_html/report_html.rb', line 775 def (img_file, img_attribs = nil) img_content = File.open(img_file).read img_base64 = Base64.encode64(img_content) format = File.basename(img_file).split('.').last img_string = "<img #{img_attribs} src=\"data:image/#{format};base64,#{img_base64}\">" return img_string end |
#embed_pdf(pdf_file, pdf_attribs = nil) ⇒ Object
783 784 785 786 787 788 |
# File 'lib/report_html/report_html.rb', line 783 def (pdf_file, pdf_attribs = nil) pdf_content = File.open(pdf_file).read pdf_base64 = Base64.encode64(pdf_content) pdf_string = "<embed #{pdf_attribs} src=\"data:application/pdf;base64,#{pdf_base64}\" type=\"application/pdf\"></embed>" return pdf_string end |
#extract_data(options) ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/report_html/report_html.rb', line 181 def extract_data() data = [] smp_attr = nil var_attr = nil ids = [:id] fields = [:fields] ids = ids.split(',') if ids.class == String && ids.include?(',') # String syntax if ids.class == Array fields = fields.split(';').map{|data_fields| data_fields.split(',').map{|fields| fields.to_i} } if fields.class == String # String syntax ids.each_with_index do |id, n| data_file = extract_fields(id, fields[n]) if data.empty? data.concat(data_file) else data.each_with_index do |row, n| data[n] = row + data_file[n] end end end else fields = fields.first if fields.class == Array smp_attr = process_attributes(extract_fields(ids, [:smp_attr]), [:var_attr], aggregated = true) if ![:smp_attr].nil? && ![:smp_attr].empty? var_attr = process_attributes(extract_rows(ids, [:var_attr]), [:smp_attr], aggregated = false) if ![:var_attr].nil? && ![:var_attr].empty? data = extract_fields(ids, [:fields], del_fields = [:smp_attr], del_rows = [:var_attr]) end return data, smp_attr, var_attr end |
#extract_fields(id, fields, del_fields = [], del_rows = []) ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/report_html/report_html.rb', line 209 def extract_fields(id, fields, del_fields = [], del_rows = []) data = [] @hash_vars[id].each_with_index do |row, i| next if !del_rows.nil? && del_rows.include?(i) if fields.empty? row = row.dup # Dup generates a array copy that avoids to modify original objects on data manipulation creating graphs if !del_fields.nil? del_fields.sort.reverse_each do |j| row.delete_at(j) end end data << row else data << fields.map{|field| row[field]} #Map without bang do the same than dup end end return data end |
#extract_rows(id, rows) ⇒ Object
228 229 230 231 232 |
# File 'lib/report_html/report_html.rb', line 228 def extract_rows(id, rows) table = @hash_vars[id] data = rows.map{|field| table[field]} return data end |
#get_cell_align(align_vector, position) ⇒ Object
353 354 355 356 357 358 359 360 |
# File 'lib/report_html/report_html.rb', line 353 def get_cell_align(align_vector, position) cell_align = '' if !align_vector.empty? align = align_vector[position] cell_align = "align=\"#{align}\"" end return cell_align end |
#get_col_n_row_span(table) ⇒ Object
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/report_html/report_html.rb', line 328 def get_col_n_row_span(table) colspan = [] rowspan = [] last_row = 0 table.each_with_index do |row, r| rowspan << Array.new(row.length, 1) colspan << Array.new(row.length, 1) last_col = 0 row.each_with_index do |col, c| if col == 'colspan' colspan[r][last_col] += 1 else last_col = c end if col == 'rowspan' rowspan[last_row][c] += 1 else last_row = r end end end return rowspan, colspan end |
#get_data(options) ⇒ Object
DATA MANIPULATION METHODS
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/report_html/report_html.rb', line 139 def get_data() data, smp_attr, var_attr = extract_data() if !data.empty? if @data_from_files # If data on container is loaded using html_report as lib, we don't care about data format # if data comes from files and is loaded as strings. We need to format correctly the data. rows = data.length cols = data.first.length if ![:text] rows.times do |r| cols.times do |c| next if r == 0 && [:header] next if c == 0 && [:row_names] data[r][c] = data[r][c].to_f end end end end add_header_row_names(data, ) if [:transpose] data = data.transpose smp_attr_bkp = smp_attr smp_attr = var_attr var_attr = smp_attr_bkp end end return data, smp_attr, var_attr end |
#get_report ⇒ Object
return all html string
122 123 124 125 |
# File 'lib/report_html/report_html.rb', line 122 def get_report #return all html string renderer = ERB.new(@all_report) return renderer.result(binding) #binding does accesible all the current ruby enviroment to erb end |
#get_span(colspan, rowspan, row, col) ⇒ Object
315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/report_html/report_html.rb', line 315 def get_span(colspan, rowspan, row, col) span = [] colspan_value = colspan[row][col] rowspan_value = rowspan[row][col] if colspan_value > 1 span << "colspan=\"#{colspan_value}\"" end if rowspan_value > 1 span << "rowspan=\"#{rowspan_value}\"" end return span.join(' ') end |
#heatmap(user_options = {}, &block) ⇒ Object
564 565 566 567 568 569 570 571 572 |
# File 'lib/report_html/report_html.rb', line 564 def heatmap( = {}, &block) = { row_names: true }.merge!() html_string = canvasXpress_main(, block) do |, config, samples, vars, values, object_id, x, z| config['graphType'] = 'Heatmap' end return html_string end |
#line(user_options = {}, &block) ⇒ Object
518 519 520 521 522 523 524 525 526 |
# File 'lib/report_html/report_html.rb', line 518 def line( = {}, &block) = { row_names: true }.merge!() html_string = canvasXpress_main(, block) do |, config, samples, vars, values, object_id, x, z| config['graphType'] = 'Line' end return html_string end |
#load_css(css_files) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/report_html/report_html.rb', line 47 def load_css(css_files) loaded_css = [] css_files.each do |css_lib| loaded_css << File.open(File.join(JS_FOLDER, css_lib)).read end return loaded_css end |
#load_js_libraries(js_libraries) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/report_html/report_html.rb', line 38 def load_js_libraries(js_libraries) loaded_libraries = [] js_libraries.each do |js_lib| js_file = File.open(File.join(JS_FOLDER, js_lib)).read loaded_libraries << Base64.encode64(js_file) end return loaded_libraries end |
#make_head ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/report_html/report_html.rb', line 55 def make_head @all_report << "\t<title>#{@title}</title> <head> <meta charset=\"utf-8\"> <meta http-equiv=\"CACHE-CONTROL\" CONTENT=\"NO-CACHE\"> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <meta http-equiv=\"Content-Language\" content=\"en-us\" /> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">\n" # ADD JS LIBRARIES AND CSS js_libraries = [] css_files = [] if !@plots_data.empty? js_libraries << 'canvasXpress.min.js' css_files << 'canvasXpress.css' end if !@dt_tables.empty? || !@bs_tables.empty? #Bootstrap for datatables or only for static tables. Use bootstrap version needed by datatables to avoid incompatibility issues @all_report << '<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>'+"\n" end if !@dt_tables.empty? # CDN load, this library is difficult to embed in html file @all_report << '<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.21/css/dataTables.bootstrap.min.css"/>'+"\n" @all_report << '<script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.js"></script>' + "\n" @all_report << '<script type="text/javascript" src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>' + "\n" @all_report << '<script type="text/javascript" src="https://cdn.datatables.net/1.10.21/js/dataTables.bootstrap.min.js"></script>' + "\n" end loaded_js_libraries = load_js_libraries(js_libraries) loaded_css = load_css(css_files) loaded_css.each do |css| @all_report << "<style type=\"text/css\"/> #{css} </style>\n" end loaded_js_libraries.each do |lib| @all_report << "<script src=\"data:application/javascript;base64,#{lib}\" type=\"application/javascript\"></script>\n" end # ADD CUSTOM FUNCTIONS TO USE LOADED JS LIBRARIES #canvasXpress objects if !@plots_data.empty? @all_report << "<script> var initPage = function () { <% @plots_data.each do |plot_data| %> <%= plot_data %> <% end %> } </script>" end #DT tables if !@dt_tables.empty? @all_report << "<script> <% @dt_tables.each do |dt_table| %> $(document).ready(function () { $('#<%= dt_table %>').DataTable(); }); <% end %> </script>\n" end @all_report << "</head>\n" end |
#pie(user_options = {}, &block) ⇒ Object
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 |
# File 'lib/report_html/report_html.rb', line 589 def pie( = {}, &block) = { transpose: false }.merge!() html_string = canvasXpress_main(, block) do |, config, samples, vars, values, object_id, x, z| config['graphType'] = 'Pie' if samples.length > 1 config['showPieGrid'] = true config['xAxis'] = samples config['layout'] = "#{(samples.length.to_f/2).ceil}X2" if config['layout'].nil? config['showPieSampleLabel'] = true if config['showPieSampleLabel'].nil? end end return html_string end |
#prepare_table_attribs(attribs) ⇒ Object
362 363 364 365 366 367 368 369 370 |
# File 'lib/report_html/report_html.rb', line 362 def prepare_table_attribs(attribs) attribs_string = '' if !attribs.empty? attribs.each do |attrib, value| attribs_string << "#{attrib}= \"#{value}\" " end end return attribs_string end |
#process_attributes(attribs, delete_items, aggregated = false) ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/report_html/report_html.rb', line 234 def process_attributes(attribs, delete_items, aggregated = false) parsed_attr = [] if aggregated if !delete_items.nil? && !delete_items.empty? (1..delete_items.length).reverse_each do |ind| attribs.delete_at(1) end end attribs.first.length.times do |i| parsed_attr << attribs.map{|at| at[i]} end else attribs.each do |attrib| if !delete_items.nil? && !delete_items.empty? (1..delete_items.length).reverse_each do |ind| attrib.delete_at(ind) end end parsed_attr << attrib end end return parsed_attr end |
#scatterbubble2D(user_options = {}, &block) ⇒ Object
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 |
# File 'lib/report_html/report_html.rb', line 640 def scatterbubble2D( = {}, &block) = { row_names: true, transpose: false }.merge!() html_string = canvasXpress_main(, block) do |, config, samples, vars, values, object_id, x, z| config['graphType'] = 'ScatterBubble2D' if [:xAxis].nil? config['xAxis'] = [samples[0]] else config['xAxis'] = [:xAxis] end if [:yAxis].nil? config['yAxis'] = [samples[1]] else config['yAxis'] = [:yAxis] end if [:zAxis].nil? config['zAxis'] = [samples[2]] else config['zAxis'] = [:zAxis] end if [:y_label].nil? config['yAxisTitle'] = 'y_axis' else config['yAxisTitle'] = [:y_label] end if [:z_label].nil? config['zAxisTitle'] = 'z_axis' else config['zAxisTitle'] = [:z_label] end if ![:upper_limit].nil? && ![:lower_limit].nil? && ![:ranges].nil? diff = ([:upper_limit] - [:lower_limit]).to_f/[:ranges] sizes = Array.new([:ranges]) {|index| [:lower_limit] + index * diff} config['sizes'] = sizes end end return html_string end |
#sccater2D(user_options = {}, &block) ⇒ Object Also known as: scatter2D
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 |
# File 'lib/report_html/report_html.rb', line 617 def sccater2D( = {}, &block) = { row_names: false, transpose: false }.merge!() html_string = canvasXpress_main(, block) do |, config, samples, vars, values, object_id, x, z| config['graphType'] = 'Scatter2D' config['xAxis'] = [samples.first] if config['xAxis'].nil? config['yAxis'] = samples[1..samples.length-1] if config['yAxis'].nil? if [:y_label].nil? config['yAxisTitle'] = 'y_axis' else config['yAxisTitle'] = [:y_label] end if [:regressionLine] [:extracode] = "C#{object_id}.addRegressionLine();" end end return html_string end |
#segregate_data(obj_id, segregate) ⇒ Object
497 498 499 500 501 502 503 504 505 506 507 |
# File 'lib/report_html/report_html.rb', line 497 def segregate_data(obj_id, segregate) string ="" segregate.each do |data_type, names| if data_type == :var string << "#{obj_id}.segregateVariables(#{names.inspect});\n" elsif data_type == :smp string << "#{obj_id}.segregateSamples(#{names.inspect});\n" end end return string end |
#set_tree(options, config) ⇒ Object
390 391 392 393 394 395 396 397 398 399 |
# File 'lib/report_html/report_html.rb', line 390 def set_tree(, config) tree = tree_from_file([:tree]) if [:treeBy] == 's' config['smpDendrogramNewick'] = tree config['samplesClustered'] = true elsif [:treeBy] == 'v' config['varDendrogramNewick'] = tree config['variablesClustered'] = true end end |
#stacked(user_options = {}, &block) ⇒ Object
528 529 530 531 532 533 534 535 536 |
# File 'lib/report_html/report_html.rb', line 528 def stacked( = {}, &block) = { row_names: true, }.merge!() html_string = canvasXpress_main(, block) do |, config, samples, vars, values, object_id, x, z| config['graphType'] = 'Stacked' end return html_string end |
#table(user_options = {}, &block) ⇒ Object
TABLE METHODS
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/report_html/report_html.rb', line 259 def table( = {}, &block) = { id: nil, header: false, row_names: false, add_header_row_names: false, transpose: false, fields: [], smp_attr: [], var_attr: [], border: 1, cell_align: [], attrib: {} } .merge!() table_attr = prepare_table_attribs([:attrib]) array_data, _, _ = get_data() block.call(array_data) if !block.nil? rowspan, colspan = get_col_n_row_span(array_data) table_id = 'table_' + @count_objects.to_s @dt_tables << table_id if [:styled] == 'dt' @bs_tables << table_id if [:styled] == 'bs' tbody_tag = false html = " <table id=\"#{table_id}\" border=\"#{[:border]}\" #{table_attr}> <% if options[:header] %> <thead> <% end %> <% array_data.each_with_index do |row, i| %> <% if options[:header] && i == 1 %> <tbody> <% end %> <tr> <% row.each_with_index do |cell, j| if cell != 'colspan' && cell != 'rowspan' if i == 0 && options[:header] %> <th <%= get_span(colspan, rowspan, i, j) %>><%= cell %></th> <% else %> <td <%= get_cell_align(options[:cell_align], j) %> <%= get_span(colspan, rowspan, i, j) %>><%= cell %></td> <% end end %> <% end %> </tr> <% if i == 0 && options[:header] %> </thead> <% end %> <% end %> <% if options[:header] %> </tbody> <% end %> </table> " @count_objects += 1 return ERB.new(html).result(binding) end |
#tree_from_file(file) ⇒ Object
385 386 387 388 |
# File 'lib/report_html/report_html.rb', line 385 def tree_from_file(file) string_tree = File.open(file).read.gsub("\n", '') return string_tree end |
#write(file) ⇒ Object
127 128 129 130 131 132 |
# File 'lib/report_html/report_html.rb', line 127 def write(file) #dir = File.dirname(file) string_report = get_report #FileUtils.cp_r(JS_FOLDER, dir) File.open(file, 'w'){|f| f.puts string_report} end |