{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "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": {}, "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\"" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = [\n", " ['Galaxy', 'Distance', 'Brightness', 'Distance-Galaxy'],\n", " ['Canis Major Dwarf', 8000, 230.3, 0],\n", " ['Sagittarius Dwarf', 24000, 4000.5, 0],\n", " ['Ursa Major II Dwarf', 30000, 1412.3, 0],\n", " ['Lg. Magellanic Cloud', 50000, 120.9, 0],\n", " ['Bootes I', 60000, 1223.1, 0]\n", " ]\n", "user_options = {\n", " formatters: {\n", " # ArrowFormat is working on localhost but not working on nbviewer.\n", " formatter1: {\n", " type: 'Arrow',\n", " options: {\n", " base: 30000\n", " },\n", " columns: 1\n", " },\n", " formatter2: {\n", " type: 'Color',\n", " range: [[1000, 30000, 'red', '#000000'],\n", " [40000, nil, 'green', 'pink']],\n", " columns: [1,2]\n", " },\n", " formatter3: {\n", " type: 'Pattern',\n", " format_string: \"{1} - {0}\",\n", " src_cols: [0, 1],\n", " des_col: 3\n", " },\n", " formatter4: {\n", " type: 'Number',\n", " options: {prefix: '*'},\n", " columns: 2\n", " },\n", " }\n", "}\n", "table = Daru::View::Table.new(data, {allowHtml: true}, user_options)\n", "table.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = [\n", " ['Employee', 'Start Date (Long)', 'Start Date (Medium)', 'Start Date (Short)'],\n", " ['Mike', Date.parse('2007-11-28'), Date.parse('2007-11-28'), Date.parse('2007-11-28')],\n", " ['Bob', Date.parse('2006-7-16'), Date.parse('2006-7-16'), Date.parse('2006-7-16')],\n", " ['Alice', Date.parse('2007-9-2'), Date.parse('2007-9-2'), Date.parse('2007-9-2')]\n", " ]\n", "\n", "user_options = {\n", " formatters: {\n", " f1: {\n", " type: 'Date',\n", " options: {\n", " formatType: 'long'\n", " },\n", " columns: 1\n", " },\n", " f2: {\n", " type: 'Date',\n", " options: {\n", " formatType: 'medium'\n", " },\n", " columns: 2\n", " },\n", " f3: {\n", " type: 'Date',\n", " options: {\n", " formatType: 'short'\n", " },\n", " columns: 3\n", " }\n", " }\n", "}\n", "\n", "table = Daru::View::Table.new(data, {}, user_options)\n", "table.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = Daru::DataFrame.new({b: [11,12,13,14,15], a: [1,2,3,4,5],\n", " c: [11,22,33,44,55]},\n", " order: [:a, :b, :c],\n", " index: [:one, :two, :three, :four, :five])\n", "\n", "user_options = {\n", " formatters: {\n", " formatter: {\n", " type: 'Color',\n", " range: [[1, 3, 'yellow', 'red'],\n", " [20, 50, 'green', 'pink']],\n", " columns: [0,2]\n", " },\n", " formatter2: {\n", " type: 'Color',\n", " range: [[14, 15, 'blue', 'orange']],\n", " columns: 1\n", " }\n", " }\n", "}\n", "\n", "# option `allowHtml: true` is necessary to make this work\n", "table = Daru::View::Table.new(df, {allowHtml: true}, user_options)\n", "table.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = Daru::DataFrame.new({b: [11,-12,13,14,-15], a: [-1,2,3,4,5],\n", " c: [11,22,-33,-44,55]},\n", " order: [:a, :b, :c],\n", " index: [:one, :two, :three, :four, :five])\n", "\n", "user_options = {\n", " formatters: {\n", " formatter: {\n", " type: 'Number',\n", " options: {negativeParens: true},\n", " columns: [0,1,2]\n", " }\n", " }\n", "}\n", "\n", "table = Daru::View::Table.new(df, {}, user_options)\n", "table.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "user_options = {\n", " formatters: {\n", " formatter: {\n", " type: 'Pattern',\n", " format_string: \"{0} and {1}\",\n", " src_cols: [0, 1],\n", " des_col: 2\n", " }\n", " }\n", "}\n", "\n", "table = Daru::View::Table.new(df, {}, user_options)\n", "table.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "user_options = {\n", " formatters: {\n", " formatter: {\n", " type: 'Arrow',\n", " options: {\n", " base: 0\n", " },\n", " columns: 1\n", " }\n", " }\n", "}\n", "\n", "table = Daru::View::Table.new(df, {}, user_options)\n", "table.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = [\n", " ['Year', 'Sales', 'Expenses'],\n", " ['2013', 1000, 400],\n", " ['2014', 1170, 460],\n", " ['2015', 660, 1120],\n", " ['2016', 1030, 540]\n", " ]\n", "user_options = {\n", " # Generating wierd bars in IRuby notebook, it is working fine in rails\n", " formatters: {\n", " f1: {\n", " type: 'Bar',\n", " options: {\n", " base: 1000,\n", " width: 120\n", " },\n", " columns: 2\n", " }\n", " }\n", "}\n", "table = Daru::View::Table.new(data, {allowHtml: true}, user_options)\n", "table.show_in_iruby" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Ruby 2.4.1", "language": "ruby", "name": "ruby" }, "language_info": { "file_extension": ".rb", "mimetype": "application/x-ruby", "name": "ruby", "version": "2.4.1" } }, "nbformat": 4, "nbformat_minor": 2 }