report_html 0.3.4 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,6 +13,8 @@ class Report_html
13
13
  @data_from_files = data_from_files
14
14
  @plots_data = []
15
15
  @count_objects = 0
16
+ @dt_tables = [] #Tables to be styled with the DataTables js lib"
17
+ @bs_tables = [] #Tables to be styled with the bootstrap js lib"
16
18
  end
17
19
 
18
20
  def build(template)
@@ -26,26 +28,95 @@ class Report_html
26
28
  end
27
29
 
28
30
  def build_body
29
- @all_report << "<body onload=\"initPage();\">\n#{yield}\n</body>\n"
31
+ if !@plots_data.empty?
32
+ @all_report << "<body onload=\"initPage();\">\n#{yield}\n</body>\n"
33
+ else
34
+ @all_report << "<body>\n#{yield}\n</body>\n"
35
+ end
36
+ end
37
+
38
+ def load_js_libraries(js_libraries)
39
+ loaded_libraries = []
40
+ js_libraries.each do |js_lib|
41
+ js_file = File.open(File.join(JS_FOLDER, js_lib)).read
42
+ loaded_libraries << Base64.encode64(js_file)
43
+ end
44
+ return loaded_libraries
45
+ end
46
+
47
+ def load_css(css_files)
48
+ loaded_css = []
49
+ css_files.each do |css_lib|
50
+ loaded_css << File.open(File.join(JS_FOLDER, css_lib)).read
51
+ end
52
+ return loaded_css
30
53
  end
31
54
 
32
55
  def make_head
33
56
  @all_report << "\t<title>#{@title}</title>
34
57
  <head>
58
+ <meta charset=\"utf-8\">
35
59
  <meta http-equiv=\"CACHE-CONTROL\" CONTENT=\"NO-CACHE\">
36
60
  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
37
61
  <meta http-equiv=\"Content-Language\" content=\"en-us\" />
62
+ <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">\n"
63
+
64
+ # ADD JS LIBRARIES AND CSS
65
+ js_libraries = []
66
+ css_files = []
67
+ if !@plots_data.empty?
68
+ js_libraries << 'canvasXpress.min.js'
69
+ css_files << 'canvasXpress.css'
70
+ end
71
+
72
+ 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
73
+ @all_report << '<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>'+"\n"
74
+ end
38
75
 
39
- <link rel=\"stylesheet\" href=\"js/canvasXpress.css\" type=\"text/css\"/>
40
- <script type=\"text/javascript\" src=\"js/canvasXpress.min.js\"></script>
41
- <script>
42
- var initPage = function () {
43
- <% @plots_data.each do |plot_data| %>
44
- <%= plot_data %>
45
- <% end %>
46
- }
47
- </script>
48
- </head>\n"
76
+ if !@dt_tables.empty? # CDN load, this library is difficult to embed in html file
77
+ @all_report << '<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.21/css/dataTables.bootstrap.min.css"/>'+"\n"
78
+ @all_report << '<script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.js"></script>' + "\n"
79
+ @all_report << '<script type="text/javascript" src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>' + "\n"
80
+ @all_report << '<script type="text/javascript" src="https://cdn.datatables.net/1.10.21/js/dataTables.bootstrap.min.js"></script>' + "\n"
81
+ end
82
+
83
+ loaded_js_libraries = load_js_libraries(js_libraries)
84
+ loaded_css = load_css(css_files)
85
+ loaded_css.each do |css|
86
+ @all_report << "<style type=\"text/css\"/>
87
+ #{css}
88
+ </style>\n"
89
+ end
90
+ loaded_js_libraries.each do |lib|
91
+ @all_report << "<script src=\"data:application/javascript;base64,#{lib}\" type=\"application/javascript\"></script>\n"
92
+ end
93
+
94
+ # ADD CUSTOM FUNCTIONS TO USE LOADED JS LIBRARIES
95
+ #canvasXpress objects
96
+ if !@plots_data.empty?
97
+ @all_report << "<script>
98
+ var initPage = function () {
99
+ <% @plots_data.each do |plot_data| %>
100
+ <%= plot_data %>
101
+ <% end %>
102
+ }
103
+ </script>"
104
+ end
105
+
106
+ #DT tables
107
+ if !@dt_tables.empty?
108
+ @all_report << "<script>
109
+ <% @dt_tables.each do |dt_table| %>
110
+ $(document).ready(function () {
111
+ $('#<%= dt_table %>').DataTable();
112
+ });
113
+
114
+ <% end %>
115
+ </script>\n"
116
+ end
117
+
118
+
119
+ @all_report << "</head>\n"
49
120
  end
50
121
 
51
122
  def get_report #return all html string
@@ -54,9 +125,9 @@ class Report_html
54
125
  end
55
126
 
56
127
  def write(file)
57
- dir = File.dirname(file)
128
+ #dir = File.dirname(file)
58
129
  string_report = get_report
59
- FileUtils.cp_r(JS_FOLDER, dir)
130
+ #FileUtils.cp_r(JS_FOLDER, dir)
60
131
  File.open(file, 'w'){|f| f.puts string_report}
61
132
  end
62
133
 
@@ -158,9 +229,19 @@ class Report_html
158
229
  array_data = get_data(options)
159
230
  block.call(array_data) if !block.nil?
160
231
  rowspan, colspan = get_col_n_row_span(array_data)
232
+ table_id = 'table_' + @count_objects.to_s
233
+ @dt_tables << table_id if options[:styled] == 'dt'
234
+ @bs_tables << table_id if options[:styled] == 'bs'
235
+ tbody_tag = false
161
236
  html = "
162
- <table border=\"#{options[:border]}\" #{table_attr}>
237
+ <table id=\"#{table_id}\" border=\"#{options[:border]}\" #{table_attr}>
238
+ <% if options[:header] %>
239
+ <thead>
240
+ <% end %>
163
241
  <% array_data.each_with_index do |row, i| %>
242
+ <% if options[:header] && i == 1 %>
243
+ <tbody>
244
+ <% end %>
164
245
  <tr>
165
246
  <% row.each_with_index do |cell, j|
166
247
  if cell != 'colspan' && cell != 'rowspan'
@@ -172,9 +253,16 @@ class Report_html
172
253
  end %>
173
254
  <% end %>
174
255
  </tr>
256
+ <% if i == 0 && options[:header] %>
257
+ </thead>
258
+ <% end %>
259
+ <% end %>
260
+ <% if options[:header] %>
261
+ </tbody>
175
262
  <% end %>
176
263
  </table>
177
264
  "
265
+ @count_objects += 1
178
266
  return ERB.new(html).result(binding)
179
267
  end
180
268
 
@@ -287,7 +375,7 @@ class Report_html
287
375
  }
288
376
  options.merge!(user_options)
289
377
  config = {
290
- 'toolbarPermanent' => true,
378
+ 'toolbarType' => 'under',
291
379
  'xAxisTitle' => options[:x_label],
292
380
  'title' => options[:title]
293
381
  }
@@ -442,6 +530,8 @@ class Report_html
442
530
  return html_string
443
531
  end
444
532
 
533
+ alias scatter2D sccater2D # Fix for wrong name method
534
+
445
535
  def scatterbubble2D(user_options = {}, &block)
446
536
  default_options = {
447
537
  row_names: true,
@@ -494,15 +584,15 @@ class Report_html
494
584
  config['graphType'] = 'Circular'
495
585
  config['segregateVariablesBy'] = ['Ring']
496
586
  if default_options[:ringsType].empty?
497
- config['ringsType'] = Array.new(vars.length, 'heatmap')
587
+ config['ringGraphType'] = Array.new(vars.length, 'heatmap')
498
588
  else
499
- config['ringsType'] = default_options[:ringsType]
589
+ config['ringGraphType'] = default_options[:ringsType]
500
590
  end
501
591
  if default_options[:ringsWeight].empty?
502
592
  size = 100/vars.length
503
- config['ringsWeight'] = Array.new(vars.length, size)
593
+ config['ringGraphWeight'] = Array.new(vars.length, size)
504
594
  else
505
- config['ringsWeight'] = default_options[:ringsWeight]
595
+ config['ringGraphWeight'] = default_options[:ringsWeight]
506
596
  end
507
597
  if default_options[:ring_assignation].empty?
508
598
  options[:ring_assignation] = Array.new(vars.length) {|index| (index + 1).to_s}
@@ -1,3 +1,3 @@
1
1
  module ReportHtml
2
- VERSION = "0.3.4"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: report_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - seoanezonjic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-12 00:00:00.000000000 Z
11
+ date: 2020-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -62,8 +62,9 @@ files:
62
62
  - bin/report_html
63
63
  - bin/setup
64
64
  - js/canvasXpress.css
65
- - js/canvasXpress.js
65
+ - js/canvasXpress.css_old
66
66
  - js/canvasXpress.min.js
67
+ - js/canvasXpress.min.js_old
67
68
  - js/canvasXpress_license
68
69
  - lib/report_html.rb
69
70
  - lib/report_html/report_html.rb
@@ -89,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
90
  version: '0'
90
91
  requirements: []
91
92
  rubyforge_project:
92
- rubygems_version: 2.4.8
93
+ rubygems_version: 2.6.14
93
94
  signing_key:
94
95
  specification_version: 4
95
96
  summary: Gem to build html interactive reports.
@@ -1,55 +0,0 @@
1
- HTMLWidgets.widget({
2
-
3
- name : "canvasXpress",
4
-
5
- type : "output",
6
-
7
- initialize : function(el, width, height) {
8
-
9
- // Create a sized canvas element for the CanvasXpress instance
10
-
11
- var c = document.createElement('canvas');
12
-
13
- c.id = el.id + '-cx';
14
- c.width = width;
15
- c.height = height;
16
-
17
- // Append it to the element
18
-
19
- el.appendChild(c);
20
-
21
- // Return the id where the canvas will be initialized
22
-
23
- return {
24
- id : c.id
25
- };
26
-
27
- },
28
-
29
- renderValue : function(el, x, instance) {
30
-
31
- var cx = CanvasXpress && instance ? CanvasXpress.getObject(instance.id) : false;
32
-
33
- // Remove the CanvasXpress object if it exists
34
-
35
- if (cx) {
36
- cx.destroy(instance.id);
37
- }
38
-
39
- x.renderTo = instance.id;
40
-
41
- cx = new CanvasXpress(x);
42
-
43
- },
44
-
45
- resize : function(el, width, height, instance) {
46
-
47
- var cx = CanvasXpress && instance ? CanvasXpress.getObject(instance.id) : false;
48
-
49
- if (cx) {
50
- cx.setDimensions(width, height);
51
- }
52
-
53
- }
54
-
55
- });