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



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.expand_path(path, Dir::pwd)
  str = generate_html
  File.write(path, str)
end

#generate_bodyObject

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.expand_path("../templates/iruby.erb", __FILE__)
  template = File.read(path)
  id = SecureRandom.uuid()
  model = self.to_json
  ERB.new(template).result(binding)
end

#generate_htmlString

generate static html file

Returns:

  • (String)

    generated html



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.expand_path("../templates/static_html.erb", __FILE__)
  template = File.read(path)
  ERB.new(template).result(binding)
end

#showObject

show plot on IRuby notebook



62
63
64
# File 'lib/nyaplot/frame.rb', line 62

def show
  IRuby.display(self)
end

#to_irubyObject

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