report_html 0.4.6 → 0.5.7

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.
@@ -137,8 +137,7 @@ class Report_html
137
137
  # DATA MANIPULATION METHODS
138
138
  #-------------------------------------------------------------------------------------
139
139
  def get_data(options)
140
- data = []
141
- data = extract_data(options)
140
+ data, smp_attr, var_attr = extract_data(options)
142
141
  if !data.empty?
143
142
  if @data_from_files # If data on container is loaded using html_report as lib, we don't care about data format
144
143
  # if data comes from files and is loaded as strings. We need to format correctly the data.
@@ -155,9 +154,14 @@ class Report_html
155
154
  end
156
155
  end
157
156
  add_header_row_names(data, options)
158
- data = data.transpose if options[:transpose]
157
+ if options[:transpose]
158
+ data = data.transpose
159
+ smp_attr_bkp = smp_attr
160
+ smp_attr = var_attr
161
+ var_attr = smp_attr_bkp
162
+ end
159
163
  end
160
- return data
164
+ return data, smp_attr, var_attr
161
165
  end
162
166
 
163
167
  def add_header_row_names(data, options)
@@ -176,6 +180,8 @@ class Report_html
176
180
 
177
181
  def extract_data(options)
178
182
  data = []
183
+ smp_attr = nil
184
+ var_attr = nil
179
185
  ids = options[:id]
180
186
  fields = options[:fields]
181
187
  ids = ids.split(',') if ids.class == String && ids.include?(',') # String syntax
@@ -193,16 +199,25 @@ class Report_html
193
199
  end
194
200
  else
195
201
  fields = fields.first if fields.class == Array
196
- data = extract_fields(ids, options[:fields])
202
+ smp_attr = process_attributes(extract_fields(ids, options[:smp_attr]), options[:var_attr], aggregated = true) if !options[:smp_attr].nil? && !options[:smp_attr].empty?
203
+ var_attr = process_attributes(extract_rows(ids, options[:var_attr]), options[:smp_attr], aggregated = false) if !options[:var_attr].nil? && !options[:var_attr].empty?
204
+ data = extract_fields(ids, options[:fields], del_fields = options[:smp_attr], del_rows = options[:var_attr])
197
205
  end
198
- return data
206
+ return data, smp_attr, var_attr
199
207
  end
200
208
 
201
- def extract_fields(id, fields)
209
+ def extract_fields(id, fields, del_fields = [], del_rows = [])
202
210
  data = []
203
- @hash_vars[id].each do |row|
211
+ @hash_vars[id].each_with_index do |row, i|
212
+ next if !del_rows.nil? && del_rows.include?(i)
204
213
  if fields.empty?
205
- data << row.dup # Dup generates a array copy that avoids to modify original objects on data manipulation creating graphs
214
+ row = row.dup # Dup generates a array copy that avoids to modify original objects on data manipulation creating graphs
215
+ if !del_fields.nil?
216
+ del_fields.sort.reverse_each do |j|
217
+ row.delete_at(j)
218
+ end
219
+ end
220
+ data << row
206
221
  else
207
222
  data << fields.map{|field| row[field]} #Map without bang do the same than dup
208
223
  end
@@ -210,6 +225,35 @@ class Report_html
210
225
  return data
211
226
  end
212
227
 
228
+ def extract_rows(id, rows)
229
+ table = @hash_vars[id]
230
+ data = rows.map{|field| table[field]}
231
+ return data
232
+ end
233
+
234
+ def process_attributes(attribs, delete_items, aggregated = false)
235
+ parsed_attr = []
236
+ if aggregated
237
+ if !delete_items.nil? && !delete_items.empty?
238
+ (1..delete_items.length).reverse_each do |ind|
239
+ attribs.delete_at(1)
240
+ end
241
+ end
242
+ attribs.first.length.times do |i|
243
+ parsed_attr << attribs.map{|at| at[i]}
244
+ end
245
+ else
246
+ attribs.each do |attrib|
247
+ if !delete_items.nil? && !delete_items.empty?
248
+ (1..delete_items.length).reverse_each do |ind|
249
+ attrib.delete_at(ind)
250
+ end
251
+ end
252
+ parsed_attr << attrib
253
+ end
254
+ end
255
+ return parsed_attr
256
+ end
213
257
  # TABLE METHODS
214
258
  #-------------------------------------------------------------------------------------
215
259
  def table(user_options = {}, &block)
@@ -220,13 +264,15 @@ class Report_html
220
264
  add_header_row_names: false,
221
265
  transpose: false,
222
266
  fields: [],
267
+ smp_attr: [],
268
+ var_attr: [],
223
269
  border: 1,
224
270
  cell_align: [],
225
271
  attrib: {}
226
272
  }
227
273
  options.merge!(user_options)
228
274
  table_attr = prepare_table_attribs(options[:attrib])
229
- array_data = get_data(options)
275
+ array_data, _, _ = get_data(options)
230
276
  block.call(array_data) if !block.nil?
231
277
  rowspan, colspan = get_col_n_row_span(array_data)
232
278
  table_id = 'table_' + @count_objects.to_s
@@ -329,7 +375,7 @@ class Report_html
329
375
  def add_sample_attributes(data_structure, options)
330
376
  parsed_sample_attributes = {}
331
377
  options[:sample_attributes].each do |key, col|
332
- data = get_data({id: options[:id], fields: [col], text: true})
378
+ data, _, _ = get_data({id: options[:id], fields: [col], text: true})
333
379
  data.shift if options[:header]
334
380
  parsed_sample_attributes[key] = data.flatten
335
381
  end
@@ -358,6 +404,9 @@ class Report_html
358
404
  options = {
359
405
  id: nil,
360
406
  fields: [],
407
+ smp_attr: [],
408
+ var_attr: [],
409
+ segregate: [],
361
410
  data_format: 'one_axis',
362
411
  responsive: true,
363
412
  height: '600px',
@@ -386,7 +435,7 @@ class Report_html
386
435
  # Data manipulation
387
436
  #------------------------------------------
388
437
  no_data_string = ERB.new("<div width=\"#{options[:width]}\" height=\"#{options[:height]}\" > <p>NO DATA<p></div>").result(binding)
389
- data_array = get_data(options)
438
+ data_array, smp_attr, var_attr = get_data(options)
390
439
  return no_data_string if data_array.empty?
391
440
  block.call(data_array) if !block.nil?
392
441
  object_id = "obj_#{@count_objects}_"
@@ -402,6 +451,8 @@ class Report_html
402
451
 
403
452
  x = {}
404
453
  z = {}
454
+ add_canvas_attr(x, var_attr) if !var_attr.nil? && !var_attr.empty?
455
+ add_canvas_attr(z, smp_attr) if !smp_attr.nil? && !smp_attr.empty?
405
456
  yield(options, config, samples, vars, values, object_id, x, z)
406
457
  # Build JSON objects and Javascript code
407
458
  #-----------------------------------------------
@@ -426,6 +477,7 @@ class Report_html
426
477
  end
427
478
  add_sample_attributes(data_structure, options) if !options[:sample_attributes].empty?
428
479
  extracode = "#{options[:extracode]}\n"
480
+ extracode << segregate_data("C#{object_id}", options[:segregate]) if !options[:segregate].empty?
429
481
  extracode << "C#{object_id}.groupSamples(#{options[:group_samples]})\n" if !options[:group_samples].nil?
430
482
  plot_data = "
431
483
  var data = #{data_structure.to_json};
@@ -442,6 +494,25 @@ class Report_html
442
494
  return ERB.new(html).result(binding)
443
495
  end
444
496
 
497
+ def segregate_data(obj_id, segregate)
498
+ string =""
499
+ segregate.each do |data_type, names|
500
+ if data_type == :var
501
+ string << "#{obj_id}.segregateVariables(#{names.inspect});\n"
502
+ elsif data_type == :smp
503
+ string << "#{obj_id}.segregateSamples(#{names.inspect});\n"
504
+ end
505
+ end
506
+ return string
507
+ end
508
+
509
+ def add_canvas_attr(hash_attr, attr2add)
510
+ attr2add.each do |attrs|
511
+ attr_name = attrs.shift
512
+ hash_attr[attr_name] = attrs
513
+ end
514
+ end
515
+
445
516
  def line(user_options = {}, &block)
446
517
  default_options = {
447
518
  row_names: true
@@ -505,14 +576,58 @@ class Report_html
505
576
  }.merge!(user_options)
506
577
  html_string = canvasXpress_main(default_options, block) do |options, config, samples, vars, values, object_id, x, z|
507
578
  config['graphType'] = 'Boxplot'
508
- options[:mod_data_structure] = 'boxplot'
509
- if options[:extracode].nil?
579
+ if default_options[:group].nil?
580
+ options[:mod_data_structure] = 'boxplot'
581
+ else
582
+ if default_options[:group].class == String
583
+ reshape(samples, vars, x, values)
584
+ group = default_options[:group]
585
+ series = 'factor'
586
+ else
587
+ series, group = default_options[:group]
588
+ end
589
+ if config["groupingFactors"].nil? # if config is defined, we assume that the user set this property to the value that he/she desires
590
+ if group.nil?
591
+ config["groupingFactors"] = [series]
592
+ else
593
+ config["groupingFactors"] = [series, group]
594
+ end
595
+ end
596
+ config["colorBy"] = series if config["colorBy"].nil?
597
+ config["segregateSamplesBy"] = [group] if !group.nil? && config["segregateSamplesBy"].nil?
598
+ end
599
+ if options[:extracode].nil? && default_options[:group].nil?
510
600
  options[:extracode] = "C#{object_id}.groupSamples([\"Factor\"]);"
511
601
  end
512
602
  end
513
603
  return html_string
514
604
  end
515
605
 
606
+ def reshape(samples, vars, x, values)
607
+ item_names = samples.dup
608
+ (vars.length - 1).times do |n|
609
+ samples.concat(item_names.map{|i| i+"_#{n}"})
610
+ end
611
+ x.each do |factor, annotations|
612
+ current_annotations = annotations.dup
613
+ (vars.length - 1).times do
614
+ annotations.concat(current_annotations)
615
+ end
616
+ end
617
+ series_annot = []
618
+ vars.each do |var|
619
+ item_names.each do
620
+ series_annot << var
621
+ end
622
+ end
623
+ x['factor'] = series_annot
624
+ vars.select!{|v| v.nil?}
625
+ vars << 'vals'
626
+ vals = values.flatten
627
+ values.select!{|v| v.nil?}
628
+ values << vals
629
+ end
630
+
516
631
  def pie(user_options = {}, &block)
517
632
  default_options = {
518
633
  transpose: false
@@ -633,7 +748,7 @@ class Report_html
633
748
  end
634
749
  if !default_options[:links].nil?
635
750
  if !@hash_vars[default_options[:links]].nil? && !@hash_vars[default_options[:links]].empty?
636
- link_data = get_data({id: default_options[:links], fields: [], add_header_row_names: false, text: true, transpose: false})
751
+ link_data, _, _ = get_data({id: default_options[:links], fields: [], add_header_row_names: false, text: true, transpose: false})
637
752
  config['connections'] = assign_rgb(link_data)
638
753
  end
639
754
  end
@@ -1,3 +1,3 @@
1
1
  module ReportHtml
2
- VERSION = "0.4.6"
2
+ VERSION = "0.5.7"
3
3
  end
data/report_html.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["seoanezonjic@hotmail.com"]
11
11
 
12
12
  spec.summary = %q{Gem to build html interactive reports.}
13
- spec.description = %q{Html reports based on erb, HTML5 and javascript libraries.}
13
+ spec.description = %q{iDEPRECATED PROJECT. MIGRATED TO PYTHON: https://github.com/seoanezonjic/py_report_html\n.Html reports based on erb, HTML5 and javascript libraries.}
14
14
  spec.homepage = ""
15
15
  spec.license = "MIT"
16
16
 
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.4.6
4
+ version: 0.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - seoanezonjic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-23 00:00:00.000000000 Z
11
+ date: 2025-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,7 +38,8 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
- description: Html reports based on erb, HTML5 and javascript libraries.
41
+ description: 'iDEPRECATED PROJECT. MIGRATED TO PYTHON: https://github.com/seoanezonjic/py_report_html\n.Html
42
+ reports based on erb, HTML5 and javascript libraries.'
42
43
  email:
43
44
  - seoanezonjic@hotmail.com
44
45
  executables:
@@ -87,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
88
  - !ruby/object:Gem::Version
88
89
  version: '0'
89
90
  requirements: []
90
- rubygems_version: 3.2.15
91
+ rubygems_version: 3.3.7
91
92
  signing_key:
92
93
  specification_version: 4
93
94
  summary: Gem to build html interactive reports.