Class: Daru::View::PlotList

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = []) ⇒ void

df = Daru::DataFrame.new(‘B’, ‘C’, ‘D’, ‘E’], b:) plot1 = Daru::View::Plot.new(

df, type: :bar, x: :a, y: :b, adapter: :googlecharts

) plot2 = Daru::View::Plot.new(

df, chart: { type: 'line' }, adapter: :highcharts

) plots = Daru::View::PlotList.new([plot1, plot2])

Parameters:



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/daru/view/plot_list.rb', line 28

def initialize(data=[])
  unless data.is_a?(Array) && data.all? { |plot|
           plot.is_a?(Daru::View::Plot) ||
           plot.is_a?(Daru::View::Table)
         }
    raise ArgumentError, 'Invalid Argument Passed! Valid Arguments '\
                         'consists an Array of: Daru::View::Plot or '\
                         'Daru::View::Table (Right now, it is not '\
                         'implemented for DataTables)'
  end
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



13
14
15
# File 'lib/daru/view/plot_list.rb', line 13

def data
  @data
end

Instance Method Details

#divString

Returns generates html code to include in body tag.

Returns:

  • (String)

    generates html code to include in body tag



47
48
49
50
51
52
53
# File 'lib/daru/view/plot_list.rb', line 47

def div
  path = File.expand_path('templates/multiple_charts_div.erb', __dir__)
  template = File.read(path)
  charts_id_div_tag = []
  charts_script = extract_charts_script(charts_id_div_tag)
  ERB.new(template).result(binding)
end

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

This method returns an undefined value.

Returns writes a html file to disk.



56
57
58
59
60
# File 'lib/daru/view/plot_list.rb', line 56

def export_html_file(path='./plot.html')
  path = File.expand_path(path, Dir.pwd)
  str = generate_html
  File.write(path, str)
end

#show_in_irubyvoid

This method returns an undefined value.

Returns display in IRuby notebook.



42
43
44
# File 'lib/daru/view/plot_list.rb', line 42

def show_in_iruby
  IRuby.html(div)
end