nyaplot 0.1.6 → 0.2.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/nyaplot/frame.rb DELETED
@@ -1,70 +0,0 @@
1
- require 'erb'
2
- require 'securerandom'
3
-
4
- module Nyaplot
5
-
6
- # Jsonizable Object which holds Plots (panes) in it.
7
- class Frame
8
- include Jsonizable
9
-
10
- define_properties(:data, :panes, :extension)
11
-
12
- def initialize
13
- init_properties
14
- set_property(:panes, [])
15
- set_property(:data, {})
16
- end
17
-
18
- # Add new pane to the frame
19
- # @param [Nyaplot::Plot] the pane to add
20
- def add(plot)
21
- data = get_property(:data)
22
- plot.df_list.each do |name|
23
- data[name] = DataBase.instance.fetch(name)
24
- end
25
- panes = get_property(:panes)
26
- panes.push(plot)
27
- end
28
-
29
- # generate html code for <body> tag
30
- def generate_body
31
- path = File.expand_path("../templates/iruby.erb", __FILE__)
32
- template = File.read(path)
33
- id = SecureRandom.uuid()
34
- model = self.to_json
35
- ERB.new(template).result(binding)
36
- end
37
-
38
- # generate static html file
39
- # @return [String] generated html
40
- def generate_html
41
- body = generate_body
42
- init = Nyaplot.generate_init_code
43
- path = File.expand_path("../templates/static_html.erb", __FILE__)
44
- template = File.read(path)
45
- ERB.new(template).result(binding)
46
- end
47
-
48
- # export static html file
49
- def export_html(path="./plot.html")
50
- path = File.expand_path(path, Dir::pwd)
51
- str = generate_html
52
- File.write(path, str)
53
- end
54
-
55
- # show plot automatically on IRuby notebook
56
- def to_iruby
57
- html = generate_body
58
- ['text/html', html]
59
- end
60
-
61
- # show plot on IRuby notebook
62
- def show
63
- IRuby.display(self)
64
- end
65
-
66
- def before_to_json
67
- set_property(:extension, Nyaplot.extension_lists)
68
- end
69
- end
70
- end