require 'daru/view'
true
dv = Daru::Vector.new [:a, :a, :a, :b, :b, :c], type: :category
0 | a |
1 | a |
2 | a |
3 | b |
4 | b |
5 | c |
bar_graph1 = Daru::View::Plot.new(dv, type: :bar)
#<Daru::View::Plot:0x000055b945a90e80 @data=#<Daru::Vector(6):category> 0 a 1 a 2 a 3 b 4 b 5 c, @options={:type=>:bar}, @user_options={}, @adapter=Daru::View::Adapter::NyaplotAdapter, @chart=#<Nyaplot::Plot:0x000055b945a838c0 @properties={:diagrams=>[#<Nyaplot::Diagram:0x000055b945a73ec0 @properties={:type=>:bar, :options=>{:x=>"data0", :y=>"data1"}, :data=>"ef23c616-9b53-4bf8-bbe9-c7e3b6aee775"}, @xrange=[:a, :b, :c], @yrange=[0, 3]>], :options=>{}}>>
bar_graph1.init_script
"<!-- TODO : remove the link and use downloaded js -->\n<script src=\"http://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.14/require.min.js\"></script>\n<script>if(window['d3'] === undefined ||\n window['Nyaplot'] === undefined){\n var path = {\"d3\":\"https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min\",\"downloadable\":\"http://cdn.rawgit.com/domitry/d3-downloadable/master/d3-downloadable\"};\n\n\n\n var shim = {\"d3\":{\"exports\":\"d3\"},\"downloadable\":{\"exports\":\"downloadable\"}};\n\n require.config({paths: path, shim:shim});\n\n\nrequire(['d3'], function(d3){window['d3']=d3;console.log('finished loading d3');require(['downloadable'], function(downloadable){window['downloadable']=downloadable;console.log('finished loading downloadable');\n\n\tvar script = d3.select(\"head\")\n\t .append(\"script\")\n\t .attr(\"src\", \"http://cdn.rawgit.com/domitry/Nyaplotjs/master/release/nyaplot.js\")\n\t .attr(\"async\", true);\n\n\tscript[0][0].onload = script[0][0].onreadystatechange = function(){\n\n\n\t var event = document.createEvent(\"HTMLEvents\");\n\t event.initEvent(\"load_nyaplot\",false,false);\n\t window.dispatchEvent(event);\n\t console.log('Finished loading Nyaplotjs');\n\n\t};\n\n\n});});\n}\n</script>\n"
Daru::View.plotting_library = :nyaplot
:nyaplot
bar_graph1.div
"<div id='vis-7bf2244b-8d87-4d6a-91ce-b2f7d3391dd0'></div>\n<script>\n(function(){\n var render = function(){\n var model = {\"panes\":[{\"diagrams\":[{\"type\":\"bar\",\"options\":{\"x\":\"data0\",\"y\":\"data1\"},\"data\":\"ef23c616-9b53-4bf8-bbe9-c7e3b6aee775\"}],\"options\":{\"width\":700,\"xrange\":[\"a\",\"b\",\"c\"],\"yrange\":[0,3]}}],\"data\":{\"ef23c616-9b53-4bf8-bbe9-c7e3b6aee775\":[{\"data0\":\"a\",\"data1\":3},{\"data0\":\"b\",\"data1\":2},{\"data0\":\"c\",\"data1\":1}]},\"extension\":[]}\n var id_name = '#vis-7bf2244b-8d87-4d6a-91ce-b2f7d3391dd0';\n Nyaplot.core.parse(model, id_name);\n\n require(['downloadable'], function(downloadable){\n var svg = d3.select(id_name).select(\"svg\");\n\t if(!svg.empty())\n\t svg.call(downloadable().filename('fig'));\n\t});\n };\n if(window['Nyaplot']==undefined){\n window.addEventListener('load_nyaplot', render, false);\n\treturn;\n } else {\n render();\n }\n})();\n</script>\n"
IRuby.html bar_graph1.div
bar_graph1.show_in_iruby