diff --git a/lib/plotrb.rb b/lib/plotrb.rb index 1a500c3..22efeda 100644 --- a/lib/plotrb.rb +++ b/lib/plotrb.rb @@ -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 diff --git a/lib/plotrb/visualization.rb b/lib/plotrb/visualization.rb index 46904ba..881b98a 100644 --- a/lib/plotrb/visualization.rb +++ b/lib/plotrb/visualization.rb @@ -44,6 +44,27 @@ def generate_spec(format=nil) end end + def to_iruby + ['text/html', %{ +
+}] + end + + def show + IRuby.display(self) + end + private def attribute_post_processing