Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iruby compatibility finished #20

Merged
merged 1 commit into from
Sep 10, 2014
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
18 changes: 18 additions & 0 deletions lib/plotrb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,21 @@ class Object
include ::Plotrb::Kernel

end

if defined? IRuby
IRuby.display(IRuby.javascript(%{
require.config({paths: {
d3: 'http://d3js.org/d3.v3.min',
d3_geo: 'http://trifacta.github.io/vega/lib/d3.geo.projection.min',
topojson: 'http://trifacta.github.io/vega/lib/topojson',
vg: 'http://trifacta.github.io/vega/vega.min'
}});
require(['d3', 'vg', 'd3_geo', 'topojson'], function(d3, vg, d3_geo, topojson) {
window.d3 = d3;
window.vg = vg;
var event = document.createEvent('HTMLEvents');
event.initEvent('load_plotrb',false,false);
window.dispatchEvent(event);
});
}))
end
21 changes: 21 additions & 0 deletions lib/plotrb/visualization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@ def generate_spec(format=nil)
end
end

def to_iruby
['text/html', %{
<div id='vis-#{name}'></div>
<script type='text/javascript'>
$(function() {
function render() {
vg.parse.spec(#{generate_spec}, function(chart) { view = chart({el:'#vis-#{name}'}).update(); });
}
if (typeof window.vg === 'undefined') {
window.addEventListener('load_plotrb', render, false);
} else {
render();
}
});
</script>}]
end

def show
IRuby.display(self)
end

private

def attribute_post_processing
Expand Down