Class: Daru::View::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/daru/view/table.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = [], options = {}, user_options = {}) ⇒ Table

TODO: modify the examples df = Daru::DataFrame.new(‘B’, ‘C’, ‘D’, ‘E’], b:) Daru::View::Plot.new df, type: :bar, x: :a, y: :b

Set the new adapter(plotting library) ,for example highcharts:

Daru::View.plotting_library = :highcharts

To use a particular apdater in certain plot object(s), then user must pass the adapter in ‘options` hash. e.g. `adapter: :highcharts`



39
40
41
42
43
44
45
# File 'lib/daru/view/table.rb', line 39

def initialize(data=[], options={}, user_options={})
  @data = data
  @options = options
  @user_options = user_options
  self.adapter = options.delete(:adapter) unless options[:adapter].nil?
  @table = table_data(data, options, user_options)
end

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



5
6
7
# File 'lib/daru/view/table.rb', line 5

def adapter
  @adapter
end

#dataObject (readonly)

Returns the value of attribute data.



4
5
6
# File 'lib/daru/view/table.rb', line 4

def data
  @data
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/daru/view/table.rb', line 4

def options
  @options
end

#tableObject (readonly)

Returns the value of attribute table.



4
5
6
# File 'lib/daru/view/table.rb', line 4

def table
  @table
end

#user_optionsObject (readonly)

Returns the value of attribute user_options.



4
5
6
# File 'lib/daru/view/table.rb', line 4

def user_options
  @user_options
end

Class Method Details

.adapter=(adapter) ⇒ Object

class method

Daru::View::Table.adapter = :new_library



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/daru/view/table.rb', line 12

def adapter=(adapter)
  # The library wrapper method for generating table is in the
  # same folder as the plotting library. Since google chart can be
  # used for plotting charts as well as table.
  #
  require "daru/view/adapters/#{adapter}"
  # rubocop:disable Style/ClassVars
  @@adapter = Daru::View::Adapter.const_get(
    adapter.to_s.capitalize + 'Adapter'
  )
  # rubocop:enable Style/ClassVars
end

Instance Method Details

#divObject

generate html code, to include in body tag



74
75
76
# File 'lib/daru/view/table.rb', line 74

def div
  @adapter.generate_body(@table)
end

#export_html_file(path = './plot.html') ⇒ Object

generat html file



79
80
81
# File 'lib/daru/view/table.rb', line 79

def export_html_file(path='./plot.html')
  @adapter.export_html_file(@table, path)
end

#init_irubyObject

load the corresponding JS files in IRuby notebook. This is done automatically when plotting library is set using Daru::View.plotting_library = :new_library



86
87
88
# File 'lib/daru/view/table.rb', line 86

def init_iruby
  @adapter.init_iruby
end

#init_scriptObject

dependent js file, to include in head tag using the plot object. @example: plot_obj.init_script

Note : User can directly put the dependent script file into the head tag using ‘Daru::View.dependent_script(:highcharts), by default it loads Nyaplot JS files.



69
70
71
# File 'lib/daru/view/table.rb', line 69

def init_script
  @adapter.init_script
end

#show_in_irubyObject

display in IRuby notebook



56
57
58
# File 'lib/daru/view/table.rb', line 56

def show_in_iruby
  @adapter.show_in_iruby @table
end