{ "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": [ "#\"string\", :label=>\"Element\"}, {:type=>\"number\", :label=>\"Density\"}], @rows=[[#, #], [#, #], [#, #], [#, #]], @listeners=[], @options={:height=>300, :width=>200}, @data=#\n", " Element Density\n", " 0 Copper 8.94\n", " 1 Silver 10.49\n", " 2 Gold 19.3\n", " 3 Platinum 21.45, @user_options={}, @html_id=\"0929ccec-0bb4-4043-bfe9-6e93854391f0\">" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "col_table = Daru::View::Table.new(df_element_density, height: 300, width: 200)\n", "col_table.table" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "\"\\n
\\n\\n\"" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "col_options = {\n", " title: \"Density of Precious Metals, in g/cm^3\",\n", " width: 600,\n", " height: 400,\n", " bar: {groupWidth: \"95%\"},\n", " legend: { position: \"none\" },\n", " type: :column\n", "}\n", "col_chart = Daru::View::Plot.new(col_table.table, col_options)\n", "col_chart.show_in_iruby" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Stacked column charts" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ " Daru::DataFrame(3x7) \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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "\n", "
GenreFantasy & Sci FiRomanceMystery/CrimeGeneralWesternLiterature
0201010242032185
1202016222330169
22030281929301213
" ], "text/plain": [ "#\n", " Genre Fantasy & Romance Mystery/Cr General Western Literature\n", " 0 2010 10 24 20 32 18 5\n", " 1 2020 16 22 23 30 16 9\n", " 2 2030 28 19 29 30 12 13" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "idx = Daru::Index.new ['Genre', 'Fantasy & Sci Fi', 'Romance', 'Mystery/Crime', 'General',\n", " 'Western', 'Literature'] \n", "data_rows = [\n", " ['2010', 10, 24, 20, 32, 18, 5],\n", " ['2020', 16, 22, 23, 30, 16, 9],\n", " ['2030', 28, 19, 29, 30, 12, 13]\n", "]\n", "df_stacked = Daru::DataFrame.rows(data_rows)\n", "df_stacked.vectors = idx\n", "df_stacked" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "#\"string\", :label=>\"Genre\"}, {:type=>\"number\", :label=>\"Fantasy & Sci Fi\"}, {:type=>\"number\", :label=>\"Romance\"}, {:type=>\"number\", :label=>\"Mystery/Crime\"}, {:type=>\"number\", :label=>\"General\"}, {:type=>\"number\", :label=>\"Western\"}, {:type=>\"number\", :label=>\"Literature\"}], @rows=[[#, #, #, #, #, #, #], [#, #, #, #, #, #, #], [#, #, #, #, #, #, #]], @listeners=[], @options={:height=>300, :width=>700}, @data=#\n", " Genre Fantasy & Romance Mystery/Cr General Western Literature\n", " 0 2010 10 24 20 32 18 5\n", " 1 2020 16 22 23 30 16 9\n", " 2 2030 28 19 29 30 12 13, @user_options={}, @html_id=\"42606ea6-77b4-4ef9-9e7c-7cbe9ea70075\">" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "col_stacked_table = Daru::View::Table.new(df_stacked, height: 300, width: 700)\n", "col_stacked_table.table" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "\"\\n
\\n\\n\"" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "col_stacked_options = {\n", " width: 600,\n", " height: 400,\n", " legend: { position: 'top', maxLines: 3 },\n", " bar: { groupWidth: '75%' },\n", " isStacked: true,\n", " type: :column\n", "}\n", "col_stacked_chart = Daru::View::Plot.new(col_stacked_table.table, col_stacked_options)\n", "col_stacked_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "\"\\n
\\n\\n\"" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "col_stacked_options = {\n", " isStacked: true,\n", " height: 300,\n", " legend: {position: 'top', maxLines: 3},\n", " vAxis: {minValue: 0},\n", " type: :column\n", "}\n", "col_stacked_chart = Daru::View::Plot.new(col_stacked_table.table, col_stacked_options)\n", "col_stacked_chart.show_in_iruby" ] }, { "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": [ "col_stacked_options = {\n", " isStacked: 'percent',\n", " height: 400,\n", " legend: {position: 'top', maxLines: 3},\n", " vAxis: {\n", " minValue: 0,\n", " ticks: [0, 0.3, 0.6, 0.9, 1]\n", " },\n", " type: :column\n", "}\n", "col_stacked_chart = Daru::View::Plot.new(col_stacked_table.table, col_stacked_options)\n", "col_stacked_chart.show_in_iruby" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "TODO: Material column chart using google_visualr. Refer : https://developers.google.com/chart/interactive/docs/gallery/columnchart" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Dual-Y charts" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ " Daru::DataFrame(5x3) \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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "\n", "
GalaxyDistanceBrightness
0Canis Major Dwarf800023.3
1Sagittarius Dwarf240004.5
2Ursa Major II Dwarf3000014.3
3Lg. Magellanic Cloud500000.9
4Bootes I6000013.1
" ], "text/plain": [ "#\n", " Galaxy Distance Brightness\n", " 0 Canis Majo 8000 23.3\n", " 1 Sagittariu 24000 4.5\n", " 2 Ursa Major 30000 14.3\n", " 3 Lg. Magell 50000 0.9\n", " 4 Bootes I 60000 13.1" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "idx = Daru::Index.new ['Galaxy', 'Distance', 'Brightness']\n", "data_rows = [\n", " ['Canis Major Dwarf', 8000, 23.3],\n", " ['Sagittarius Dwarf', 24000, 4.5],\n", " ['Ursa Major II Dwarf', 30000, 14.3],\n", " ['Lg. Magellanic Cloud', 50000, 0.9],\n", " ['Bootes I', 60000, 13.1]\n", "]\n", "df_dualY = Daru::DataFrame.rows(data_rows)\n", "df_dualY.vectors = idx\n", "df_dualY" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "#\"string\", :label=>\"Galaxy\"}, {:type=>\"number\", :label=>\"Distance\"}, {:type=>\"number\", :label=>\"Brightness\"}], @rows=[[#, #, #], [#, #, #], [#, #, #], [#, #, #], [#, #, #]], @listeners=[], @options={:height=>300, :width=>700}, @data=#\n", " Galaxy Distance Brightness\n", " 0 Canis Majo 8000 23.3\n", " 1 Sagittariu 24000 4.5\n", " 2 Ursa Major 30000 14.3\n", " 3 Lg. Magell 50000 0.9\n", " 4 Bootes I 60000 13.1, @user_options={}, @html_id=\"e616d194-5606-48b9-8572-39e1baa6b561\">" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "col_dualY_table = Daru::View::Table.new(df_dualY, height: 300, width: 700)\n", "col_dualY_table.table" ] }, { "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": [ "col_dualY_options = {\n", " chart: {\n", " title: 'Nearby galaxies',\n", " subtitle: 'distance on the left, brightness on the right'\n", " },\n", " \n", "# series: {\n", "# 0: { axis: 'distance' }, # Bind series 0 to an axis named 'distance'.\n", "# 1: { axis: 'brightness' } # Bind series 1 to an axis named 'brightness'.\n", "# },\n", "# axes: {\n", "# y: {\n", "# distance: {label: 'parsecs'}, # Left y-axis.\n", "# brightness: {side: 'right', label: 'apparent magnitude'} # Right y-axis.\n", "# }\n", "# }\n", " type: :column\n", "}\n", "col_dualY_chart = Daru::View::Plot.new(col_dualY_table.table, col_dualY_options)\n", "col_dualY_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "\"\\n
\\n\\n\"" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "col_dualY_options = {\n", " width: 900,\n", "# Fixme: below line not working. expecting :\n", "# https://developers.google.com/chart/interactive/docs/gallery/columnchart\n", "# series: {\n", "# 0: {targetAxisIndex: 0},\n", "# 1: {targetAxisIndex: 1}\n", "# },\n", " title: 'Nearby galaxies - distance on the left, brightness on the right',\n", "# vAxes: {\n", "# # Adds titles to each axis.\n", "# 0: {title: 'parsecs'},\n", "# 1: {title: 'apparent magnitude'}\n", "# }\n", " type: :column\n", "}\n", "col_dualY_chart = Daru::View::Plot.new(col_dualY_table.table, col_dualY_options)\n", "col_dualY_chart.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 }