Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/nyaplot/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ def self.extension_lists
@@extension_lists
end

def self.init_iruby
raise "IRuby notebook is not loaded." unless defined? IRuby

path = File.expand_path("../templates/init.html.erb", __FILE__)
template = File.read(path)
dep_libraries = @@dep_libraries
html = ERB.new(template).result(binding)
return IRuby.html(html)
end

def self.add_extension(name)
@@extension_lists.push(name)
end

def self.add_dependency(name, url)
@@dep_libraries[name]=url;
end

def self.init_iruby
path = File.expand_path("../templates/init.js.erb", __FILE__)
template = File.read(path)
dep_libraries = @@dep_libraries
js = ERB.new(template).result(binding)
IRuby.display(IRuby.javascript(js))
end

init_iruby if defined? IRuby
end
11 changes: 7 additions & 4 deletions lib/nyaplot/frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,19 @@ def export_html
template = File.read(path)
model = self.to_json
html = ERB.new(template).result(binding)
return html
html
end

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

def show
IRuby.display(self)
end

def configure(&block)
Expand Down
8 changes: 5 additions & 3 deletions lib/nyaplot/plot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ def add_with_df(df, type, *labels)
return diagram
end

def to_iruby
Frame.new.tap {|f| f.add(self) }.to_iruby
end

def show
frame = Frame.new
frame.add(self)
frame.show
Frame.new.tap {|f| f.add(self) }.show
end

def df_list
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<script>
if(window['d3'] === undefined ||
window['Nyaplot'] === undefined){
var path = <%= dep_libraries.to_json %>;
Expand Down Expand Up @@ -36,4 +35,3 @@ end
%>
<%= str %>
}
</script>
3 changes: 2 additions & 1 deletion lib/nyaplot/templates/iruby.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
if(window['Nyaplot']==undefined){
window.addEventListener('load_nyaplot', render, false);
return;
} else {
render();
}
render();
})();
</script>