class Nyaplot::Frame

Jsonizable Object which holds Plots (panes) in it.

Public Class Methods

new() click to toggle source
# File lib/nyaplot/frame.rb, line 12
def initialize
  init_properties
  set_property(:panes, [])
  set_property(:data, {})
end

Public Instance Methods

add(plot) click to toggle source

Add new pane to the frame @param [Nyaplot::Plot] the pane to add

# 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() click to toggle source
# File lib/nyaplot/frame.rb, line 66
def before_to_json
  set_property(:extension, Nyaplot.extension_lists)
end
export_html(path="./plot.html") click to toggle source

export static html file

# 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_body() click to toggle source

generate html code for <body> tag

# 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_html() click to toggle source

generate static html file @return [String] generated html

# 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
show() click to toggle source

show plot on IRuby notebook

# File lib/nyaplot/frame.rb, line 62
def show
  IRuby.display(self)
end
to_iruby() click to toggle source

show plot automatically on IRuby notebook

# File lib/nyaplot/frame.rb, line 56
def to_iruby
  html = generate_body
  ['text/html', html]
end