{ "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": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = [\n", " ['Task', 'Hours per Day'],\n", " ['Work', 11],\n", " ['Eat', 2],\n", " ['Commute', 2],\n", " ['Watch TV', 2],\n", " ['Sleep', 7]\n", " ]\n", "pie_chart_table = Daru::View::Table.new(data)\n", "pie_chart_table.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "\"\\n
\\n\\n\"" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "pie_chart_options = {\n", " type: :pie, height: 400, title: 'My Daily Activities'\n", "}\n", "pie_chart_chart = Daru::View::Plot.new(pie_chart_table.table, pie_chart_options)\n", "pie_chart_chart.show_in_iruby" ] }, { "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": [ "\n", "pie_chart3D_options = {\n", " type: :pie, height: 400, title: 'My Daily Activities', is3D: true\n", "}\n", "pie_chart3D = Daru::View::Plot.new(pie_chart_table.table, pie_chart3D_options)\n", "pie_chart3D.show_in_iruby" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Making a Donut Chart" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "\"\\n
\\n\\n\"" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "pie_chart_dount_options = {\n", " type: :pie, height: 400, title: 'My Daily Activities',pieHole: 0.4,\n", "}\n", "pie_chart_dount = Daru::View::Plot.new(pie_chart_table.table, pie_chart_dount_options)\n", "pie_chart_dount.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "\"\\n
\\n\\n\"" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "pie_chart_dount_options = {\n", " type: :pie, height: 400, title: 'My Daily Activities',pieHole: 0.5,\n", " pieSliceTextStyle: {\n", " color: 'black',\n", " },\n", " legend: 'none'\n", "}\n", "pie_chart_dount = Daru::View::Plot.new(pie_chart_table.table, pie_chart_dount_options)\n", "pie_chart_dount.show_in_iruby" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Rotating a Pie Chart" ] }, { "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": [ "data = [\n", " ['Language', 'Speakers (in millions)'],\n", " ['German', 5.85],\n", " ['French', 1.66],\n", " ['Italian', 0.316],\n", " ['Romansh', 0.0791]\n", " ]\n", "pie_chart_rotate_table = Daru::View::Table.new(data)\n", "pie_chart_rotate_table.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": [ "pie_chart_rotate_options = {\n", "type: :pie, height: 500\n", "}\n", "pie_chart_rotate_dount = Daru::View::Plot.new(pie_chart_rotate_table.table, pie_chart_rotate_options)\n", "pie_chart_rotate_dount.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": [ "\n", "pie_chart_rotate_options = {\n", " legend: 'none',\n", " pieSliceText: 'label',\n", " title: 'Swiss Language Use (100 degree rotation)',\n", " pieStartAngle: 100,type: :pie, height: 500\n", "}\n", "pie_chart_rotate_dount = Daru::View::Plot.new(pie_chart_rotate_table.table, pie_chart_rotate_options)\n", "pie_chart_rotate_dount.show_in_iruby" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exploding a Slice" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "\"\\n
\\n\\n\"" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = [\n", " ['Language', 'Speakers (in millions)'],\n", " ['Assamese', 13], ['Bengali', 83], ['Bodo', 1.4],\n", " ['Dogri', 2.3], ['Gujarati', 46], ['Hindi', 300],\n", " ['Kannada', 38], ['Kashmiri', 5.5], ['Konkani', 5],\n", " ['Maithili', 20], ['Malayalam', 33], ['Manipuri', 1.5],\n", " ['Marathi', 72], ['Nepali', 2.9], ['Oriya', 33],\n", " ['Punjabi', 29], ['Sanskrit', 0.01], ['Santhali', 6.5],\n", " ['Sindhi', 2.5], ['Tamil', 61], ['Telugu', 74], ['Urdu', 52]\n", " ]\n", "pie_chart_slice_table = Daru::View::Table.new(data, pageSize: 5)\n", "pie_chart_slice_table.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "\"\\n
\\n\\n\"" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "pie_chart_slice_options = {\n", "type: :pie, height: 500\n", "}\n", "pie_chart_slice = Daru::View::Plot.new(pie_chart_slice_table.table, pie_chart_slice_options)\n", "pie_chart_slice.show_in_iruby" ] }, { "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": [ "\n", "pie_chart_slice_options = {\n", " title: 'Indian Language Use',\n", " legend: 'none',\n", " pieSliceText: 'label',\n", " slices: { 4 => {offset: 0.2},\n", " 12 => {offset: 0.3},\n", " 14 => {offset: 0.4},\n", " 15 => {offset: 0.5},\n", " },\n", " type: :pie, height: 500\n", "}\n", "pie_chart_slice = Daru::View::Plot.new(pie_chart_slice_table.table, pie_chart_slice_options)\n", "pie_chart_slice.show_in_iruby" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Removing Slices" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ " Daru::DataFrame(2x2) \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", "
Pac ManPercentage
075
125
" ], "text/plain": [ "#\n", " Pac Man Percentage\n", " 0 75\n", " 1 25" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "idx = Daru::Index.new ['Pac Man', 'Percentage']\n", "data_rows = [\n", " ['', 75],\n", " ['', 25]]\n", "df_pac_man = Daru::DataFrame.rows(data_rows)\n", "df_pac_man.vectors = idx\n", "df_pac_man" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "\"\\n
\\n\\n\"" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pie_pac_chart = Daru::View::Plot.new(df_pac_man, type: :pie)\n", "pie_pac_chart.show_in_iruby" ] }, { "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": [ "opts = {\n", " legend: 'none',\n", " pieSliceText: 'none',\n", " pieStartAngle: 135,\n", " tooltip: { trigger: 'none' },\n", " slices: {\n", " 0 => { color: 'yellow' },\n", " 1 => { color: 'transparent' }\n", " },\n", " type: :pie\n", " }\n", "pie_pac_chart = Daru::View::Plot.new(df_pac_man, opts)\n", "pie_pac_chart.show_in_iruby" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Slice Visibility Threshold" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/html": [ " Daru::DataFrame(5x2) \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", "
PizzaPopulartiy
0Pepperoni33
1Hawaiian26
2Mushroom22
3Sausage10
4Anchovies9
" ], "text/plain": [ "#\n", " Pizza Populartiy\n", " 0 Pepperoni 33\n", " 1 Hawaiian 26\n", " 2 Mushroom 22\n", " 3 Sausage 10\n", " 4 Anchovies 9" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "idx = Daru::Index.new ['Pizza', 'Populartiy']\n", "data_rows = [\n", " ['Pepperoni', 33],\n", " ['Hawaiian', 26],\n", " ['Mushroom', 22],\n", " ['Sausage', 10], # Below limit.\n", " ['Anchovies', 9] # Below limit.\n", " ]\n", "df_pizza = Daru::DataFrame.rows(data_rows)\n", "df_pizza.vectors = idx\n", "df_pizza" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "\"\\n
\\n\\n\"" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "opts = {\n", "title: 'Popularity of Types of Pizza',\n", " sliceVisibilityThreshold: 0.2,\n", " type: :pie, height: 400\n", " }\n", "pie_pizza = Daru::View::Plot.new(df_pizza, opts)\n", "pie_pizza.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 }