Class: Nyaplot::Frame
- Inherits:
-
Object
- Object
- Nyaplot::Frame
- Includes:
- Jsonizable
- Defined in:
- lib/nyaplot/frame.rb
Overview
Jsonizable Object which holds Plots (panes) in it.
Instance Method Summary collapse
-
#add(plot) ⇒ Object
Add new pane to the frame.
- #before_to_json ⇒ Object
-
#export_html(path = "./plot.html") ⇒ Object
export static html file.
-
#generate_body ⇒ Object
generate html code for <body> tag.
-
#generate_html ⇒ String
generate static html file.
-
#initialize ⇒ Frame
constructor
A new instance of Frame.
-
#show ⇒ Object
show plot on IRuby notebook.
-
#to_iruby ⇒ Object
show plot automatically on IRuby notebook.
Methods included from Jsonizable
#get_property, included, #init_properties, #set_property, #to_json
Constructor Details
#initialize ⇒ Frame
Returns a new instance of Frame.
12 13 14 15 16 |
# File 'lib/nyaplot/frame.rb', line 12 def initialize init_properties set_property(:panes, []) set_property(:data, {}) end |
Instance Method Details
#add(plot) ⇒ Object
Add new pane to the frame
20 21 22 23 24 25 26 27 |
# File 'lib/nyaplot/frame.rb', line 20 def add(plot) data = get_property(:data) plot.df_list.each do |name| data[name] = DataBase.instance.fetch(name) end panes = get_property(:panes) panes.push(plot) end |
#before_to_json ⇒ Object
66 67 68 |
# File 'lib/nyaplot/frame.rb', line 66 def before_to_json set_property(:extension, Nyaplot.extension_lists) end |
#export_html(path = "./plot.html") ⇒ Object
export static html file
49 50 51 52 53 |
# File 'lib/nyaplot/frame.rb', line 49 def export_html(path="./plot.html") path = File.(path, Dir::pwd) str = generate_html File.write(path, str) end |
#generate_body ⇒ Object
generate html code for <body> tag
30 31 32 33 34 35 36 |
# File 'lib/nyaplot/frame.rb', line 30 def generate_body path = File.("../templates/iruby.erb", __FILE__) template = File.read(path) id = SecureRandom.uuid() model = self.to_json ERB.new(template).result(binding) end |
#generate_html ⇒ String
generate static html file
40 41 42 43 44 45 46 |
# File 'lib/nyaplot/frame.rb', line 40 def generate_html body = generate_body init = Nyaplot.generate_init_code path = File.("../templates/static_html.erb", __FILE__) template = File.read(path) ERB.new(template).result(binding) end |
#show ⇒ Object
show plot on IRuby notebook
62 63 64 |
# File 'lib/nyaplot/frame.rb', line 62 def show IRuby.display(self) end |
#to_iruby ⇒ Object
show plot automatically on IRuby notebook
56 57 58 59 |
# File 'lib/nyaplot/frame.rb', line 56 def to_iruby html = generate_body ['text/html', html] end |