Class: Nyaplot::Frame

Inherits:
Object
  • Object
show all
Includes:
Jsonizable
Defined in:
lib/nyaplot/frame.rb

Overview

Jsonizable Object which holds Plots (panes) in it.

Instance Method Summary collapse

Methods included from Jsonizable

#get_property, included, #init_properties, #set_property, #to_json

Constructor Details

#initializeFrame

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

Parameters:



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_jsonObject



53
54
55
# File 'lib/nyaplot/frame.rb', line 53

def before_to_json
  set_property(:extension, Nyaplot.extension_lists)
end

#export_htmlString

export static html file

Returns:

  • (String)

    generated html



31
32
33
34
35
36
37
# File 'lib/nyaplot/frame.rb', line 31

def export_html
  path = File.expand_path("../templates/static_html.erb", __FILE__)
  template = File.read(path)
  model = self.to_json
  html = ERB.new(template).result(binding)
  html
end

#showObject

show plot on IRuby notebook



49
50
51
# File 'lib/nyaplot/frame.rb', line 49

def show
  IRuby.display(self)
end

#to_irubyObject

show plot automatically on IRuby notebook



40
41
42
43
44
45
46
# File 'lib/nyaplot/frame.rb', line 40

def to_iruby
  path = File.expand_path("../templates/iruby.erb", __FILE__)
  template = File.read(path)
  id = SecureRandom.uuid()
  model = self.to_json
  ['text/html', ERB.new(template).result(binding)]
end