{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\n", "Install the spreadsheet gem version ~>1.1.1 for using spreadsheet functions.\n", "\n", "Install the mechanize gem version ~>2.7.5 for using mechanize functions.\n" ] }, { "data": { "text/plain": [ "true" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "require 'daru/view'" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "<table>\n", " <tr>\n", " <th colspan=\"2\">Daru::Vector(6):category</th>\n", " </tr>\n", " \n", "\n", " \n", " <tr>\n", " <td>0</td>\n", " <td>a</td>\n", " </tr>\n", " \n", " <tr>\n", " <td>1</td>\n", " <td>a</td>\n", " </tr>\n", " \n", " <tr>\n", " <td>2</td>\n", " <td>a</td>\n", " </tr>\n", " \n", " <tr>\n", " <td>3</td>\n", " <td>b</td>\n", " </tr>\n", " \n", " <tr>\n", " <td>4</td>\n", " <td>b</td>\n", " </tr>\n", " \n", " <tr>\n", " <td>5</td>\n", " <td>c</td>\n", " </tr>\n", " \n", "\n", " \n", "</table>" ], "text/plain": [ "#<Daru::Vector(6):cataegory>\n", " 0 a\n", " 1 a\n", " 2 a\n", " 3 b\n", " 4 b\n", " 5 c" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv = Daru::Vector.new [:a, :a, :a, :b, :b, :c], type: :category" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "#<Daru::View::Plot:0x007fec6723b738 @data=#<Daru::Vector(6):cataegory>\n", " 0 a\n", " 1 a\n", " 2 a\n", " 3 b\n", " 4 b\n", " 5 c, @options={:type=>:bar, :method=>:count}, @adapter=Daru::View::Adapter::NyaplotAdapter, @chart=#<Nyaplot::Plot:0x007fec6723b5f8 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fec67239a50 @properties={:type=>:bar, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"5f227022-dd7d-42e0-8645-1b60c76507a0\"}, @xrange=[:a, :b, :c], @yrange=[0, 3]>], :options=>{}}>>" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar_graph1 = Daru::View::Plot.new(dv, type: :bar)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "\"<!-- 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\"" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar_graph1.init_script" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ ":nyaplot" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Daru::View.plotting_library" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "\"<div id='vis-62a99d20-bf77-4dfd-ab69-4ecfd51789d3'></div>\\n<script>\\n(function(){\\n var render = function(){\\n var model = {\\\"panes\\\":[{\\\"diagrams\\\":[{\\\"type\\\":\\\"bar\\\",\\\"options\\\":{\\\"x\\\":\\\"data0\\\",\\\"y\\\":\\\"data1\\\"},\\\"data\\\":\\\"5f227022-dd7d-42e0-8645-1b60c76507a0\\\"}],\\\"options\\\":{\\\"width\\\":700,\\\"xrange\\\":[\\\"a\\\",\\\"b\\\",\\\"c\\\"],\\\"yrange\\\":[0,3]}}],\\\"data\\\":{\\\"5f227022-dd7d-42e0-8645-1b60c76507a0\\\":[{\\\"data0\\\":\\\"a\\\",\\\"data1\\\":3},{\\\"data0\\\":\\\"b\\\",\\\"data1\\\":2},{\\\"data0\\\":\\\"c\\\",\\\"data1\\\":1}]},\\\"extension\\\":[]}\\n var id_name = '#vis-62a99d20-bf77-4dfd-ab69-4ecfd51789d3';\\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\"" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar_graph1.div" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "<div id='vis-e8a98398-dcab-449a-ab21-4c21dfcc43cd'></div>\n", "<script>\n", "(function(){\n", " var render = function(){\n", " var model = {\"panes\":[{\"diagrams\":[{\"type\":\"bar\",\"options\":{\"x\":\"data0\",\"y\":\"data1\"},\"data\":\"5f227022-dd7d-42e0-8645-1b60c76507a0\"}],\"options\":{\"width\":700,\"xrange\":[\"a\",\"b\",\"c\"],\"yrange\":[0,3]}}],\"data\":{\"5f227022-dd7d-42e0-8645-1b60c76507a0\":[{\"data0\":\"a\",\"data1\":3},{\"data0\":\"b\",\"data1\":2},{\"data0\":\"c\",\"data1\":1}]},\"extension\":[]}\n", " var id_name = '#vis-e8a98398-dcab-449a-ab21-4c21dfcc43cd';\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" ], "text/plain": [ "\"<div id='vis-e8a98398-dcab-449a-ab21-4c21dfcc43cd'></div>\\n<script>\\n(function(){\\n var render = function(){\\n var model = {\\\"panes\\\":[{\\\"diagrams\\\":[{\\\"type\\\":\\\"bar\\\",\\\"options\\\":{\\\"x\\\":\\\"data0\\\",\\\"y\\\":\\\"data1\\\"},\\\"data\\\":\\\"5f227022-dd7d-42e0-8645-1b60c76507a0\\\"}],\\\"options\\\":{\\\"width\\\":700,\\\"xrange\\\":[\\\"a\\\",\\\"b\\\",\\\"c\\\"],\\\"yrange\\\":[0,3]}}],\\\"data\\\":{\\\"5f227022-dd7d-42e0-8645-1b60c76507a0\\\":[{\\\"data0\\\":\\\"a\\\",\\\"data1\\\":3},{\\\"data0\\\":\\\"b\\\",\\\"data1\\\":2},{\\\"data0\\\":\\\"c\\\",\\\"data1\\\":1}]},\\\"extension\\\":[]}\\n var id_name = '#vis-e8a98398-dcab-449a-ab21-4c21dfcc43cd';\\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\"" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "IRuby.html bar_graph1.div" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Ruby 2.3.1", "language": "ruby", "name": "ruby" }, "language_info": { "file_extension": ".rb", "mimetype": "application/x-ruby", "name": "ruby", "version": "2.3.1" } }, "nbformat": 4, "nbformat_minor": 2 }