@@ -3,14 +3,16 @@ module Nyaplot
33 # !! Classes to include PlotBase should have #to_json. !!
44 #
55 module Exportable
6+ PATH_NYAPLOT = "https://cdn.rawgit.com/domitry/Nyaplotjs/bb48705474f7878c0a83f267675e019658421b52/release/nyaplot"
7+
68 def raise_display_failed
79 raise "This method works only on IRuby. Use #export_html or install IRuby."
810 end
911
1012 # generate static html file
1113 # @return [String] generated html
12- def generate_html ( to_png = false )
13- path = File . expand_path ( "../templates/iruby.erb" , __FILE__ )
14+ def generate_html ( temp_path )
15+ path = File . expand_path ( temp_path , __FILE__ )
1416 id = SecureRandom . uuid
1517 model = to_json
1618 template = File . read ( path )
@@ -20,8 +22,7 @@ def generate_html(to_png=false)
2022 # export static html file
2123 def export_html ( path = "./plot.html" , to_png = false )
2224 path = File . expand_path ( path , Dir ::pwd )
23- body = generate_html ( to_png )
24-
25+ body = generate_html ( "../templates/iruby.erb" )
2526 temp_path = File . expand_path ( "../templates/static_html.erb" , __FILE__ )
2627 template = File . read ( temp_path )
2728 num = File . write ( path , ERB . new ( template ) . result ( binding ) )
@@ -30,14 +31,14 @@ def export_html(path="./plot.html", to_png=false)
3031
3132 def to_png
3233 raise_display_failed unless defined? IRuby
33- html = generate_html ( true )
34+ html = generate_html ( "../templates/to_png.erb" )
3435 IRuby . display html , mime : 'text/html'
3536 end
3637
3738 # show plot automatically on IRuby notebook
3839 def to_iruby
3940 raise_display_failed unless defined? IRuby
40- html = generate_html
41+ html = generate_html ( "../templates/iruby.erb" )
4142 [ 'text/html' , html ]
4243 end
4344
0 commit comments