Class: Daru::View::PlotList
- Inherits:
-
Object
- Object
- Daru::View::PlotList
- Defined in:
- lib/daru/view/plot_list.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
-
#div ⇒ String
Generates html code to include in body tag.
-
#export_html_file(path = './plot.html') ⇒ void
Writes a html file to disk.
-
#initialize(data = []) ⇒ void
constructor
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]).
-
#show_in_iruby ⇒ void
Display in IRuby notebook.
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])
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
#data ⇒ Object (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
#div ⇒ String
Returns 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.('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.(path, Dir.pwd) str = generate_html File.write(path, str) end |
#show_in_iruby ⇒ void
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 |