{ "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": [ "country_population = [\n", " ['Germany', 200],\n", " ['United States', 300],\n", " ['Brazil', 400],\n", " ['Canada', 500],\n", " ['France', 600],\n", " ['RU', 700]\n", "]\n", "\n", "df_cp = Daru::DataFrame.rows(country_population)\n", "df_cp.vectors = Daru::Index.new(['Country', 'Population'])\n", "geo_table = Daru::View::Table.new(df_cp, pageSize: 5, adapter: :googlecharts, height: 200, width: 200)\n", "geochart = Daru::View::Plot.new(\n", " geo_table.table, type: :geo, adapter: :googlecharts, height: 500, width: 800)\n", "geochart.show_in_iruby" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Marker GeoCharts" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ " Daru::DataFrame(11x3) \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", " \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", "
CityPopulationArea
0Rome27614771285.31
1Milan1324110181.76
2Naples959574117.27
3Turin907563130.17
4Palermo655875158.9
5Genoa607906243.6
6Bologna380181140.7
7Florence371282102.41
8Fiumicino67370213.44
9Anzio5219243.43
10Ciampino3826211
" ], "text/plain": [ "#\n", " City Population Area\n", " 0 Rome 2761477 1285.31\n", " 1 Milan 1324110 181.76\n", " 2 Naples 959574 117.27\n", " 3 Turin 907563 130.17\n", " 4 Palermo 655875 158.9\n", " 5 Genoa 607906 243.6\n", " 6 Bologna 380181 140.7\n", " 7 Florence 371282 102.41\n", " 8 Fiumicino 67370 213.44\n", " 9 Anzio 52192 43.43\n", " 10 Ciampino 38262 11" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "idx = Daru::Index.new ['City', 'Population', 'Area']\n", "data_rows = [['Rome', 2761477, 1285.31],\n", " ['Milan', 1324110, 181.76],\n", " ['Naples', 959574, 117.27],\n", " ['Turin', 907563, 130.17],\n", " ['Palermo', 655875, 158.9],\n", " ['Genoa', 607906, 243.60],\n", " ['Bologna', 380181, 140.7],\n", " ['Florence', 371282, 102.41],\n", " ['Fiumicino', 67370, 213.44],\n", " ['Anzio', 52192, 43.43],\n", " ['Ciampino', 38262, 11]\n", " ]\n", "df_city_pop_area = Daru::DataFrame.rows(data_rows)\n", "df_city_pop_area.vectors = idx\n", "df_city_pop_area" ] }, { "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": [ "geo_marker_table = Daru::View::Table.new(df_city_pop_area, pageSize: 5, height: 200, width: 200)\n", "geo_marker_options = {\n", " region: 'IT',\n", "# FixMe : DisplayMode is not working\n", "# displayMode: 'markers',\n", "# displayMode: 'text',\n", " colorAxis: {colors: ['green', 'blue']},\n", " type: :geo\n", " }\n", "geomarker_chart = Daru::View::Plot.new(\n", " geo_marker_table.table, geo_marker_options)\n", "geomarker_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ], "text/plain": [ "#\"string\", :label=>\"Country\"}, {:type=>\"number\", :label=>\"Latitude\"}], @rows=[[#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #]], @listeners=[], @options={:pageSize=>5, :height=>350, :width=>350}, @data=#\n", " Country Latitude\n", " 0 Algeria 36\n", " 1 Angola -8\n", " 2 Benin 6\n", " 3 Botswana -24\n", " 4 Burkina Fa 12\n", " 5 Burundi -3\n", " 6 Cameroon 3\n", " 7 Canary Isl 28\n", " 8 Cape Verde 15\n", " 9 Central Af 4\n", " 10 Ceuta 35\n", " 11 Chad 12\n", " 12 Comoros -12\n", " 13 Cote d'Ivo 6\n", " 14 Democratic -3\n", " ... ... ..., @user_options={}, @html_id=\"df5283ac-f8ce-468c-bdb8-d08bc14e1f21\">" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "idx = Daru::Index.new ['Country', 'Latitude']\n", "data_rows = [['Algeria', 36], ['Angola', -8], ['Benin', 6], ['Botswana', -24],\n", " ['Burkina Faso', 12], ['Burundi', -3], ['Cameroon', 3],\n", " ['Canary Islands', 28], ['Cape Verde', 15],\n", " ['Central African Republic', 4], ['Ceuta', 35], ['Chad', 12],\n", " ['Comoros', -12], ['Cote d\\'Ivoire', 6],\n", " ['Democratic Republic of the Congo', -3], ['Djibouti', 12],\n", " ['Egypt', 26], ['Equatorial Guinea', 3], ['Eritrea', 15],\n", " ['Ethiopia', 9], ['Gabon', 0], ['Gambia', 13], ['Ghana', 5],\n", " ['Guinea', 10], ['Guinea-Bissau', 12], ['Kenya', -1],\n", " ['Lesotho', -29], ['Liberia', 6], ['Libya', 32], ['Madagascar', nil],\n", " ['Madeira', 33], ['Malawi', -14], ['Mali', 12], ['Mauritania', 18],\n", " ['Mauritius', -20], ['Mayotte', -13], ['Melilla', 35],\n", " ['Morocco', 32], ['Mozambique', -25], ['Namibia', -22],\n", " ['Niger', 14], ['Nigeria', 8], ['Republic of the Congo', -1],\n", " ['Réunion', -21], ['Rwanda', -2], ['Saint Helena', -16],\n", " ['São Tomé and Principe', 0], ['Senegal', 15],\n", " ['Seychelles', -5], ['Sierra Leone', 8], ['Somalia', 2],\n", " ['Sudan', 15], ['South Africa', -30], ['South Sudan', 5],\n", " ['Swaziland', -26], ['Tanzania', -6], ['Togo', 6], ['Tunisia', 34],\n", " ['Uganda', 1], ['Western Sahara', 25], ['Zambia', -15],\n", " ['Zimbabwe', -18]\n", " ]\n", "df_country_latitude = Daru::DataFrame.rows(data_rows)\n", "df_country_latitude.vectors = idx\n", "df_country_latitude\n", "\n", "geo_color_table = Daru::View::Table.new(df_country_latitude, pageSize: 5, height: 350, width: 350)\n", "geo_color_table.table" ] }, { "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", "geo_color_options = {\n", " region: '002', # Africa\n", " colorAxis: {colors: ['#00853f', 'black', '#e31b23']},\n", " backgroundColor: '#81d4fa',\n", " datalessRegionColor: '#f8bbd0',\n", " defaultColor: '#f5f5f5',\n", " type: :geo\n", " }\n", "geocolor_chart = Daru::View::Plot.new(\n", " geo_color_table.table, geo_color_options)\n", "geocolor_chart.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 }