daru-view 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +4 -0
  4. data/.rubocop.yml +122 -0
  5. data/.simplecov +3 -0
  6. data/.travis.yml +18 -0
  7. data/CHANGELOG.md +21 -0
  8. data/CODE_OF_CONDUCT.md +74 -0
  9. data/CONTRIBUTING.md +53 -0
  10. data/Gemfile +11 -0
  11. data/LICENSE.txt +21 -0
  12. data/README.md +287 -0
  13. data/Rakefile +22 -0
  14. data/_config.yml +1 -0
  15. data/daru-view.gemspec +52 -0
  16. data/lib/assets/.keep +0 -0
  17. data/lib/daru/view.rb +127 -0
  18. data/lib/daru/view/adapters/datatables.rb +90 -0
  19. data/lib/daru/view/adapters/googlecharts.rb +180 -0
  20. data/lib/daru/view/adapters/googlecharts/data_table_iruby.rb +86 -0
  21. data/lib/daru/view/adapters/googlecharts/display.rb +54 -0
  22. data/lib/daru/view/adapters/googlecharts/iruby_notebook.rb +15 -0
  23. data/lib/daru/view/adapters/highcharts.rb +114 -0
  24. data/lib/daru/view/adapters/highcharts/core_ext/string.rb +10 -0
  25. data/lib/daru/view/adapters/highcharts/display.rb +58 -0
  26. data/lib/daru/view/adapters/highcharts/iruby_notebook.rb +29 -0
  27. data/lib/daru/view/adapters/highcharts/layout_helper_iruby.rb +76 -0
  28. data/lib/daru/view/adapters/js/googlecharts_js/google_visualr.js +44 -0
  29. data/lib/daru/view/adapters/js/googlecharts_js/loader.js +226 -0
  30. data/lib/daru/view/adapters/js/highcharts_js/adapters/mootools-adapter.js +13 -0
  31. data/lib/daru/view/adapters/js/highcharts_js/adapters/prototype-adapter.js +15 -0
  32. data/lib/daru/view/adapters/js/highcharts_js/highcharts-3d.js +74 -0
  33. data/lib/daru/view/adapters/js/highcharts_js/highcharts-more.js +64 -0
  34. data/lib/daru/view/adapters/js/highcharts_js/highcharts.js +399 -0
  35. data/lib/daru/view/adapters/js/highcharts_js/highstock.js +519 -0
  36. data/lib/daru/view/adapters/js/highcharts_js/modules/accessibility.js +48 -0
  37. data/lib/daru/view/adapters/js/highcharts_js/modules/annotations.js +14 -0
  38. data/lib/daru/view/adapters/js/highcharts_js/modules/boost.js +51 -0
  39. data/lib/daru/view/adapters/js/highcharts_js/modules/broken-axis.js +15 -0
  40. data/lib/daru/view/adapters/js/highcharts_js/modules/canvas-tools.js +133 -0
  41. data/lib/daru/view/adapters/js/highcharts_js/modules/data.js +26 -0
  42. data/lib/daru/view/adapters/js/highcharts_js/modules/drilldown.js +25 -0
  43. data/lib/daru/view/adapters/js/highcharts_js/modules/exporting.js +27 -0
  44. data/lib/daru/view/adapters/js/highcharts_js/modules/funnel.js +13 -0
  45. data/lib/daru/view/adapters/js/highcharts_js/modules/heatmap.js +25 -0
  46. data/lib/daru/view/adapters/js/highcharts_js/modules/no-data-to-display.js +12 -0
  47. data/lib/daru/view/adapters/js/highcharts_js/modules/offline-exporting.js +19 -0
  48. data/lib/daru/view/adapters/js/highcharts_js/modules/solid-gauge.js +14 -0
  49. data/lib/daru/view/adapters/js/highcharts_js/modules/treemap.js +31 -0
  50. data/lib/daru/view/adapters/js/highcharts_js/stock/adapters/mootools-adapter.js +13 -0
  51. data/lib/daru/view/adapters/js/highcharts_js/stock/adapters/prototype-adapter.js +15 -0
  52. data/lib/daru/view/adapters/js/highcharts_js/stock/highcharts-more.js +64 -0
  53. data/lib/daru/view/adapters/js/highcharts_js/stock/modules/exporting.js +27 -0
  54. data/lib/daru/view/adapters/js/highcharts_js/stock/modules/funnel.js +13 -0
  55. data/lib/daru/view/adapters/js/nyaplot_js/d3-downloadable.js +129 -0
  56. data/lib/daru/view/adapters/js/nyaplot_js/d3.min.js +5 -0
  57. data/lib/daru/view/adapters/js/nyaplot_js/nyaplot.js +5294 -0
  58. data/lib/daru/view/adapters/nyaplot.rb +62 -0
  59. data/lib/daru/view/adapters/nyaplot/display.rb +9 -0
  60. data/lib/daru/view/adapters/nyaplot/iruby_notebook.rb +22 -0
  61. data/lib/daru/view/app/rails/helpers/view_helper.rb +26 -0
  62. data/lib/daru/view/app/rails/railtie.rb +15 -0
  63. data/lib/daru/view/plot.rb +106 -0
  64. data/lib/daru/view/table.rb +99 -0
  65. data/lib/daru/view/templates/googlecharts/chart_div.erb +4 -0
  66. data/lib/daru/view/templates/googlecharts/init.inline.js.erb +16 -0
  67. data/lib/daru/view/templates/highcharts/init.inline.js.erb +16 -0
  68. data/lib/daru/view/templates/highcharts/static_html.erb +7 -0
  69. data/lib/daru/view/templates/nyaplot/init.inline.js.erb +16 -0
  70. data/lib/daru/view/templates/nyaplot/init_script.erb +3 -0
  71. data/lib/daru/view/version.rb +5 -0
  72. data/lib/tasks/.keep +0 -0
  73. data/lib/tasks/google_charts.rake +25 -0
  74. data/lib/tasks/high_charts.rake +60 -0
  75. data/lib/tasks/nyaplot.rake +25 -0
  76. data/spec/adapters/datatables_spec.rb +21 -0
  77. data/spec/adapters/googlecharts_spec.rb +34 -0
  78. data/spec/adapters/highcharts_spec.rb +177 -0
  79. data/spec/adapters/nyaplot_spec.rb +447 -0
  80. data/spec/app/rails/helpers/view_helpers_spec.rb +35 -0
  81. data/spec/dummy_iruby/.ipynb_checkpoints/Daru DataFrame and DataTables-checkpoint.ipynb +16091 -0
  82. data/spec/dummy_iruby/.ipynb_checkpoints/DataTables | basic examples-checkpoint.ipynb +6 -0
  83. data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Line Chart-checkpoint.ipynb +1389 -0
  84. data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Area Chart-checkpoint.ipynb +606 -0
  85. data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Bar Chart-checkpoint.ipynb +1404 -0
  86. data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Bubble Chart-checkpoint.ipynb +866 -0
  87. data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Candlestick Chart-checkpoint.ipynb +607 -0
  88. data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Combo Chart-checkpoint.ipynb +478 -0
  89. data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Histogram-checkpoint.ipynb +1182 -0
  90. data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Org Chart-checkpoint.ipynb +6 -0
  91. data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Pie Chart-checkpoint.ipynb +6 -0
  92. data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Stepped Area Chart-checkpoint.ipynb +699 -0
  93. data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Timeline-checkpoint.ipynb +1523 -0
  94. data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Treemap-checkpoint.ipynb +650 -0
  95. data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | gauge-checkpoint.ipynb +477 -0
  96. data/spec/dummy_iruby/.ipynb_checkpoints/Google Charts | Basics-checkpoint.ipynb +1881 -0
  97. data/spec/dummy_iruby/.ipynb_checkpoints/Google Charts | Column Charts-checkpoint.ipynb +6 -0
  98. data/spec/dummy_iruby/.ipynb_checkpoints/Google Charts | Geo Charts examples-checkpoint.ipynb +791 -0
  99. data/spec/dummy_iruby/.ipynb_checkpoints/Google Charts | Scatter Chart-checkpoint.ipynb +1570 -0
  100. data/spec/dummy_iruby/.ipynb_checkpoints/GoolgeChart | Datatables-checkpoint.ipynb +1792 -0
  101. data/spec/dummy_iruby/.ipynb_checkpoints/HighCharts - Area chart-checkpoint.ipynb +1272 -0
  102. data/spec/dummy_iruby/.ipynb_checkpoints/HighCharts - Bar Chart-checkpoint.ipynb +877 -0
  103. data/spec/dummy_iruby/.ipynb_checkpoints/HighCharts - column charts-checkpoint.ipynb +1587 -0
  104. data/spec/dummy_iruby/.ipynb_checkpoints/HighCharts- Pie charts-checkpoint.ipynb +1126 -0
  105. data/spec/dummy_iruby/.ipynb_checkpoints/Highcharts - Combinations -checkpoint.ipynb +925 -0
  106. data/spec/dummy_iruby/.ipynb_checkpoints/Highcharts - Daynamic charts-checkpoint.ipynb +839 -0
  107. data/spec/dummy_iruby/.ipynb_checkpoints/Highcharts - line graphs-checkpoint.ipynb +1297 -0
  108. data/spec/dummy_iruby/.ipynb_checkpoints/Highcharts - line graphs2-checkpoint.ipynb +879 -0
  109. data/spec/dummy_iruby/.ipynb_checkpoints/Highcharts - scatter -bubble charts-checkpoint.ipynb +1071 -0
  110. data/spec/dummy_iruby/.ipynb_checkpoints/Highcharts | add_series method and highcharts examples-checkpoint.ipynb +1165 -0
  111. data/spec/dummy_iruby/.ipynb_checkpoints/Nyaplot basics | Daru Examples-checkpoint.ipynb +1383 -0
  112. data/spec/dummy_iruby/.ipynb_checkpoints/Nyaplot other examples-checkpoint.ipynb +6 -0
  113. data/spec/dummy_iruby/.ipynb_checkpoints/Nyaplot testing -checkpoint.ipynb +270 -0
  114. data/spec/dummy_iruby/.ipynb_checkpoints/Nyaplot | Creating Visualizations with DataFrame | from daru examples-checkpoint.ipynb +1716 -0
  115. data/spec/dummy_iruby/.ipynb_checkpoints/Pie Chart using HighCharts2-checkpoint.ipynb +784 -0
  116. data/spec/dummy_iruby/.ipynb_checkpoints/highcharts - Use HTML table (generated from daru) as data source-checkpoint.ipynb +956 -0
  117. data/spec/dummy_iruby/.ipynb_checkpoints/spec_testing-checkpoint.ipynb +1433 -0
  118. data/spec/dummy_iruby/Daru DataFrame and DataTables.ipynb +16091 -0
  119. data/spec/dummy_iruby/DataTables | basic examples.ipynb +15587 -0
  120. data/spec/dummy_iruby/Gemfile +33 -0
  121. data/spec/dummy_iruby/Google Chart | Line Chart.ipynb +1389 -0
  122. data/spec/dummy_iruby/Google Chart | Area Chart.ipynb +606 -0
  123. data/spec/dummy_iruby/Google Chart | Bar Chart.ipynb +1394 -0
  124. data/spec/dummy_iruby/Google Chart | Bubble Chart.ipynb +866 -0
  125. data/spec/dummy_iruby/Google Chart | Candlestick Chart.ipynb +607 -0
  126. data/spec/dummy_iruby/Google Chart | Combo Chart.ipynb +478 -0
  127. data/spec/dummy_iruby/Google Chart | Histogram.ipynb +1182 -0
  128. data/spec/dummy_iruby/Google Chart | Org Chart.ipynb +474 -0
  129. data/spec/dummy_iruby/Google Chart | Pie Chart.ipynb +1177 -0
  130. data/spec/dummy_iruby/Google Chart | Stepped Area Chart.ipynb +699 -0
  131. data/spec/dummy_iruby/Google Chart | Timeline.ipynb +1523 -0
  132. data/spec/dummy_iruby/Google Chart | Treemap.ipynb +659 -0
  133. data/spec/dummy_iruby/Google Chart | gauge.ipynb +477 -0
  134. data/spec/dummy_iruby/Google Charts | Basics.ipynb +1882 -0
  135. data/spec/dummy_iruby/Google Charts | Column Charts.ipynb +1138 -0
  136. data/spec/dummy_iruby/Google Charts | Geo Charts examples.ipynb +791 -0
  137. data/spec/dummy_iruby/Google Charts | Scatter Chart.ipynb +1570 -0
  138. data/spec/dummy_iruby/GoolgeChart | Datatables.ipynb +1801 -0
  139. data/spec/dummy_iruby/HighCharts - Area chart.ipynb +1272 -0
  140. data/spec/dummy_iruby/HighCharts - Bar Chart.ipynb +877 -0
  141. data/spec/dummy_iruby/HighCharts - column charts.ipynb +1587 -0
  142. data/spec/dummy_iruby/HighCharts- Pie charts.ipynb +1197 -0
  143. data/spec/dummy_iruby/Highcharts - Combinations .ipynb +925 -0
  144. data/spec/dummy_iruby/Highcharts - Daynamic charts.ipynb +839 -0
  145. data/spec/dummy_iruby/Highcharts - line graphs.ipynb +1297 -0
  146. data/spec/dummy_iruby/Highcharts - line graphs2.ipynb +879 -0
  147. data/spec/dummy_iruby/Highcharts - scatter -bubble charts.ipynb +1071 -0
  148. data/spec/dummy_iruby/Highcharts | add_series method and highcharts examples.ipynb +1228 -0
  149. data/spec/dummy_iruby/Nyaplot basics | Daru Examples.ipynb +1390 -0
  150. data/spec/dummy_iruby/Nyaplot other examples.ipynb +589 -0
  151. data/spec/dummy_iruby/Nyaplot testing .ipynb +270 -0
  152. data/spec/dummy_iruby/Nyaplot | Creating Visualizations with DataFrame | from daru examples.ipynb +1716 -0
  153. data/spec/dummy_iruby/Pie Chart using HighCharts2.ipynb +784 -0
  154. data/spec/dummy_iruby/highcharts - Use HTML table (generated from daru) as data source.ipynb +951 -0
  155. data/spec/dummy_iruby/spec_testing.ipynb +1433 -0
  156. data/spec/dummy_nanoc/Gemfile +12 -0
  157. data/spec/dummy_nanoc/README.md +40 -0
  158. data/spec/dummy_nanoc/Rules +90 -0
  159. data/spec/dummy_nanoc/content/googlecharts/index.html +29 -0
  160. data/spec/dummy_nanoc/content/highcharts/index.html +42 -0
  161. data/spec/dummy_nanoc/content/index.html +26 -0
  162. data/spec/dummy_nanoc/content/nyaplot/index.html +9 -0
  163. data/spec/dummy_nanoc/content/stylesheet.css +101 -0
  164. data/spec/dummy_nanoc/layouts/default.html +31 -0
  165. data/spec/dummy_nanoc/layouts/googlecharts_layout.html +30 -0
  166. data/spec/dummy_nanoc/layouts/highcharts_layout.html +30 -0
  167. data/spec/dummy_nanoc/layouts/nyaplot_layout.html +30 -0
  168. data/spec/dummy_nanoc/lib/default.rb +300 -0
  169. data/spec/dummy_nanoc/nanoc.yaml +90 -0
  170. data/spec/dummy_nanoc/output/googlecharts/index.html +390 -0
  171. data/spec/dummy_nanoc/output/highcharts/index.html +1153 -0
  172. data/spec/dummy_nanoc/output/index.html +87 -0
  173. data/spec/dummy_nanoc/output/nyaplot/index.html +135 -0
  174. data/spec/dummy_nanoc/output/stylesheet.css +101 -0
  175. data/spec/dummy_nanoc/tmp/nanoc/1029d67644815/checksums +0 -0
  176. data/spec/dummy_nanoc/tmp/nanoc/1029d67644815/compiled_content +2229 -0
  177. data/spec/dummy_nanoc/tmp/nanoc/1029d67644815/dependencies +5 -0
  178. data/spec/dummy_nanoc/tmp/nanoc/1029d67644815/outdatedness +0 -0
  179. data/spec/dummy_nanoc/tmp/nanoc/1029d67644815/rule_memory +0 -0
  180. data/spec/dummy_sinatra/Gemfile +9 -0
  181. data/spec/dummy_sinatra/README.md +15 -0
  182. data/spec/dummy_sinatra/app.rb +143 -0
  183. data/spec/dummy_sinatra/config.ru +0 -0
  184. data/spec/dummy_sinatra/views/googlecharts.erb +31 -0
  185. data/spec/dummy_sinatra/views/googlecharts_layout.erb +12 -0
  186. data/spec/dummy_sinatra/views/highcharts.erb +15 -0
  187. data/spec/dummy_sinatra/views/highcharts_layout.erb +12 -0
  188. data/spec/dummy_sinatra/views/index.erb +2 -0
  189. data/spec/dummy_sinatra/views/layout.erb +26 -0
  190. data/spec/dummy_sinatra/views/nyaplot.erb +13 -0
  191. data/spec/dummy_sinatra/views/nyaplot_layout.erb +14 -0
  192. data/spec/plot_spec.rb +86 -0
  193. data/spec/spec_helper.rb +11 -0
  194. metadata +568 -0
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'bundler/setup'
4
+ require 'rubygems/tasks'
5
+ Gem::Tasks.new
6
+
7
+ require 'rspec/core/rake_task'
8
+ RSpec::Core::RakeTask.new
9
+
10
+ require 'rubocop/rake_task'
11
+ RuboCop::RakeTask.new
12
+
13
+ desc 'Default: run unit specs.'
14
+ task :default => %w[spec rubocop]
15
+
16
+
17
+ import 'lib/tasks/high_charts.rake'
18
+ import 'lib/tasks/nyaplot.rake'
19
+ import 'lib/tasks/google_charts.rake'
20
+
21
+ # TODO: add Nyaplot
22
+ task :update_all => ["googlecharts:update", "highcharts:update"]
data/_config.yml ADDED
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-hacker
data/daru-view.gemspec ADDED
@@ -0,0 +1,52 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+
7
+ require 'daru/view/version'
8
+
9
+ Daru::View::DESCRIPTION = <<MSG
10
+ Daru (Data Analysis in RUby) is a library for analysis, manipulation and
11
+ visualization of data. Daru-view is for easy and interactive plotting in web
12
+ application & IRuby notebook. It can work in frameworks e.g. Rails, Sinatra,
13
+ Nanoc and hopefully in others too.
14
+ MSG
15
+
16
+ Gem::Specification.new do |spec|
17
+ spec.name = 'daru-view'
18
+ spec.version = Daru::View::VERSION
19
+ spec.authors = ['Shekhar Prasad Rajak']
20
+ spec.email = ['shekharrajak@live.com']
21
+
22
+ spec.summary = 'Plugin gem to Data Analysis in RUby(Daru) for visualisation of data'
23
+ spec.description = Daru::View::DESCRIPTION
24
+ spec.homepage = 'https://github.com/Shekharrajak/daru-view'
25
+ spec.license = 'MIT'
26
+ spec.require_paths = ['lib']
27
+ spec.files = `git ls-files -z`.split("\x0")
28
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
29
+
30
+ spec.add_development_dependency 'bundler'
31
+ spec.add_development_dependency 'rspec'
32
+ spec.add_development_dependency 'simplecov'
33
+ spec.add_development_dependency "rake"
34
+ spec.add_development_dependency 'pry'
35
+
36
+ spec.add_development_dependency 'pry-byebug'
37
+ spec.add_development_dependency 'rubocop'
38
+
39
+ # fetching latest gem from the Gemfile
40
+ spec.add_runtime_dependency 'google_visualr'
41
+ spec.add_runtime_dependency 'lazy_high_charts'
42
+ spec.add_runtime_dependency 'daru'
43
+ spec.add_runtime_dependency 'nyaplot'
44
+ spec.add_runtime_dependency 'daru-data_tables'
45
+
46
+ # lazy_high_charts dependency
47
+ spec.add_runtime_dependency 'actionview'
48
+
49
+ # build gem and release it on rubygems
50
+ spec.add_development_dependency 'rubygems-tasks'
51
+ end
52
+
data/lib/assets/.keep ADDED
File without changes
data/lib/daru/view.rb ADDED
@@ -0,0 +1,127 @@
1
+ require 'daru/view/version'
2
+ require 'daru/view/plot'
3
+ require 'daru/view/adapters/highcharts/display'
4
+ require 'daru/view/adapters/nyaplot/display'
5
+ require 'daru/view/adapters/googlecharts/display'
6
+ require 'daru/view/table'
7
+
8
+ # needed in load_lib_in_iruby method
9
+ require 'daru/view/adapters/highcharts/iruby_notebook'
10
+ require 'daru/view/adapters/nyaplot/iruby_notebook'
11
+ require 'daru/view/adapters/googlecharts/iruby_notebook'
12
+
13
+ # Rails Helper
14
+ require 'daru/view/app/rails/railtie.rb' if defined?(Rails)
15
+
16
+ module Daru
17
+ module View
18
+ # default Nyaplot library is used.
19
+ @plotting_library = :nyaplot
20
+ Daru::View::Plot.adapter = @plotting_library
21
+
22
+ class << self
23
+ attr_reader :plotting_library, :table_library
24
+
25
+ # New plotting library is set. Same time Daru::View::Plot.adapter is set.
26
+ def plotting_library=(lib)
27
+ case lib
28
+ when :nyaplot, :highcharts
29
+ # plot charts
30
+ @plotting_library = lib
31
+ Daru::View::Plot.adapter = lib
32
+ when :googlecharts
33
+ # plot chart and table drawing
34
+ @plotting_library = lib
35
+ Daru::View::Plot.adapter = lib
36
+ Daru::View::Table.adapter = lib
37
+ else
38
+ raise ArgumentError, "Unsupported library #{lib}"
39
+ end
40
+
41
+ # When code is running in console/terminal then IRuby NameError.
42
+ # Since IRuby methods can't work in console.
43
+ begin
44
+ load_lib_in_iruby lib.to_s if defined? IRuby
45
+ rescue NameError # rubocop:disable Lint/HandleExceptions
46
+ end
47
+ end
48
+
49
+ # New table library is set. Same time Daru::View::Table.adapter is set.
50
+ def table_library=(lib)
51
+ case lib
52
+ when :googlecharts
53
+ # plot chart and table drawing
54
+ @plotting_library = lib
55
+ Daru::View::Plot.adapter = lib
56
+ Daru::View::Table.adapter = lib
57
+ when :datatables
58
+ # only for table drawing
59
+ Daru::View::Table.adapter = lib
60
+ else
61
+ raise ArgumentError, "Unsupported library #{lib}"
62
+ end
63
+
64
+ # When code is running in console/terminal then IRuby NameError.
65
+ # Since IRuby methods can't work in console.
66
+ begin
67
+ load_lib_in_iruby lib.to_s if defined? IRuby
68
+ rescue NameError # rubocop:disable Lint/HandleExceptions
69
+ end
70
+ end
71
+
72
+ # Load the dependent JS files in IRuby notebook. Those JS will help in
73
+ # plotting the charts in IRuby cell.
74
+ #
75
+ # @example
76
+ #
77
+ # To load the dependent JS file for Nyaplot library
78
+ # plotting system (Nyaplot.js, d3.js):
79
+ #
80
+ # Daru::View.load_lib_in_iruby('nyaplot')
81
+ #
82
+ # To load the HighCharts dependent JS
83
+ # files (highcharts.js, highcharts-3d.js, highstock.js):
84
+ #
85
+ # Daru::View.load_lib_in_iruby('highcharts')
86
+ #
87
+ def load_lib_in_iruby(library)
88
+ if library.match('highcharts')
89
+ library = 'LazyHighCharts'
90
+ Object.const_get(library).init_iruby
91
+ elsif library.match('googlecharts')
92
+ library = 'GoogleVisualr'
93
+ Object.const_get(library).init_iruby
94
+ elsif library.match('datatables')
95
+ library = 'DataTables'
96
+ Object.const_get(library).init_iruby
97
+ else
98
+ Object.const_get(library.capitalize).init_iruby
99
+ end
100
+ end
101
+
102
+ # dependent script for the library. It must be added in the head tag
103
+ # of the web application.
104
+ #
105
+ # @example
106
+ #
107
+ # dep_js = Daru::View.dependent_script(:highcharts)
108
+ #
109
+ # use in Rails app : <%=raw dep_js %>
110
+ #
111
+ def dependent_script(lib=:nyaplot)
112
+ case lib
113
+ when :nyaplot
114
+ Nyaplot.init_script
115
+ when :highcharts
116
+ LazyHighCharts.init_script
117
+ when :googlecharts
118
+ GoogleVisualr.init_script
119
+ when :datatables
120
+ DataTables.init_script
121
+ else
122
+ raise ArgumentError, "Unsupported library #{lib}"
123
+ end
124
+ end
125
+ end
126
+ end # view end
127
+ end
@@ -0,0 +1,90 @@
1
+ require 'daru/data_tables'
2
+ require 'daru'
3
+ require 'securerandom'
4
+
5
+ module Daru
6
+ module View
7
+ module Adapter
8
+ module DatatablesAdapter
9
+ extend self # rubocop:disable Style/ModuleFunction
10
+
11
+ # Read : https://datatables.net/ to understand
12
+ # the datatables option concept.
13
+ #
14
+ # TODO : this docs must be improved
15
+ def init_table(data=[], options={})
16
+ # TODO : create data array from the df and vector data. So that
17
+ # we can directly use the array.(No need to create df or vector and
18
+ # generate the html table using to_html)
19
+ if data.is_a?(Array)
20
+ data_name = 'series_data'+ SecureRandom.uuid
21
+ data =
22
+ if data.all? { |e| e.class==Array }
23
+ Daru::DataFrame.rows(data, name: data_name)
24
+ else
25
+ Daru::Vector.new(data, name: data_name)
26
+ end
27
+ end
28
+ # options[:data] = data_in_array unless data_in_array.empty?
29
+ @table = Daru::DataTables::DataTable.new(options)
30
+ @data = data
31
+ @table
32
+ end
33
+
34
+ def init_script
35
+ Daru::DataTables.init_script
36
+ end
37
+
38
+ def generate_body(table)
39
+ table_opts = {
40
+ class: 'display',
41
+ cellspacing: '0',
42
+ width: '100%',
43
+ table_html: @data.to_html_thead + @data.to_html_tbody
44
+ }
45
+ html_options ={
46
+ table_options: table_opts
47
+ }
48
+ table.to_html(@data.name, html_options)
49
+ end
50
+
51
+ def export_html_file(table, path='./table.html')
52
+ # TODO
53
+ end
54
+
55
+ def show_in_iruby(table)
56
+ table.show_in_iruby
57
+ end
58
+
59
+ def generate_html(table)
60
+ # TODO
61
+ end
62
+
63
+ def init_iruby
64
+ Daru::DataTables.init_iruby
65
+ end
66
+
67
+ private
68
+
69
+ # DataTables accept the data as Array of array.
70
+ #
71
+ # TODO : I didn't find use case for multi index.
72
+ def to_data_array(data_set)
73
+ case
74
+ when data_set.is_a?(Daru::DataFrame)
75
+ return ArgumentError unless data_set.index.is_a?(Daru::Index)
76
+ data_set.access_row_tuples_by_indexs(*data_set.index.to_a)
77
+ when data_set.is_a?(Daru::Vector)
78
+ rows = []
79
+ data_set.to_a.each { |a| rows << [a] }
80
+ rows
81
+ when data_set.is_a?(Array)
82
+ data_set
83
+ else
84
+ raise ArgumentError # TODO: error msg
85
+ end
86
+ end
87
+ end # DatatablesAdapter end
88
+ end # Adapter end
89
+ end
90
+ end
@@ -0,0 +1,180 @@
1
+ require 'google_visualr'
2
+ require_relative 'googlecharts/iruby_notebook'
3
+ require_relative 'googlecharts/display'
4
+ require 'daru'
5
+ require 'bigdecimal'
6
+
7
+ module Daru
8
+ module View
9
+ module Adapter
10
+ module GooglechartsAdapter
11
+ extend self # rubocop:disable Style/ModuleFunction
12
+
13
+ # Read : https://developers.google.com/chart/ to understand
14
+ # the google charts option concept.
15
+ # and google_visualr : http://googlevisualr.herokuapp.com/
16
+ #
17
+ # TODO : this docs must be improved
18
+ def init(data=[], options={})
19
+ @table = GoogleVisualr::DataTable.new
20
+ @table =
21
+ if data.is_a?(Daru::View::Table) && data.table.is_a?(GoogleVisualr::DataTable)
22
+ data.table
23
+ elsif data.is_a?(GoogleVisualr::DataTable)
24
+ data
25
+ else
26
+ add_data_in_table(data)
27
+ end
28
+ chart_type = extract_chart_type(options)
29
+ @chart = GoogleVisualr::Interactive.const_get(
30
+ chart_type
31
+ ).new(@table, options)
32
+ @chart
33
+ end
34
+
35
+ def init_table(data=[], options={})
36
+ # if `options` is something like this :
37
+ # {
38
+ # cols: [{id: 'task', label: 'Employee Name', type: 'string'},
39
+ # {id: 'startDate', label: 'Start Date', type: 'date'}],
40
+ # rows: [{c:[{v: 'Mike'}, {v: new Date(2008, 1, 28), f:'February 28, 2008'}]},
41
+ # {c:[{v: 'Bob'}, {v: new Date(2007, 5, 1)}]},
42
+ # {c:[{v: 'Alice'}, {v: new Date(2006, 7, 16)}]},
43
+ # {c:[{v: 'Frank'}, {v: new Date(2007, 11, 28)}]},
44
+ # {c:[{v: 'Floyd'}, {v: new Date(2005, 3, 13)}]},
45
+ # {c:[{v: 'Fritz'}, {v: new Date(2011, 6, 1)}]}
46
+ # ]
47
+ # }
48
+ # then directly DatTable is created using options. Use data=[] or nil
49
+ @table = GoogleVisualr::DataTable.new(options)
50
+ add_data_in_table(data)
51
+ @table
52
+ end
53
+
54
+ def init_script
55
+ GoogleVisualr.init_script
56
+ end
57
+
58
+ def generate_body(plot)
59
+ plot.to_html
60
+ end
61
+
62
+ def export_html_file(plot, path='./plot.html')
63
+ path = File.expand_path(path, Dir.pwd)
64
+ str = generate_html(plot)
65
+ File.write(path, str)
66
+ end
67
+
68
+ def show_in_iruby(plot)
69
+ plot.show_in_iruby
70
+ end
71
+
72
+ def generate_html(plot)
73
+ # TODO: modify code
74
+ path = File.expand_path('../../templates/googlecharts/chart_div.erb', __FILE__)
75
+ template = File.read(path)
76
+ initial_script = init_script
77
+ chart_script = generate_body(plots)
78
+ ERB.new(template).result(binding)
79
+ end
80
+
81
+ def init_iruby
82
+ GoogleVisualr.init_iruby
83
+ end
84
+
85
+ # Generally, in opts Hash, :name, :type, :data , :center=> [X, Y],
86
+ # :size=> Integer, :showInLegend=> Bool, etc may present.
87
+ def add_series(plot, opts={})
88
+ plot.series(opts)
89
+ plot
90
+ end
91
+
92
+ private
93
+
94
+ def extract_chart_type(options)
95
+ # TODO: Imprvoe this method.
96
+ chart_type = options[:type].nil? ? 'Line' : options.delete(:type)
97
+ chart_type = chart_type.to_s.capitalize
98
+ chart_type = 'SteppedArea' if chart_type == 'Steppedarea'
99
+ chart_type = 'TreeMap' if chart_type == 'Treemap'
100
+ direct_name = %w[Map Histogram TreeMap Timeline Gauge]
101
+ direct_name.include?(chart_type) ? chart_type : chart_type + 'Chart'
102
+ end
103
+
104
+ # For google table, column is needed.
105
+ #
106
+ # note : 1st line must be colmns name and then all others
107
+ # data rows
108
+ #
109
+ # TODO : Currently I didn't find use case for multi index.
110
+ def add_data_in_table(data_set) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity, Metrics/LineLength
111
+ case
112
+ when data_set.is_a?(Daru::DataFrame)
113
+ return ArgumentError unless data_set.index.is_a?(Daru::Index)
114
+ rows = data_set.access_row_tuples_by_indexs(*data_set.index.to_a)
115
+ data_set.vectors.to_a.each do |vec|
116
+ @table.new_column(converted_type_to_js(vec, data_set), vec)
117
+ end
118
+ when data_set.is_a?(Daru::Vector)
119
+ vec_name = data_set.name.nil? ? 'Series' : data_set.name
120
+ @table.new_column(return_js_type(data_set[0]), vec_name)
121
+ rows = []
122
+ data_set.to_a.each { |a| rows << [a] }
123
+ when data_set.is_a?(Array)
124
+ return GoogleVisualr::DataTable.new if data_set.empty?
125
+
126
+ data_set[0].each_with_index do |col, indx|
127
+ # TODO: below while loop must be improved. Similar thing for
128
+ # above 2 cases.
129
+ row_index = 1
130
+ type = return_js_type(data_set[row_index][indx])
131
+ while type.nil?
132
+ row_index += 1
133
+ type = return_js_type(data_set[row_index][indx])
134
+ end
135
+ @table.new_column(type, col)
136
+ end
137
+ data_set.shift # 1st row removed
138
+ rows = data_set
139
+ when data_set.is_a?(Hash)
140
+ @table = GoogleVisualr::DataTable.new(data_set)
141
+ return
142
+ else
143
+ raise ArgumentError # TODO: error msg
144
+ end
145
+ @table.add_rows(rows)
146
+ @table
147
+ end
148
+
149
+ def converted_type_to_js(vec_name, data_set)
150
+ # Assuming all the data type is same for all the column values.
151
+ case
152
+ when data_set.is_a?(Daru::DataFrame)
153
+ return_js_type(data_set[vec_name][0])
154
+ when data_set.is_a?(Daru::Vector)
155
+ return_js_type(data_set[0])
156
+ end
157
+ end
158
+
159
+ # TODO : fix Metrics/PerceivedComplexity rubocop error
160
+ def return_js_type(data) # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
161
+ data = data.is_a?(Hash) ? data[:v] : data
162
+ case
163
+ when data.nil?
164
+ return
165
+ when data.is_a?(String)
166
+ return 'string'
167
+ when data.is_a?(Integer) || data.is_a?(Float) || data.is_a?(BigDecimal)
168
+ return 'number'
169
+ when data.is_a?(TrueClass) || data.is_a?(FalseClass)
170
+ return 'boolean'
171
+ when data.is_a?(DateTime) || data.is_a?(Time)
172
+ return 'datetime'
173
+ when data.is_a?(Date)
174
+ return 'date'
175
+ end
176
+ end
177
+ end # GooglechartsAdapter end
178
+ end # Adapter end
179
+ end
180
+ end