{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "true" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "require 'daru/view'" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "\n", " /* BEGIN google_visualr.js */\n", "\n", "if(!window['googleLT_']){window['googleLT_']=(new Date()).getTime();}if (!window['google']) {\n", "window['google'] = {};\n", "}\n", "if (!window['google']['loader']) {\n", "window['google']['loader'] = {};\n", "google.loader.ServiceBase = 'https://www.google.com/uds';\n", "google.loader.GoogleApisBase = 'https://ajax.googleapis.com/ajax';\n", "google.loader.ApiKey = 'notsupplied';\n", "google.loader.KeyVerified = true;\n", "google.loader.LoadFailure = false;\n", "google.loader.Secure = true;\n", "google.loader.GoogleLocale = 'www.google.com';\n", "google.loader.ClientLocation = null;\n", "google.loader.AdditionalParams = '';\n", "(function() {function g(a){return a in l?l[a]:l[a]=-1!=navigator.userAgent.toLowerCase().indexOf(a)}var l={};function m(a,b){var c=function(){};c.prototype=b.prototype;a.ca=b.prototype;a.prototype=new c}function n(a,b,c){var d=Array.prototype.slice.call(arguments,2)||[];return function(){return a.apply(b,d.concat(Array.prototype.slice.call(arguments)))}}function p(a){a=Error(a);a.toString=function(){return this.message};return a}\n", "function q(a,b){a=a.split(/\\./);for(var c=window,d=0;d\\x3c/script>\"):(g(\"safari\")||g(\"konqueror\"))&&window.setTimeout(B,10)),x.push(a)):y(window,\"load\",a)};t(\"google.setOnLoadCallback\",google.ba);\n", "function y(a,b,c){if(a.addEventListener)a.addEventListener(b,c,!1);else if(a.attachEvent)a.attachEvent(\"on\"+b,c);else{var d=a[\"on\"+b];a[\"on\"+b]=null!=d?C([c,d]):c}}function C(a){return function(){for(var b=0;b\\x3c/script>'):\"css\"==a&&document.write('')};\n", "t(\"google.loader.writeLoadTag\",google.loader.f);google.loader.Z=function(a){w=a};t(\"google.loader.rfm\",google.loader.Z);google.loader.aa=function(a){for(var b in a)\"string\"==typeof b&&b&&\":\"==b.charAt(0)&&!v[b]&&(v[b]=new E(b.substring(1),a[b]))};t(\"google.loader.rpl\",google.loader.aa);google.loader.$=function(a){if((a=a.specs)&&a.length)for(var b=0;b\\x3c/script>')},K.Ki=function(b){var c=K.global.document,d=c.createElement(\"script\");d.type=C;d.src=b;d.defer=!1;d.async=!1;c.head.appendChild(d)},\n", "K.Tl=function(b,c){if(K.qg()){var d=K.global.document;if(!K.De&&d.readyState==t){if(/\\bdeps.js$/.test(b))return!1;throw Error('Cannot write \"'+b+'\" after document load');}void 0===c?K.di?(K.$g=!0,c=\" onreadystatechange='goog.onScriptLoad_(this, \"+ ++K.Pg+\")' \",d.write(n+b+'\"'+c+\">\\x3c/script>\")):K.De?K.Ki(b):K.Sl(b):d.write('\n" ], "text/plain": [ "\"\\n
\\n\\n\"" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t1.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\"\\n
\\n\\n\"" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t1.div" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "\"\\n
\\n\\n\"" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "IRuby.html t1.div" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ " Daru::DataFrame(4x3) \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "\n", "
012
0Mike{:v=>10000, :f=>\"$10,000\"}true
1Jim{:v=>8000, :f=>\"$8,000\"}false
2Alice{:v=>12500, :f=>\"$12,500\"}true
3Bob{:v=>7000, :f=>\"$7,000\"}true
" ], "text/plain": [ "#\n", " 0 1 2\n", " 0 Mike {:v=>10000 true\n", " 1 Jim {:v=>8000, false\n", " 2 Alice {:v=>12500 true\n", " 3 Bob {:v=>7000, true" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rows = [\n", " ['Mike', {v: 10000, f: '$10,000'}, true],\n", " ['Jim', {v:8000, f: '$8,000'}, false],\n", " ['Alice', {v: 12500, f: '$12,500'}, true],\n", " ['Bob', {v: 7000, f: '$7,000'}, true]\n", "]\n", "\n", "df2 = Daru::DataFrame.rows(rows)\n" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "#\n", " 0 1 2\n", " 0 Mike {:v=>10000 true\n", " 1 Jim {:v=>8000, false\n", " 2 Alice {:v=>12500 true\n", " 3 Bob {:v=>7000, true, @options={}, @user_options={}, @adapter=Daru::View::Adapter::GooglechartsAdapter, @table=#\"string\", :label=>\"0\"}, {:type=>\"number\", :label=>\"1\"}, {:type=>\"boolean\", :label=>\"2\"}], @rows=[[#, #, #], [#, #, #], [#, #, #], [#, #, #]], @listeners=[], @options={}, @data=#\n", " 0 1 2\n", " 0 Mike {:v=>10000 true\n", " 1 Jim {:v=>8000, false\n", " 2 Alice {:v=>12500 true\n", " 3 Bob {:v=>7000, true, @user_options={}>>" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t2 = Daru::View::Table.new(df2)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "\"\\n
\\n\\n\"" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t2.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{:showRowNumber=>true, :width=>\"100%\", :height=>\"100%\", :page=>\"enable\", :pageSize=>2, :pagingSymbols=>{:prev=>\"prev\", :next=>\"next\"}, :pagingButtonsConfiguration=>\"auto\"}" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# adding pagination\n", "opts_pagination = {\n", " showRowNumber: true, width: '100%', height: '100%' ,\n", " page: 'enable',\n", " pageSize: 2,\n", " pagingSymbols: {\n", " prev: 'prev',\n", " next: 'next'\n", " },\n", " pagingButtonsConfiguration: 'auto'}" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "#\n", " 0 1 2\n", " 0 Mike {:v=>10000 true\n", " 1 Jim {:v=>8000, false\n", " 2 Alice {:v=>12500 true\n", " 3 Bob {:v=>7000, true, @options={:showRowNumber=>true, :width=>\"100%\", :height=>\"100%\", :page=>\"enable\", :pageSize=>2, :pagingSymbols=>{:prev=>\"prev\", :next=>\"next\"}, :pagingButtonsConfiguration=>\"auto\"}, @user_options={}, @adapter=Daru::View::Adapter::GooglechartsAdapter, @table=#\"string\", :label=>\"0\"}, {:type=>\"number\", :label=>\"1\"}, {:type=>\"boolean\", :label=>\"2\"}], @rows=[[#, #, #], [#, #, #], [#, #, #], [#, #, #]], @listeners=[], @options={:showRowNumber=>true, :width=>\"100%\", :height=>\"100%\", :page=>\"enable\", :pageSize=>2, :pagingSymbols=>{:prev=>\"prev\", :next=>\"next\"}, :pagingButtonsConfiguration=>\"auto\"}, @data=#\n", " 0 1 2\n", " 0 Mike {:v=>10000 true\n", " 1 Jim {:v=>8000, false\n", " 2 Alice {:v=>12500 true\n", " 3 Bob {:v=>7000, true, @user_options={}>>" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t3 = Daru::View::Table.new(df2,opts_pagination)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "\"\\n
\\n\\n\"" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t3.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Daru::View::Table" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t3.class" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "#true, :width=>\"100%\", :height=>\"100%\", :page=>\"enable\", :pageSize=>2, :pagingSymbols=>{:prev=>\"prev\", :next=>\"next\"}, :pagingButtonsConfiguration=>\"auto\"}, @user_options={}, @adapter=Daru::View::Adapter::GooglechartsAdapter, @table=#true, :width=>\"100%\", :height=>\"100%\", :page=>\"enable\", :pageSize=>2, :pagingSymbols=>{:prev=>\"prev\", :next=>\"next\"}, :pagingButtonsConfiguration=>\"auto\"}, @data=[], @user_options={}>>" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t4 = Daru::View::Table.new([],opts_pagination)" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[[\"2004\", 1000, 400, 1111], [\"2005\", 1170, 460, 2111], [\"2006\", 660, 1120, 3111], [\"2007\", 1030, 540, 1112]]" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# users are free to use the Google charts features, by accessing the google chart table using `#table`\n", "# Add Column Headers\n", "t4.table.new_column('string', 'Year' )\n", "t4.table.new_column('number', 'Sales')\n", "t4.table.new_column('number', 'Expenses')\n", "t4.table.new_column('number', 'Expenses2')\n", "\n", " # Add Rows and Values\n", "t4.table.add_rows([\n", " ['2004', 1000, 400, 1111],\n", " ['2005', 1170, 460, 2111],\n", " ['2006', 660, 1120, 3111],\n", " ['2007', 1030, 540, 1112]\n", " ])" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "\"\\n
\\n\\n\"" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t4.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{:cols=>[{:id=>\"A\", :label=>\"NEW A\", :type=>\"string\"}, {:id=>\"B\", :label=>\"B-label\", :type=>\"number\"}, {:id=>\"C\", :label=>\"C-label\", :type=>\"date\"}], :rows=>[{:c=>[{:v=>\"a\"}, {:v=>1.0, :f=>\"One\"}, {:v=>#, :f=>\"2/28/08 12:31 AM\"}]}, {:c=>[{:v=>\"b\"}, {:v=>2.0, :f=>\"Two\"}, {:v=>#, :f=>\"3/30/08 12:31 AM\"}]}, {:c=>[{:v=>\"c\"}, {:v=>3.0, :f=>\"Three\"}, {:v=>#, :f=>\"4/30/08 12:31 AM\"}]}]}" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "opts = {\n", " cols: [\n", " {id: 'A', label: 'NEW A', type: 'string'},\n", " {id: 'B', label: 'B-label', type: 'number'},\n", " {id: 'C', label: 'C-label', type: 'date'} \n", " ],\n", " rows: [\n", " {c:[\n", " {v: 'a'},\n", " {v: 1.0, f: 'One'},\n", " {:v => Date.parse('2008-1-28 00:31:26'), f: '2/28/08 12:31 AM'}\n", " ]},\n", " {c:[\n", " {v: 'b'},\n", " {v: 2.0, f: 'Two'},\n", " {:v =>Date.parse('2008-2-12 00:31:27'), f: '3/30/08 12:31 AM'}\n", " ]},\n", " {c:[\n", " {v: 'c'},\n", " {v: 3.0, f: 'Three'},\n", " {v: Date.parse('2008-3-30 00:31:26'), f: '4/30/08 12:31 AM'}\n", " ]}\n", " ]\n", "}" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "#[{:id=>\"A\", :label=>\"NEW A\", :type=>\"string\"}, {:id=>\"B\", :label=>\"B-label\", :type=>\"number\"}, {:id=>\"C\", :label=>\"C-label\", :type=>\"date\"}], :rows=>[{:c=>[{:v=>\"a\"}, {:v=>1.0, :f=>\"One\"}, {:v=>#, :f=>\"2/28/08 12:31 AM\"}]}, {:c=>[{:v=>\"b\"}, {:v=>2.0, :f=>\"Two\"}, {:v=>#, :f=>\"3/30/08 12:31 AM\"}]}, {:c=>[{:v=>\"c\"}, {:v=>3.0, :f=>\"Three\"}, {:v=>#, :f=>\"4/30/08 12:31 AM\"}]}]}, @user_options={}, @adapter=Daru::View::Adapter::GooglechartsAdapter, @table=#\"string\", :label=>\"NEW A\", :id=>\"A\"}, {:type=>\"number\", :label=>\"B-label\", :id=>\"B\"}, {:type=>\"date\", :label=>\"C-label\", :id=>\"C\"}], @rows=[[#, #, #, @type=\"date\", @f=\"2/28/08 12:31 AM\", @p=nil>], [#, #, #, @type=\"date\", @f=\"3/30/08 12:31 AM\", @p=nil>], [#, #, #, @type=\"date\", @f=\"4/30/08 12:31 AM\", @p=nil>]], @listeners=[], @options={:cols=>[{:id=>\"A\", :label=>\"NEW A\", :type=>\"string\"}, {:id=>\"B\", :label=>\"B-label\", :type=>\"number\"}, {:id=>\"C\", :label=>\"C-label\", :type=>\"date\"}], :rows=>[{:c=>[{:v=>\"a\"}, {:v=>1.0, :f=>\"One\"}, {:v=>#, :f=>\"2/28/08 12:31 AM\"}]}, {:c=>[{:v=>\"b\"}, {:v=>2.0, :f=>\"Two\"}, {:v=>#, :f=>\"3/30/08 12:31 AM\"}]}, {:c=>[{:v=>\"c\"}, {:v=>3.0, :f=>\"Three\"}, {:v=>#, :f=>\"4/30/08 12:31 AM\"}]}]}, @data=[], @user_options={}>>" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t_ops = Daru::View::Table.new([],opts)" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "\"\\n
\\n\\n\"" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t_ops.show_in_iruby # or t_ops.table" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "#>" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t_update = Daru::View::Table.new" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{:type=>\"string\", :label=>\"Employee Name\"}, {:type=>\"date\", :label=>\"Start Date\"}]" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t_update.table.new_column(type= 'string', 'Employee Name');\n", "t_update.table.new_column(type= 'date', 'Start Date');" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "#\"string\", :label=>\"Employee Name\"}, {:type=>\"date\", :label=>\"Start Date\"}], @rows=[], @listeners=[], @options={}, @data=[], @user_options={}, @html_id=\"0e991f5f-b463-4475-b40f-8a14ad0a304c\">" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t_update.table" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t_update.table.add_rows(6)\n" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "#" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t_update.table.set_cell(0, 0, 'Mike');\n" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "#, @type=\"date\">" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t_update.table.set_cell(0, 1, Date.parse('2008-1-28'));\n", "t_update.table.set_cell(1, 0, 'Bob');\n", "t_update.table.set_cell(1, 1, Date.parse('2007-5-1'));\n", "t_update.table.set_cell(2, 0, 'Alice');\n", "t_update.table.set_cell(2, 1, Date.parse('2006-7-16'));\n", "t_update.table.set_cell(3, 0, 'Frank');\n", "t_update.table.set_cell(3, 1, Date.parse('2007-11-28'));\n", "t_update.table.set_cell(4, 0, 'Floyd');\n", "t_update.table.set_cell(4, 1, Date.parse('2005-3-13'));\n", "t_update.table.set_cell(5, 0, 'Fritz');\n", "t_update.table.set_cell(5, 1, Date.parse('2007-9-2'));" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "#\"string\", :label=>\"Employee Name\"}, {:type=>\"date\", :label=>\"Start Date\"}], @rows=[[#, #, @type=\"date\">], [#, #, @type=\"date\">], [#, #, @type=\"date\">], [#, #, @type=\"date\">], [#, #, @type=\"date\">], [#, #, @type=\"date\">]], @listeners=[], @options={}, @data=[], @user_options={}, @html_id=\"e118bc06-8027-44f6-9da7-8fe8867b15c6\">" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t_update.table" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[\"Mike\", \"Bob\", \"Alice\", \"Frank\", \"Floyd\", \"Fritz\"]" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t_update.table.get_column(0)" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[\"Mike\", #]" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t_update.table.get_row(0)" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\"Frank\"" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t_update.table.get_cell(3,0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Using Daru Vector" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "#\n", " 0 43934\n", " 1 52503\n", " 2 57177\n", " 3 69658\n", " 4 97031\n", " 5 119931\n", " 6 137133\n", " 7 154175, @options={}, @user_options={}, @adapter=Daru::View::Adapter::GooglechartsAdapter, @table=#\"number\", :label=>\"Series\"}], @rows=[[#], [#], [#], [#], [#], [#], [#], [#]], @listeners=[], @options={}, @data=#\n", " 0 43934\n", " 1 52503\n", " 2 57177\n", " 3 69658\n", " 4 97031\n", " 5 119931\n", " 6 137133\n", " 7 154175, @user_options={}>>" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv = Daru::Vector.new [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]\n", "t_vec = Daru::View::Table.new(dv)" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "#\"number\", :label=>\"Series\"}], @rows=[[#], [#], [#], [#], [#], [#], [#], [#]], @listeners=[], @options={}, @data=#\n", " 0 43934\n", " 1 52503\n", " 2 57177\n", " 3 69658\n", " 4 97031\n", " 5 119931\n", " 6 137133\n", " 7 154175, @user_options={}, @html_id=\"f1795c9e-72af-433d-b3f6-05732f22fc1a\">" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t_vec.table" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{}" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t_vec.table.options" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{:showRowNumber=>true, :width=>\"100%\", :height=>\"100%\", :page=>\"enable\", :pageSize=>2, :pagingSymbols=>{:prev=>\"prev\", :next=>\"next\"}, :pagingButtonsConfiguration=>\"auto\"}" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# set new options in the table. This feature is not present in the basic google_visualr\n", "t_vec.table.options = opts_pagination" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "#\"number\", :label=>\"Series\"}], @rows=[[#], [#], [#], [#], [#], [#], [#], [#]], @listeners=[], @options={:showRowNumber=>true, :width=>\"100%\", :height=>\"100%\", :page=>\"enable\", :pageSize=>2, :pagingSymbols=>{:prev=>\"prev\", :next=>\"next\"}, :pagingButtonsConfiguration=>\"auto\"}, @data=#\n", " 0 43934\n", " 1 52503\n", " 2 57177\n", " 3 69658\n", " 4 97031\n", " 5 119931\n", " 6 137133\n", " 7 154175, @user_options={}, @html_id=\"369270fd-cdeb-4232-afe4-e1d2be2aef75\">" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t_vec.table" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{:showRowNumber=>true, :pageSize=>5, :allowHtml=>true, :cssClassNames=>{:headerRow=>\"italic-darkblue-font large-font bold-font\", :tableRow=>\"\", :oddTableRow=>\"beige-background\", :selectedTableRow=>\"orange-background large-font\", :hoverTableRow=>\"\", :headerCell=>\"gold-border\", :tableCell=>\"\", :rowNumberCell=>\"underline-blue-font\"}}" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# css styling\n", "cssClassNames = {\n", " 'headerRow': 'italic-darkblue-font large-font bold-font',\n", " 'tableRow': '',\n", " 'oddTableRow': 'beige-background',\n", " 'selectedTableRow': 'orange-background large-font',\n", " 'hoverTableRow': '',\n", " 'headerCell': 'gold-border',\n", " 'tableCell': '',\n", " 'rowNumberCell': 'underline-blue-font'\n", " };\n", "opts_css = {'showRowNumber': true, pageSize: 5, 'allowHtml': true, 'cssClassNames': cssClassNames};\n" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{:showRowNumber=>true, :pageSize=>5, :allowHtml=>true, :cssClassNames=>{:headerRow=>\"italic-darkblue-font large-font bold-font\", :tableRow=>\"\", :oddTableRow=>\"beige-background\", :selectedTableRow=>\"orange-background large-font\", :hoverTableRow=>\"\", :headerCell=>\"gold-border\", :tableCell=>\"\", :rowNumberCell=>\"underline-blue-font\"}}" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t_vec.table.options = opts_css" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "#\"number\", :label=>\"Series\"}], @rows=[[#], [#], [#], [#], [#], [#], [#], [#]], @listeners=[], @options={:showRowNumber=>true, :pageSize=>5, :allowHtml=>true, :cssClassNames=>{:headerRow=>\"italic-darkblue-font large-font bold-font\", :tableRow=>\"\", :oddTableRow=>\"beige-background\", :selectedTableRow=>\"orange-background large-font\", :hoverTableRow=>\"\", :headerCell=>\"gold-border\", :tableCell=>\"\", :rowNumberCell=>\"underline-blue-font\"}}, @data=#\n", " 0 43934\n", " 1 52503\n", " 2 57177\n", " 3 69658\n", " 4 97031\n", " 5 119931\n", " 6 137133\n", " 7 154175, @user_options={}, @html_id=\"e995bb8f-6b71-4bd7-b8cb-5b37b1021442\">" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# FixMe: css is not working. May be there is other way to pass cssClassName\n", "t_vec.table" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "### Using option Hash " ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "\"\\n
\\n\\n\"" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = {\n", " cols: [{id: 'Name', label: 'Name', type: 'string'},\n", " {id: 'Salary', label: 'Salary', type: 'number'},\n", " {type: 'boolean', label: 'Full Time Employee' },\n", " ],\n", " rows: [\n", " {c:[{v: 'Mike'}, {v: 10000, f: '$10,000'}, {v: true}]},\n", " {c:[{v: 'Jim'}, {v:8000, f: '$8,000'}, {v: false}]},\n", " {c:[{v: 'Alice'}, {v: 12500, f: '$12,500'}, {v: true}]},\n", " {c:[{v: 'Bob'}, {v: 7000, f: '$7,000'}, {v: true}]},\n", " ]\n", " }\n", "table = Daru::View::Table.new(data, {height: 300, width: 200})\n", "table.show_in_iruby" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### From Data Array (First row should be column vector for google data table)" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "\"\\n
\\n\\n\"" ] }, "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = [\n", " ['Galaxy', 'Distance', 'Brightness'],\n", " ['Canis Major Dwarf', 8000, 230.3],\n", " ['Sagittarius Dwarf', 24000, 4000.5],\n", " ['Ursa Major II Dwarf', 30000, 1412.3],\n", " ['Lg. Magellanic Cloud', 50000, 120.9],\n", " ['Bootes I', 60000, 1223.1]\n", " ]\n", "table = Daru::View::Table.new(data)\n", "table.show_in_iruby" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Ruby 2.5.3", "language": "ruby", "name": "ruby" }, "language_info": { "file_extension": ".rb", "mimetype": "application/x-ruby", "name": "ruby", "version": "2.5.3" } }, "nbformat": 4, "nbformat_minor": 2 }