From 93ba9b066e274a2ef17b58ef6f1ede4aa7125b04 Mon Sep 17 00:00:00 2001 From: shekharrajak Date: Mon, 7 Jan 2019 18:56:06 +0530 Subject: [PATCH 01/10] easy highChart example added --- README.md | 52 +++++++++------------------------------------------- 1 file changed, 9 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index a133240..035995e 100644 --- a/README.md +++ b/README.md @@ -115,56 +115,22 @@ HighCharts example : # set the library, to plot charts Daru::View.plotting_library = :highcharts -# options for the charts -opts = { - chart: {defaultSeriesType: 'line'}, - title: { - text: 'Solar Employment Growth by Sector, 2010-2016' - }, - - subtitle: { - text: 'Source: thesolarfoundation.com' - }, - - yAxis: { - title: { - text: 'Number of Employees' - } - }, - legend: { - layout: 'vertical', - align: 'right', - verticalAlign: 'middle' - }, - - plotOptions: { - # this is not working. Find the bug - # series: { - # pointStart: 43934 - # } - }, - } - -# data for the charts -series_dt = ([{ - name: 'Tokyo', - data: [7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6] - }, { - name: 'London', - data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8] - }]) +# Simple line chart +@line_graph = Daru::View::Plot.new( + data=[43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175] +) -# initialize -@line_graph = Daru::View::Plot.new(series_dt, opts) +# to see graph in IRuby noteboook +@line_graph.show_in_iruby +# to see graph in any ruby web application framework # Add this line in your view file, where you want to see you graph in web application. (It will put the html code of the line graph in web page) - <%=raw @line_graph.div %> -# Now refresh the page, you will be able to see your graph. - ``` +[[ https://github.com/shekharrajak/medium-daru-view-blog/blob/master/GIF_Images/HighChart blog/lineChart.gif]] + Nyaplot example : From 54d84b7b43eb2b03afe0d54a92a049aa55ed237a Mon Sep 17 00:00:00 2001 From: shekharrajak Date: Mon, 7 Jan 2019 19:03:41 +0530 Subject: [PATCH 02/10] GIF url added for line chart --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 035995e..fb7d666 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ Daru::View.plotting_library = :highcharts ``` -[[ https://github.com/shekharrajak/medium-daru-view-blog/blob/master/GIF_Images/HighChart blog/lineChart.gif]] +![Line Graph](https://github.com/shekharrajak/medium-daru-view-blog/blob/master/GIF_Images/HighChart blog/lineChart.gif) Nyaplot example : From e61bf4b094d310d852cd231b8c826e83f4d9cfc2 Mon Sep 17 00:00:00 2001 From: shekharrajak Date: Mon, 7 Jan 2019 19:07:40 +0530 Subject: [PATCH 03/10] readme file updated - linechart url corrected. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fb7d666..b1d65ce 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ Daru::View.plotting_library = :highcharts ``` -![Line Graph](https://github.com/shekharrajak/medium-daru-view-blog/blob/master/GIF_Images/HighChart blog/lineChart.gif) +![Line Graph](https://github.com/shekharrajak/medium-daru-view-blog/blob/master/GIF_Images/HighChartBlog/lineChart.gif) Nyaplot example : From 4a41fb5868f434e5d2e6c77d5b3fb93fe974d28b Mon Sep 17 00:00:00 2001 From: shekharrajak Date: Mon, 7 Jan 2019 21:25:07 +0530 Subject: [PATCH 04/10] removed Unnecessary disabling of Style/ModuleFunction --- lib/daru/view/adapters/googlecharts.rb | 2 +- lib/daru/view/adapters/highcharts.rb | 2 +- lib/daru/view/adapters/nyaplot.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/daru/view/adapters/googlecharts.rb b/lib/daru/view/adapters/googlecharts.rb index 30e4574..a08ca40 100644 --- a/lib/daru/view/adapters/googlecharts.rb +++ b/lib/daru/view/adapters/googlecharts.rb @@ -9,7 +9,7 @@ module Daru module View module Adapter module GooglechartsAdapter - extend self # rubocop:disable Style/ModuleFunction + extend self # Read : https://developers.google.com/chart/ to understand # the google charts option concept. diff --git a/lib/daru/view/adapters/highcharts.rb b/lib/daru/view/adapters/highcharts.rb index 22261aa..a716ae8 100644 --- a/lib/daru/view/adapters/highcharts.rb +++ b/lib/daru/view/adapters/highcharts.rb @@ -8,7 +8,7 @@ module Daru module View module Adapter module HighchartsAdapter - extend self # rubocop:disable Style/ModuleFunction + extend self # Read : https://www.highcharts.com/docs/chart-concepts to understand # the highcharts option concept. diff --git a/lib/daru/view/adapters/nyaplot.rb b/lib/daru/view/adapters/nyaplot.rb index 50422b2..4705faa 100644 --- a/lib/daru/view/adapters/nyaplot.rb +++ b/lib/daru/view/adapters/nyaplot.rb @@ -6,7 +6,7 @@ module Daru module View module Adapter module NyaplotAdapter - extend self # rubocop:disable Style/ModuleFunction + extend self def init(data, options, _user_options={}) data_new = guess_data(data) data_new.plot(options) From 88aeec4de3f39782abc1e04bac3709b57cdee5c4 Mon Sep 17 00:00:00 2001 From: shekharrajak Date: Mon, 7 Jan 2019 21:46:42 +0530 Subject: [PATCH 05/10] travis Ruby version and bundler error: bundler requires Ruby version >= 2.3.0 --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 14de476..6817220 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,11 @@ after_script: - bundle exec rake coveralls:push install: - - gem install bundler + - if [ $TRAVIS_RUBY_VERSION == '2.2' || $TRAVIS_RUBY_VERSION == '2.1' || $TRAVIS_RUBY_VERSION == '2.0']; then + echo $TRAVIS_RUBY_VERSION + gem install bundler -v '~> 1.6' + else + gem install bundler + fi - gem install rainbow -v '2.2.1' - bundle install From 579af63414e17ba2c1518f122f15033f297f2a10 Mon Sep 17 00:00:00 2001 From: shekharrajak Date: Mon, 7 Jan 2019 21:52:36 +0530 Subject: [PATCH 06/10] travis Ruby version and bundler error: bundler requires Ruby version >= 2.3.0 --- .travis.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6817220..45f6c4b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,11 +16,11 @@ after_script: - bundle exec rake coveralls:push install: - - if [ $TRAVIS_RUBY_VERSION == '2.2' || $TRAVIS_RUBY_VERSION == '2.1' || $TRAVIS_RUBY_VERSION == '2.0']; then - echo $TRAVIS_RUBY_VERSION - gem install bundler -v '~> 1.6' - else - gem install bundler - fi + - if [ $TRAVIS_RUBY_VERSION == '2.2'] || [ $TRAVIS_RUBY_VERSION == '2.1'] || [ $TRAVIS_RUBY_VERSION == '2.0']; then + echo $TRAVIS_RUBY_VERSION + gem install bundler -v '~> 1.6' + else + gem install bundler + fi - gem install rainbow -v '2.2.1' - bundle install From 013ede6d9c3eed003a45153182aa8abd431da72b Mon Sep 17 00:00:00 2001 From: shekharrajak Date: Mon, 7 Jan 2019 21:59:08 +0530 Subject: [PATCH 07/10] travis Ruby version and bundler error: bundler requires Ruby version >= 2.3.0 --- .travis.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 45f6c4b..d2fef28 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,11 +16,9 @@ after_script: - bundle exec rake coveralls:push install: - - if [ $TRAVIS_RUBY_VERSION == '2.2'] || [ $TRAVIS_RUBY_VERSION == '2.1'] || [ $TRAVIS_RUBY_VERSION == '2.0']; then - echo $TRAVIS_RUBY_VERSION - gem install bundler -v '~> 1.6' - else - gem install bundler - fi + - if [ $TRAVIS_RUBY_VERSION == '2.2' ] || [ $TRAVIS_RUBY_VERSION == '2.1' ] || [ $TRAVIS_RUBY_VERSION == '2.0' ]; + then gem install bundler -v '~> 1.6'; + else gem install bundler; + fi - gem install rainbow -v '2.2.1' - bundle install From 5a35aa62748da57c41c4869da859c0abf39a15c0 Mon Sep 17 00:00:00 2001 From: shekharrajak Date: Tue, 8 Jan 2019 15:05:23 +0530 Subject: [PATCH 08/10] travis Ruby version and bundler error: bundler requires Ruby version >= 2.3.0 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d2fef28..2f6c23f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ after_script: install: - if [ $TRAVIS_RUBY_VERSION == '2.2' ] || [ $TRAVIS_RUBY_VERSION == '2.1' ] || [ $TRAVIS_RUBY_VERSION == '2.0' ]; - then gem install bundler -v '~> 1.6'; + then gem install bundler -v '1.17.3'; else gem install bundler; fi - gem install rainbow -v '2.2.1' From f0920b653d4edecc6a383f75f2eefb3cbf299a5b Mon Sep 17 00:00:00 2001 From: shekharrajak Date: Tue, 8 Jan 2019 15:28:38 +0530 Subject: [PATCH 09/10] travis Ruby version and bundler error: bundler requires Ruby version >= 2.3.0 --- lib/daru/view/adapters/datatables.rb | 15 +++++++-------- lib/daru/view/adapters/googlecharts.rb | 23 +++++++++++------------ lib/daru/view/adapters/highcharts.rb | 19 +++++++++---------- lib/daru/view/adapters/nyaplot.rb | 15 +++++++-------- 4 files changed, 34 insertions(+), 38 deletions(-) diff --git a/lib/daru/view/adapters/datatables.rb b/lib/daru/view/adapters/datatables.rb index cec4a2c..d7e0c17 100644 --- a/lib/daru/view/adapters/datatables.rb +++ b/lib/daru/view/adapters/datatables.rb @@ -6,7 +6,6 @@ module Daru module View module Adapter module DatatablesAdapter - extend self # rubocop:disable Style/ModuleFunction # Read : https://datatables.net/ to understand # the datatables option concept. @@ -57,13 +56,13 @@ module DatatablesAdapter # table = Daru::View::Table.new(df_sale_exp, options1) # table2 = Daru::View::Table.new(df_sale_exp, options2) # table3 = Daru::View::Table.new(df_sale_exp) - def init_table(data=[], options={}, _user_options={}) + def self.init_table(data=[], options={}, _user_options={}) @table = Daru::View::DataTable.new(data, options) @table end # @return [String] returns code of the dependent JS and CSS file(s) - def init_script + def self.init_script Daru::View::DataTables.init_script end @@ -71,7 +70,7 @@ def init_script # daru-data_table methods # @return [String] script and table (containg thead only) tags of the # datatable generated - def generate_body(table) + def self.generate_body(table) table.to_html end @@ -81,7 +80,7 @@ def generate_body(table) # @example # table = Daru::View::Table.new(data, options) # table.export_html_file - def export_html_file(table, path='./table.html') + def self.export_html_file(table, path='./table.html') path = File.expand_path(path, Dir.pwd) str = generate_html(table) File.write(path, str) @@ -93,14 +92,14 @@ def export_html_file(table, path='./table.html') # @example # table = Daru::View::Table.new(data, options) # table.show_in_iruby - def show_in_iruby(table) + def self.show_in_iruby(table) table.show_in_iruby end # @param table [Daru::DataTables::DataTable] table object to access # daru-data_table methods # @return [String] returns html code of the datatable generated - def generate_html(table) + def self.generate_html(table) path = File.expand_path( '../templates/datatables/static_html.erb', __dir__ ) @@ -115,7 +114,7 @@ def generate_html(table) # @example # table = Daru::View::Table.new(data, options) # table.init_iruby - def init_iruby + def self.init_iruby Daru::View::DataTables.init_iruby end end diff --git a/lib/daru/view/adapters/googlecharts.rb b/lib/daru/view/adapters/googlecharts.rb index a08ca40..c34cada 100644 --- a/lib/daru/view/adapters/googlecharts.rb +++ b/lib/daru/view/adapters/googlecharts.rb @@ -9,7 +9,6 @@ module Daru module View module Adapter module GooglechartsAdapter - extend self # Read : https://developers.google.com/chart/ to understand # the google charts option concept. @@ -72,7 +71,7 @@ module GooglechartsAdapter # Draw the Daru::View::PlotList object with the data as an array of # Daru::View::Plots(s) or Daru::View::Table(s) or both # combined = Daru::View::PlotList([line_chart, bar_chart]) - def init(data=[], options={}, user_options={}) + def self.init(data=[], options={}, user_options={}) @table = GoogleVisualr::DataTable.new @table = get_table(data) unless data.is_a?(String) validate_url(data) if data.is_a?(String) @@ -135,7 +134,7 @@ def init(data=[], options={}, user_options={}) # ['2016', 1030, 540] # ] # table = Daru::View::Table.new(data, {}, chart_class: 'Charteditor') - def init_table(data=[], options={}, user_options={}) + def self.init_table(data=[], options={}, user_options={}) # if `options` is something like this : # { # cols: [{id: 'task', label: 'Employee Name', type: 'string'}, @@ -165,7 +164,7 @@ def init_table(data=[], options={}, user_options={}) # has to invoked # @return [Boolean, void] returns true for valid URL and raises error # for invalid URL - def validate_url(data) + def self.validate_url(data) # `PATTERN_URL.match? data` is faster but does not support older ruby # versions # For testing purpose, it is returning true @@ -174,21 +173,21 @@ def validate_url(data) raise 'Invalid URL' end - def init_script + def self.init_script GoogleVisualr.init_script end - def generate_body(plot) + def self.generate_body(plot) plot.to_html end - def export_html_file(plot, path='./plot.html') + def self.export_html_file(plot, path='./plot.html') path = File.expand_path(path, Dir.pwd) str = generate_html(plot) File.write(path, str) end - def show_in_iruby(plot) + def self.show_in_iruby(plot) plot.show_in_iruby end @@ -198,7 +197,7 @@ def show_in_iruby(plot) # IRuby notebook. # # @see #Daru::View::Plot.export - def export(plot, export_type='png', file_name='chart') + def self.export(plot, export_type='png', file_name='chart') raise NotImplementedError, 'Not yet implemented!' unless export_type == 'png' @@ -207,7 +206,7 @@ def export(plot, export_type='png', file_name='chart') plot.export(export_type, file_name) end - def generate_html(plot) + def self.generate_html(plot) path = File.expand_path( '../templates/googlecharts/static_html.erb', __dir__ ) @@ -218,13 +217,13 @@ def generate_html(plot) ERB.new(template).result(binding) end - def init_iruby + def self.init_iruby GoogleVisualr.init_iruby end # Generally, in opts Hash, :name, :type, :data , :center=> [X, Y], # :size=> Integer, :showInLegend=> Bool, etc may present. - def add_series(plot, opts={}) + def self.add_series(plot, opts={}) plot.series(opts) plot end diff --git a/lib/daru/view/adapters/highcharts.rb b/lib/daru/view/adapters/highcharts.rb index a716ae8..20033ea 100644 --- a/lib/daru/view/adapters/highcharts.rb +++ b/lib/daru/view/adapters/highcharts.rb @@ -8,7 +8,6 @@ module Daru module View module Adapter module HighchartsAdapter - extend self # Read : https://www.highcharts.com/docs/chart-concepts to understand # the highcharts option concept. @@ -28,7 +27,7 @@ module HighchartsAdapter # # @param [Array/Daru::DataFrame/Daru::Vector] data # - def init(data=[], options={}, user_options={}) + def self.init(data=[], options={}, user_options={}) # Alternate way is using `add_series` method. # # There are many options present in Highcharts so it is better to use @@ -57,15 +56,15 @@ def init(data=[], options={}, user_options={}) @chart end - def init_script + def self.init_script LazyHighCharts.init_script end - def generate_body(plot) + def self.generate_body(plot) plot.to_html end - def export_html_file(plot, path='./plot.html') + def self.export_html_file(plot, path='./plot.html') path = File.expand_path(path, Dir.pwd) str = generate_html(plot) File.write(path, str) @@ -80,17 +79,17 @@ def export_html_file(plot, path='./plot.html') # running the cells works fine. # # @see #Daru::View::Plot.export - def export(plot, export_type='png', file_name='chart') + def self.export(plot, export_type='png', file_name='chart') plot.export_iruby(export_type, file_name) if defined? IRuby rescue NameError plot.export(export_type, file_name) end - def show_in_iruby(plot) + def self.show_in_iruby(plot) plot.show_in_iruby end - def generate_html(plot) + def self.generate_html(plot) path = File.expand_path('../templates/highcharts/static_html.erb', __dir__) template = File.read(path) initial_script = init_script @@ -98,13 +97,13 @@ def generate_html(plot) ERB.new(template).result(binding) end - def init_iruby + def self.init_iruby LazyHighCharts.init_iruby end # Generally, in opts Hash, :name, :type, :data , :center=> [X, Y], # :size=> Integer, :showInLegend=> Bool, etc may present. - def add_series(plot, opts={}) + def self.add_series(plot, opts={}) plot.series(opts) plot end diff --git a/lib/daru/view/adapters/nyaplot.rb b/lib/daru/view/adapters/nyaplot.rb index 4705faa..9e58544 100644 --- a/lib/daru/view/adapters/nyaplot.rb +++ b/lib/daru/view/adapters/nyaplot.rb @@ -6,33 +6,32 @@ module Daru module View module Adapter module NyaplotAdapter - extend self - def init(data, options, _user_options={}) + def self.init(data, options, _user_options={}) data_new = guess_data(data) data_new.plot(options) end - def export_html_file(plot, path) + def self.export_html_file(plot, path) plot.export_html path end - def export(_plot, _export_type='png', _file_name='chart') + def self.export(_plot, _export_type='png', _file_name='chart') raise 'Not implemented yet' end - def show_in_iruby(plot) + def self.show_in_iruby(plot) plot.show end - def init_script + def self.init_script Nyaplot.init_script end - def generate_body(plot) + def self.generate_body(plot) plot.to_iruby[1] end - def init_iruby + def self.init_iruby Nyaplot.init_iruby end From c0933093cac59554b8919e974234f126e93cadf0 Mon Sep 17 00:00:00 2001 From: shekharrajak Date: Tue, 8 Jan 2019 15:35:09 +0530 Subject: [PATCH 10/10] extra line removed at the beginning of module --- lib/daru/view/adapters/datatables.rb | 1 - lib/daru/view/adapters/googlecharts.rb | 1 - lib/daru/view/adapters/highcharts.rb | 1 - 3 files changed, 3 deletions(-) diff --git a/lib/daru/view/adapters/datatables.rb b/lib/daru/view/adapters/datatables.rb index d7e0c17..e8dc265 100644 --- a/lib/daru/view/adapters/datatables.rb +++ b/lib/daru/view/adapters/datatables.rb @@ -6,7 +6,6 @@ module Daru module View module Adapter module DatatablesAdapter - # Read : https://datatables.net/ to understand # the datatables option concept. # Along with these options, a user can provide an additional option diff --git a/lib/daru/view/adapters/googlecharts.rb b/lib/daru/view/adapters/googlecharts.rb index c34cada..1791f69 100644 --- a/lib/daru/view/adapters/googlecharts.rb +++ b/lib/daru/view/adapters/googlecharts.rb @@ -9,7 +9,6 @@ module Daru module View module Adapter module GooglechartsAdapter - # Read : https://developers.google.com/chart/ to understand # the google charts option concept. # and google_visualr : http://googlevisualr.herokuapp.com/ diff --git a/lib/daru/view/adapters/highcharts.rb b/lib/daru/view/adapters/highcharts.rb index 20033ea..07dcc67 100644 --- a/lib/daru/view/adapters/highcharts.rb +++ b/lib/daru/view/adapters/highcharts.rb @@ -8,7 +8,6 @@ module Daru module View module Adapter module HighchartsAdapter - # Read : https://www.highcharts.com/docs/chart-concepts to understand # the highcharts option concept. #