Skip to content

Commit 2c16e61

Browse files
committed
Add Frame#to_iruby, Plot#to_iruby
- This allows automatic plotting by just returning the Plot/Frame object - Plot#show and Frame#show calls IRuby#display
1 parent c8a4df0 commit 2c16e61

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

lib/nyaplot/frame.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,19 @@ def export_html
2727
template = File.read(path)
2828
model = self.to_json
2929
html = ERB.new(template).result(binding)
30-
return html
30+
html
3131
end
3232

33-
def show
33+
def to_iruby
3434
path = File.expand_path("../templates/iruby.erb", __FILE__)
3535
template = File.read(path)
3636
id = SecureRandom.uuid()
3737
model = self.to_json
38-
html = ERB.new(template).result(binding)
39-
return IRuby.html(html)
38+
['text/html', ERB.new(template).result(binding)]
39+
end
40+
41+
def show
42+
IRuby.display(self)
4043
end
4144

4245
def configure(&block)

lib/nyaplot/plot.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ def add_with_df(df, type, *labels)
2727
return diagram
2828
end
2929

30+
def to_iruby
31+
Frame.new.tap {|f| f.add(self) }.to_iruby
32+
end
33+
3034
def show
31-
frame = Frame.new
32-
frame.add(self)
33-
frame.show
35+
Frame.new.tap {|f| f.add(self) }.show
3436
end
3537

3638
def df_list

lib/nyaplot/templates/iruby.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
if(window['Nyaplot']==undefined){
99
window.addEventListener('load_nyaplot', render, false);
1010
return;
11+
} else {
12+
render();
1113
}
12-
render();
1314
})();
1415
</script>

0 commit comments

Comments
 (0)