{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "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": { "collapsed": false }, "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.Mi=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.Wl=function(b,c){if(K.tg()){var d=K.global.document;if(!K.Ge&&d.readyState==t){if(/\\bdeps.js$/.test(b))return!1;throw Error('Cannot write \"'+b+'\" after document load');}void 0===c?K.fi?(K.eh=!0,c=\" onreadystatechange='goog.onScriptLoad_(this, \"+ ++K.Sg+\")' \",d.write(n+b+'\"'+c+\">\\x3c/script>\")):K.Ge?K.Mi(b):K.Vl(b):d.write('\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = [\n", " ['Location', 'Parent', 'Market trade volume (size)', 'Market increase/decrease (color)'],\n", " ['Global', nil, 0, 0],\n", " ['America', 'Global', 0, 0],\n", " ['Europe', 'Global', 0, 0],\n", " ['Asia', 'Global', 0, 0],\n", " ['Australia', 'Global', 0, 0],\n", " ['Africa', 'Global', 0, 0],\n", " ['Brazil', 'America', 11, 10],\n", " ['USA', 'America', 52, 31],\n", " ['Mexico', 'America', 24, 12],\n", " ['Canada', 'America', 16, -23],\n", " ['France', 'Europe', 42, -11],\n", " ['Germany', 'Europe', 31, -2],\n", " ['Sweden', 'Europe', 22, -13],\n", " ['Italy', 'Europe', 17, 4],\n", " ['UK', 'Europe', 21, -5],\n", " ['China', 'Asia', 36, 4],\n", " ['Japan', 'Asia', 20, -12],\n", " ['India', 'Asia', 40, 63],\n", " ['Laos', 'Asia', 4, 34],\n", " ['Mongolia', 'Asia', 1, -5],\n", " ['Israel', 'Asia', 12, 24],\n", " ['Iran', 'Asia', 18, 13],\n", " ['Pakistan', 'Asia', 11, -52],\n", " ['Egypt', 'Africa', 21, 0],\n", " ['S. Africa', 'Africa', 30, 43],\n", " ['Sudan', 'Africa', 12, 2],\n", " ['Congo', 'Africa', 10, 12],\n", " ['Zaire', 'Africa', 8, 10]\n", " ]\n", "\n", "treemap_table = Daru::View::Table.new(data, pageSize: 8)\n", "treemap_table.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "treemap_basic_options = {\n", " type: :treemap,\n", "}\n", "# We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source\n", "treemap_basic_chart = Daru::View::Plot.new(treemap_table.table, treemap_basic_options)\n", "treemap_basic_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "treemap_basic_options = {\n", " type: :treemap,\n", " minColor: '#f00',\n", " midColor: '#ddd',\n", " maxColor: '#0d0',\n", " headerHeight: 15,\n", " fontColor: 'black',\n", " showScale: true\n", "}\n", "# We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source\n", "treemap_basic_chart = Daru::View::Plot.new(treemap_table.table, treemap_basic_options)\n", "treemap_basic_chart.show_in_iruby" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Highlights" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "treemap_basic_options = {\n", " type: :treemap,\n", "highlightOnMouseOver: true,\n", " maxDepth: 1,\n", " maxPostDepth: 2,\n", " minHighlightColor: '#8c6bb1',\n", " midHighlightColor: '#9ebcda',\n", " maxHighlightColor: '#edf8fb',\n", " minColor: '#009688',\n", " midColor: '#f7f7f7',\n", " maxColor: '#ee8100',\n", " headerHeight: 15,\n", " showScale: true,\n", " height: 500,\n", " useWeightedAverageForAggregation: true\n", "}\n", "# We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source\n", "treemap_basic_chart = Daru::View::Plot.new(treemap_table.table, treemap_basic_options)\n", "treemap_basic_chart.show_in_iruby" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Tooltips" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "js_method = <<-EOJS\n", "function showStaticTooltip(row, size, value) {\n", " return '
' +\n", " 'Read more about the kingdoms of life.
';\n", " }\n", "EOJS\n", "treemap_basic_options = {\n", " type: :treemap,\n", " minColor: '#e7711c',\n", " midColor: '#fff',\n", " maxColor: '#4374e0',\n", " showScale: true,\n", "# generateTooltip: js_method\n", "}\n", "# We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source\n", "treemap_basic_chart = Daru::View::Plot.new(treemap_table.table, treemap_basic_options)\n", "treemap_basic_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Ruby 2.3.1", "language": "ruby", "name": "ruby" }, "language_info": { "file_extension": ".rb", "mimetype": "application/x-ruby", "name": "ruby", "version": "2.3.1" } }, "nbformat": 4, "nbformat_minor": 2 }