daru-view 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +4 -0
- data/.rubocop.yml +122 -0
- data/.simplecov +3 -0
- data/.travis.yml +18 -0
- data/CHANGELOG.md +21 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/CONTRIBUTING.md +53 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +21 -0
- data/README.md +287 -0
- data/Rakefile +22 -0
- data/_config.yml +1 -0
- data/daru-view.gemspec +52 -0
- data/lib/assets/.keep +0 -0
- data/lib/daru/view.rb +127 -0
- data/lib/daru/view/adapters/datatables.rb +90 -0
- data/lib/daru/view/adapters/googlecharts.rb +180 -0
- data/lib/daru/view/adapters/googlecharts/data_table_iruby.rb +86 -0
- data/lib/daru/view/adapters/googlecharts/display.rb +54 -0
- data/lib/daru/view/adapters/googlecharts/iruby_notebook.rb +15 -0
- data/lib/daru/view/adapters/highcharts.rb +114 -0
- data/lib/daru/view/adapters/highcharts/core_ext/string.rb +10 -0
- data/lib/daru/view/adapters/highcharts/display.rb +58 -0
- data/lib/daru/view/adapters/highcharts/iruby_notebook.rb +29 -0
- data/lib/daru/view/adapters/highcharts/layout_helper_iruby.rb +76 -0
- data/lib/daru/view/adapters/js/googlecharts_js/google_visualr.js +44 -0
- data/lib/daru/view/adapters/js/googlecharts_js/loader.js +226 -0
- data/lib/daru/view/adapters/js/highcharts_js/adapters/mootools-adapter.js +13 -0
- data/lib/daru/view/adapters/js/highcharts_js/adapters/prototype-adapter.js +15 -0
- data/lib/daru/view/adapters/js/highcharts_js/highcharts-3d.js +74 -0
- data/lib/daru/view/adapters/js/highcharts_js/highcharts-more.js +64 -0
- data/lib/daru/view/adapters/js/highcharts_js/highcharts.js +399 -0
- data/lib/daru/view/adapters/js/highcharts_js/highstock.js +519 -0
- data/lib/daru/view/adapters/js/highcharts_js/modules/accessibility.js +48 -0
- data/lib/daru/view/adapters/js/highcharts_js/modules/annotations.js +14 -0
- data/lib/daru/view/adapters/js/highcharts_js/modules/boost.js +51 -0
- data/lib/daru/view/adapters/js/highcharts_js/modules/broken-axis.js +15 -0
- data/lib/daru/view/adapters/js/highcharts_js/modules/canvas-tools.js +133 -0
- data/lib/daru/view/adapters/js/highcharts_js/modules/data.js +26 -0
- data/lib/daru/view/adapters/js/highcharts_js/modules/drilldown.js +25 -0
- data/lib/daru/view/adapters/js/highcharts_js/modules/exporting.js +27 -0
- data/lib/daru/view/adapters/js/highcharts_js/modules/funnel.js +13 -0
- data/lib/daru/view/adapters/js/highcharts_js/modules/heatmap.js +25 -0
- data/lib/daru/view/adapters/js/highcharts_js/modules/no-data-to-display.js +12 -0
- data/lib/daru/view/adapters/js/highcharts_js/modules/offline-exporting.js +19 -0
- data/lib/daru/view/adapters/js/highcharts_js/modules/solid-gauge.js +14 -0
- data/lib/daru/view/adapters/js/highcharts_js/modules/treemap.js +31 -0
- data/lib/daru/view/adapters/js/highcharts_js/stock/adapters/mootools-adapter.js +13 -0
- data/lib/daru/view/adapters/js/highcharts_js/stock/adapters/prototype-adapter.js +15 -0
- data/lib/daru/view/adapters/js/highcharts_js/stock/highcharts-more.js +64 -0
- data/lib/daru/view/adapters/js/highcharts_js/stock/modules/exporting.js +27 -0
- data/lib/daru/view/adapters/js/highcharts_js/stock/modules/funnel.js +13 -0
- data/lib/daru/view/adapters/js/nyaplot_js/d3-downloadable.js +129 -0
- data/lib/daru/view/adapters/js/nyaplot_js/d3.min.js +5 -0
- data/lib/daru/view/adapters/js/nyaplot_js/nyaplot.js +5294 -0
- data/lib/daru/view/adapters/nyaplot.rb +62 -0
- data/lib/daru/view/adapters/nyaplot/display.rb +9 -0
- data/lib/daru/view/adapters/nyaplot/iruby_notebook.rb +22 -0
- data/lib/daru/view/app/rails/helpers/view_helper.rb +26 -0
- data/lib/daru/view/app/rails/railtie.rb +15 -0
- data/lib/daru/view/plot.rb +106 -0
- data/lib/daru/view/table.rb +99 -0
- data/lib/daru/view/templates/googlecharts/chart_div.erb +4 -0
- data/lib/daru/view/templates/googlecharts/init.inline.js.erb +16 -0
- data/lib/daru/view/templates/highcharts/init.inline.js.erb +16 -0
- data/lib/daru/view/templates/highcharts/static_html.erb +7 -0
- data/lib/daru/view/templates/nyaplot/init.inline.js.erb +16 -0
- data/lib/daru/view/templates/nyaplot/init_script.erb +3 -0
- data/lib/daru/view/version.rb +5 -0
- data/lib/tasks/.keep +0 -0
- data/lib/tasks/google_charts.rake +25 -0
- data/lib/tasks/high_charts.rake +60 -0
- data/lib/tasks/nyaplot.rake +25 -0
- data/spec/adapters/datatables_spec.rb +21 -0
- data/spec/adapters/googlecharts_spec.rb +34 -0
- data/spec/adapters/highcharts_spec.rb +177 -0
- data/spec/adapters/nyaplot_spec.rb +447 -0
- data/spec/app/rails/helpers/view_helpers_spec.rb +35 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Daru DataFrame and DataTables-checkpoint.ipynb +16091 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/DataTables | basic examples-checkpoint.ipynb +6 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Line Chart-checkpoint.ipynb +1389 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Area Chart-checkpoint.ipynb +606 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Bar Chart-checkpoint.ipynb +1404 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Bubble Chart-checkpoint.ipynb +866 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Candlestick Chart-checkpoint.ipynb +607 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Combo Chart-checkpoint.ipynb +478 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Histogram-checkpoint.ipynb +1182 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Org Chart-checkpoint.ipynb +6 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Pie Chart-checkpoint.ipynb +6 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Stepped Area Chart-checkpoint.ipynb +699 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Timeline-checkpoint.ipynb +1523 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | Treemap-checkpoint.ipynb +650 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Google Chart | gauge-checkpoint.ipynb +477 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Google Charts | Basics-checkpoint.ipynb +1881 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Google Charts | Column Charts-checkpoint.ipynb +6 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Google Charts | Geo Charts examples-checkpoint.ipynb +791 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Google Charts | Scatter Chart-checkpoint.ipynb +1570 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/GoolgeChart | Datatables-checkpoint.ipynb +1792 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/HighCharts - Area chart-checkpoint.ipynb +1272 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/HighCharts - Bar Chart-checkpoint.ipynb +877 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/HighCharts - column charts-checkpoint.ipynb +1587 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/HighCharts- Pie charts-checkpoint.ipynb +1126 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Highcharts - Combinations -checkpoint.ipynb +925 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Highcharts - Daynamic charts-checkpoint.ipynb +839 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Highcharts - line graphs-checkpoint.ipynb +1297 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Highcharts - line graphs2-checkpoint.ipynb +879 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Highcharts - scatter -bubble charts-checkpoint.ipynb +1071 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Highcharts | add_series method and highcharts examples-checkpoint.ipynb +1165 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Nyaplot basics | Daru Examples-checkpoint.ipynb +1383 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Nyaplot other examples-checkpoint.ipynb +6 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Nyaplot testing -checkpoint.ipynb +270 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Nyaplot | Creating Visualizations with DataFrame | from daru examples-checkpoint.ipynb +1716 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/Pie Chart using HighCharts2-checkpoint.ipynb +784 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/highcharts - Use HTML table (generated from daru) as data source-checkpoint.ipynb +956 -0
- data/spec/dummy_iruby/.ipynb_checkpoints/spec_testing-checkpoint.ipynb +1433 -0
- data/spec/dummy_iruby/Daru DataFrame and DataTables.ipynb +16091 -0
- data/spec/dummy_iruby/DataTables | basic examples.ipynb +15587 -0
- data/spec/dummy_iruby/Gemfile +33 -0
- data/spec/dummy_iruby/Google Chart | Line Chart.ipynb +1389 -0
- data/spec/dummy_iruby/Google Chart | Area Chart.ipynb +606 -0
- data/spec/dummy_iruby/Google Chart | Bar Chart.ipynb +1394 -0
- data/spec/dummy_iruby/Google Chart | Bubble Chart.ipynb +866 -0
- data/spec/dummy_iruby/Google Chart | Candlestick Chart.ipynb +607 -0
- data/spec/dummy_iruby/Google Chart | Combo Chart.ipynb +478 -0
- data/spec/dummy_iruby/Google Chart | Histogram.ipynb +1182 -0
- data/spec/dummy_iruby/Google Chart | Org Chart.ipynb +474 -0
- data/spec/dummy_iruby/Google Chart | Pie Chart.ipynb +1177 -0
- data/spec/dummy_iruby/Google Chart | Stepped Area Chart.ipynb +699 -0
- data/spec/dummy_iruby/Google Chart | Timeline.ipynb +1523 -0
- data/spec/dummy_iruby/Google Chart | Treemap.ipynb +659 -0
- data/spec/dummy_iruby/Google Chart | gauge.ipynb +477 -0
- data/spec/dummy_iruby/Google Charts | Basics.ipynb +1882 -0
- data/spec/dummy_iruby/Google Charts | Column Charts.ipynb +1138 -0
- data/spec/dummy_iruby/Google Charts | Geo Charts examples.ipynb +791 -0
- data/spec/dummy_iruby/Google Charts | Scatter Chart.ipynb +1570 -0
- data/spec/dummy_iruby/GoolgeChart | Datatables.ipynb +1801 -0
- data/spec/dummy_iruby/HighCharts - Area chart.ipynb +1272 -0
- data/spec/dummy_iruby/HighCharts - Bar Chart.ipynb +877 -0
- data/spec/dummy_iruby/HighCharts - column charts.ipynb +1587 -0
- data/spec/dummy_iruby/HighCharts- Pie charts.ipynb +1197 -0
- data/spec/dummy_iruby/Highcharts - Combinations .ipynb +925 -0
- data/spec/dummy_iruby/Highcharts - Daynamic charts.ipynb +839 -0
- data/spec/dummy_iruby/Highcharts - line graphs.ipynb +1297 -0
- data/spec/dummy_iruby/Highcharts - line graphs2.ipynb +879 -0
- data/spec/dummy_iruby/Highcharts - scatter -bubble charts.ipynb +1071 -0
- data/spec/dummy_iruby/Highcharts | add_series method and highcharts examples.ipynb +1228 -0
- data/spec/dummy_iruby/Nyaplot basics | Daru Examples.ipynb +1390 -0
- data/spec/dummy_iruby/Nyaplot other examples.ipynb +589 -0
- data/spec/dummy_iruby/Nyaplot testing .ipynb +270 -0
- data/spec/dummy_iruby/Nyaplot | Creating Visualizations with DataFrame | from daru examples.ipynb +1716 -0
- data/spec/dummy_iruby/Pie Chart using HighCharts2.ipynb +784 -0
- data/spec/dummy_iruby/highcharts - Use HTML table (generated from daru) as data source.ipynb +951 -0
- data/spec/dummy_iruby/spec_testing.ipynb +1433 -0
- data/spec/dummy_nanoc/Gemfile +12 -0
- data/spec/dummy_nanoc/README.md +40 -0
- data/spec/dummy_nanoc/Rules +90 -0
- data/spec/dummy_nanoc/content/googlecharts/index.html +29 -0
- data/spec/dummy_nanoc/content/highcharts/index.html +42 -0
- data/spec/dummy_nanoc/content/index.html +26 -0
- data/spec/dummy_nanoc/content/nyaplot/index.html +9 -0
- data/spec/dummy_nanoc/content/stylesheet.css +101 -0
- data/spec/dummy_nanoc/layouts/default.html +31 -0
- data/spec/dummy_nanoc/layouts/googlecharts_layout.html +30 -0
- data/spec/dummy_nanoc/layouts/highcharts_layout.html +30 -0
- data/spec/dummy_nanoc/layouts/nyaplot_layout.html +30 -0
- data/spec/dummy_nanoc/lib/default.rb +300 -0
- data/spec/dummy_nanoc/nanoc.yaml +90 -0
- data/spec/dummy_nanoc/output/googlecharts/index.html +390 -0
- data/spec/dummy_nanoc/output/highcharts/index.html +1153 -0
- data/spec/dummy_nanoc/output/index.html +87 -0
- data/spec/dummy_nanoc/output/nyaplot/index.html +135 -0
- data/spec/dummy_nanoc/output/stylesheet.css +101 -0
- data/spec/dummy_nanoc/tmp/nanoc/1029d67644815/checksums +0 -0
- data/spec/dummy_nanoc/tmp/nanoc/1029d67644815/compiled_content +2229 -0
- data/spec/dummy_nanoc/tmp/nanoc/1029d67644815/dependencies +5 -0
- data/spec/dummy_nanoc/tmp/nanoc/1029d67644815/outdatedness +0 -0
- data/spec/dummy_nanoc/tmp/nanoc/1029d67644815/rule_memory +0 -0
- data/spec/dummy_sinatra/Gemfile +9 -0
- data/spec/dummy_sinatra/README.md +15 -0
- data/spec/dummy_sinatra/app.rb +143 -0
- data/spec/dummy_sinatra/config.ru +0 -0
- data/spec/dummy_sinatra/views/googlecharts.erb +31 -0
- data/spec/dummy_sinatra/views/googlecharts_layout.erb +12 -0
- data/spec/dummy_sinatra/views/highcharts.erb +15 -0
- data/spec/dummy_sinatra/views/highcharts_layout.erb +12 -0
- data/spec/dummy_sinatra/views/index.erb +2 -0
- data/spec/dummy_sinatra/views/layout.erb +26 -0
- data/spec/dummy_sinatra/views/nyaplot.erb +13 -0
- data/spec/dummy_sinatra/views/nyaplot_layout.erb +14 -0
- data/spec/plot_spec.rb +86 -0
- data/spec/spec_helper.rb +11 -0
- metadata +568 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
|
2
|
+
require_relative 'nyaplot/iruby_notebook'
|
3
|
+
require 'daru'
|
4
|
+
require 'nyaplot'
|
5
|
+
|
6
|
+
module Daru
|
7
|
+
module View
|
8
|
+
module Adapter
|
9
|
+
module NyaplotAdapter
|
10
|
+
extend self # rubocop:disable Style/ModuleFunction
|
11
|
+
def init(data, options)
|
12
|
+
data_new = guess_data(data)
|
13
|
+
data_new.plot(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def export_html_file(plot, path)
|
17
|
+
plot.export_html path
|
18
|
+
end
|
19
|
+
|
20
|
+
def show_in_iruby(plot)
|
21
|
+
plot.show
|
22
|
+
end
|
23
|
+
|
24
|
+
def init_script
|
25
|
+
Nyaplot.init_script
|
26
|
+
end
|
27
|
+
|
28
|
+
def generate_body(plot)
|
29
|
+
plot.to_iruby[1]
|
30
|
+
end
|
31
|
+
|
32
|
+
def init_iruby
|
33
|
+
Nyaplot.init_iruby
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def multi_dimension_check(arr)
|
39
|
+
arr.all? { |a| a.class==Array }
|
40
|
+
end
|
41
|
+
|
42
|
+
def guess_data(data_set)
|
43
|
+
case
|
44
|
+
when [Daru::DataFrame, Daru::Vector].include?(data_set.class)
|
45
|
+
data_set
|
46
|
+
when data_set.is_a?(Array)
|
47
|
+
if data_set.empty?
|
48
|
+
Daru::Vector.new([])
|
49
|
+
else
|
50
|
+
multi_dimension_check(data_set)? Daru::DataFrame.new(data_set) : Daru::Vector.new(data_set)
|
51
|
+
end
|
52
|
+
else
|
53
|
+
raise ArgumentError, "For Nyaplot Library, data must be in
|
54
|
+
Daru::Vector or Daru::DataFrame.\n You can change the plotting
|
55
|
+
library using the code : \n
|
56
|
+
` Daru::View.plotting_library = :highcharts` or other library."
|
57
|
+
end
|
58
|
+
end # def guess_data end
|
59
|
+
end
|
60
|
+
end # Adapter end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module Nyaplot
|
2
|
+
# dependent JS to include in head tag of the web application
|
3
|
+
def self.init_script
|
4
|
+
init = Nyaplot.generate_init_code
|
5
|
+
path = File.expand_path('../../../templates/nyaplot/init_script.erb', __FILE__)
|
6
|
+
template = File.read(path)
|
7
|
+
ERB.new(template).result(binding)
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Nyaplot
|
2
|
+
# generate initializing code
|
3
|
+
def self.generate_init_code_offline(dependent_js)
|
4
|
+
js_dir = File.expand_path('../../js/nyaplot_js', __FILE__)
|
5
|
+
path = File.expand_path('../../../templates/nyaplot/init.inline.js.erb', __FILE__)
|
6
|
+
template = File.read(path)
|
7
|
+
ERB.new(template).result(binding)
|
8
|
+
end
|
9
|
+
|
10
|
+
# generate initializing code
|
11
|
+
def self.generate_init_code_online
|
12
|
+
# TODO : better than present Nyaplot.generate_init_code
|
13
|
+
end
|
14
|
+
|
15
|
+
# Enable to show plots on IRuby notebook
|
16
|
+
def self.init_iruby(*)
|
17
|
+
#
|
18
|
+
# dependent_js=['d3.min.js', 'd3-downloadable.js', 'nyaplot.js']
|
19
|
+
js = generate_init_code
|
20
|
+
IRuby.display(IRuby.javascript(js))
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'daru/view/plot'
|
2
|
+
require 'daru/view/table'
|
3
|
+
|
4
|
+
module Daru
|
5
|
+
module View
|
6
|
+
module Rails
|
7
|
+
module ViewHelper
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
if respond_to?(:helper_method)
|
12
|
+
helper_method 'daru_chart', 'daru_table'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def daru_chart(data=[], options={})
|
17
|
+
Daru::View::Plot.new(data, options).div.html_safe
|
18
|
+
end
|
19
|
+
|
20
|
+
def daru_table(data=[], options={})
|
21
|
+
Daru::View::Table.new(data, options).div.html_safe
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative 'helpers/view_helper'
|
2
|
+
|
3
|
+
module Daru
|
4
|
+
module View
|
5
|
+
module Rails
|
6
|
+
class Railtie < ::Rails::Railtie
|
7
|
+
initializer 'daru/view' do
|
8
|
+
ActiveSupport.on_load(:action_controller) do
|
9
|
+
include Daru::View::Rails::ViewHelper
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
|
2
|
+
module Daru
|
3
|
+
module View
|
4
|
+
class Plot
|
5
|
+
attr_reader :chart, :data, :options
|
6
|
+
attr_accessor :adapter
|
7
|
+
class << self
|
8
|
+
# class method
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
#
|
12
|
+
# Daru::View::Plot.adapter = :googlecharts
|
13
|
+
#
|
14
|
+
# Plotting libraries are nyaplot, highcharts, googlecharts
|
15
|
+
def adapter=(adapter)
|
16
|
+
require "daru/view/adapters/#{adapter}"
|
17
|
+
# rubocop:disable Style/ClassVars
|
18
|
+
@@adapter = Daru::View::Adapter.const_get(
|
19
|
+
adapter.to_s.capitalize + 'Adapter'
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# df = Daru::DataFrame.new({a:['A', 'B', 'C', 'D', 'E'], b:[10,20,30,40,50]})
|
27
|
+
# Daru::View::Plot.new df, type: :bar, x: :a, y: :b, adapter: :nyaplot
|
28
|
+
#
|
29
|
+
# Set the new adapter(plotting library) ,for example highcharts:
|
30
|
+
#
|
31
|
+
# Daru::View.plotting_library = :highcharts
|
32
|
+
#
|
33
|
+
# To use a particular apdater in certain plot object(s), then user
|
34
|
+
# must pass the adapter in `options` hash. e.g. `adapter: :highcharts`
|
35
|
+
#
|
36
|
+
def initialize(data=[], options={}, &block)
|
37
|
+
# TODO: &block is not used, right now.
|
38
|
+
@data = data
|
39
|
+
@options = options
|
40
|
+
self.adapter = options.delete(:adapter) unless options[:adapter].nil?
|
41
|
+
@chart = plot_data(data, options, &block)
|
42
|
+
end
|
43
|
+
|
44
|
+
# instance method
|
45
|
+
def adapter=(adapter)
|
46
|
+
require "daru/view/adapters/#{adapter}"
|
47
|
+
@adapter = Daru::View::Adapter.const_get(
|
48
|
+
adapter.to_s.capitalize + 'Adapter'
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
# display in IRuby notebook
|
53
|
+
def show_in_iruby
|
54
|
+
@adapter.show_in_iruby @chart
|
55
|
+
end
|
56
|
+
|
57
|
+
# dependent js file, to include in head tag using the plot object.
|
58
|
+
# @example:
|
59
|
+
# plot_obj.init_script
|
60
|
+
#
|
61
|
+
# Note :
|
62
|
+
# User can directly put the dependent script file into the head tag
|
63
|
+
# using `Daru::View.dependent_script(:highcharts), by default it loads
|
64
|
+
# Nyaplot JS files.
|
65
|
+
#
|
66
|
+
def init_script
|
67
|
+
@adapter.init_script
|
68
|
+
end
|
69
|
+
|
70
|
+
# generat html code, to include in body tag
|
71
|
+
def div
|
72
|
+
@adapter.generate_body(@chart)
|
73
|
+
end
|
74
|
+
|
75
|
+
# generat html file
|
76
|
+
def export_html_file(path='./plot.html')
|
77
|
+
@adapter.export_html_file(@chart, path)
|
78
|
+
end
|
79
|
+
|
80
|
+
# load the corresponding JS files in IRuby notebook.
|
81
|
+
# This is done automatically when plotting library is set using
|
82
|
+
# Daru::View.plotting_library = :new_library
|
83
|
+
def init_iruby
|
84
|
+
@adapter.init_iruby
|
85
|
+
end
|
86
|
+
|
87
|
+
def add_series(opts={})
|
88
|
+
case adapter
|
89
|
+
when Daru::View::Adapter::HighchartsAdapter
|
90
|
+
@chart = @adapter.add_series(@chart, opts)
|
91
|
+
else
|
92
|
+
raise("Method `add-series` is not valid for #{@adapter}.to_s.capitalize library.")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def plot_data(data, options)
|
99
|
+
# class variable @@aapter is used in instance variable @adapter.
|
100
|
+
# so in each object `adapter` variable can be accessed.
|
101
|
+
@adapter ||= @@adapter
|
102
|
+
@adapter.init(data, options)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
|
2
|
+
module Daru
|
3
|
+
module View
|
4
|
+
class Table
|
5
|
+
attr_reader :table, :data, :options
|
6
|
+
attr_accessor :adapter
|
7
|
+
class << self
|
8
|
+
# class method
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
#
|
12
|
+
# Daru::View::Table.adapter = :new_library
|
13
|
+
def adapter=(adapter)
|
14
|
+
# The library wrapper method for generating table is in the
|
15
|
+
# same folder as the plotting library. Since google chart can be
|
16
|
+
# used for plotting charts as well as table.
|
17
|
+
#
|
18
|
+
require "daru/view/adapters/#{adapter}"
|
19
|
+
# rubocop:disable Style/ClassVars
|
20
|
+
@@adapter = Daru::View::Adapter.const_get(
|
21
|
+
adapter.to_s.capitalize + 'Adapter'
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# TODO: modify the examples
|
27
|
+
# @example
|
28
|
+
#
|
29
|
+
# df = Daru::DataFrame.new({a:['A', 'B', 'C', 'D', 'E'], b:[10,20,30,40,50]})
|
30
|
+
# Daru::View::Plot.new df, type: :bar, x: :a, y: :b
|
31
|
+
#
|
32
|
+
# Set the new adapter(plotting library) ,for example highcharts:
|
33
|
+
#
|
34
|
+
# Daru::View.plotting_library = :highcharts
|
35
|
+
#
|
36
|
+
# To use a particular apdater in certain plot object(s), then user
|
37
|
+
# must pass the adapter in `options` hash. e.g. `adapter: :highcharts`
|
38
|
+
#
|
39
|
+
def initialize(data=[], options={})
|
40
|
+
@data = data
|
41
|
+
@options = options
|
42
|
+
self.adapter = options.delete(:adapter) unless options[:adapter].nil?
|
43
|
+
@table = table_data(data, options)
|
44
|
+
end
|
45
|
+
|
46
|
+
# instance method
|
47
|
+
def adapter=(adapter)
|
48
|
+
require "daru/view/adapters/#{adapter}"
|
49
|
+
@adapter = Daru::View::Adapter.const_get(
|
50
|
+
adapter.to_s.capitalize + 'Adapter'
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
# display in IRuby notebook
|
55
|
+
def show_in_iruby
|
56
|
+
@adapter.show_in_iruby @table
|
57
|
+
end
|
58
|
+
|
59
|
+
# dependent js file, to include in head tag using the plot object.
|
60
|
+
# @example:
|
61
|
+
# plot_obj.init_script
|
62
|
+
#
|
63
|
+
# Note :
|
64
|
+
# User can directly put the dependent script file into the head tag
|
65
|
+
# using `Daru::View.dependent_script(:highcharts), by default it loads
|
66
|
+
# Nyaplot JS files.
|
67
|
+
#
|
68
|
+
def init_script
|
69
|
+
@adapter.init_script
|
70
|
+
end
|
71
|
+
|
72
|
+
# generate html code, to include in body tag
|
73
|
+
def div
|
74
|
+
@adapter.generate_body(@table)
|
75
|
+
end
|
76
|
+
|
77
|
+
# generat html file
|
78
|
+
def export_html_file(path='./plot.html')
|
79
|
+
@adapter.export_html_file(@table, path)
|
80
|
+
end
|
81
|
+
|
82
|
+
# load the corresponding JS files in IRuby notebook.
|
83
|
+
# This is done automatically when plotting library is set using
|
84
|
+
# Daru::View.plotting_library = :new_library
|
85
|
+
def init_iruby
|
86
|
+
@adapter.init_iruby
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def table_data(data, options)
|
92
|
+
# class variable @@aapter is used in instance variable @adapter.
|
93
|
+
# so in each object `adapter` variable can be accessed.
|
94
|
+
@adapter ||= @@adapter
|
95
|
+
@adapter.init_table(data, options)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<%
|
2
|
+
|
3
|
+
dependent_js.each{ |dep_js|
|
4
|
+
contents = IO.read(File.join(js_dir,dep_js), mode: 'r:UTF-8')
|
5
|
+
%>
|
6
|
+
/* BEGIN <%= dep_js %> */
|
7
|
+
|
8
|
+
<%= contents %>
|
9
|
+
/* END <%= dep_js %>*/
|
10
|
+
<% } %>
|
11
|
+
|
12
|
+
var event = document.createEvent("HTMLEvents");
|
13
|
+
event.initEvent("load_google_charts", false, false);
|
14
|
+
window.dispatchEvent(event);
|
15
|
+
console.log("Finish loading google charts js files");
|
16
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<%
|
2
|
+
|
3
|
+
dependent_js.each{ |dep_js|
|
4
|
+
contents = IO.read(File.join(js_dir,dep_js), mode: 'r:UTF-8')
|
5
|
+
%>
|
6
|
+
/* BEGIN <%= dep_js %> */
|
7
|
+
|
8
|
+
<%= contents %>
|
9
|
+
/* END <%= dep_js %>*/
|
10
|
+
<% } %>
|
11
|
+
|
12
|
+
var event = document.createEvent("HTMLEvents");
|
13
|
+
event.initEvent("load_highcharts", false, false);
|
14
|
+
window.dispatchEvent(event);
|
15
|
+
console.log("Finish loading highchartsjs");
|
16
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<%
|
2
|
+
|
3
|
+
dependent_js.each{ |dep_js|
|
4
|
+
contents = IO.read(File.join(js_dir,dep_js), mode: 'r:UTF-8')
|
5
|
+
%>
|
6
|
+
/* BEGIN <%= dep_js %> */
|
7
|
+
|
8
|
+
<%= contents %>
|
9
|
+
/* END <%= dep_js %>*/
|
10
|
+
<% } %>
|
11
|
+
|
12
|
+
var event = document.createEvent("HTMLEvents");
|
13
|
+
event.initEvent("load_nyaplot", false, false);
|
14
|
+
window.dispatchEvent(event);
|
15
|
+
console.log("Finish loading nyaplot.js");
|
16
|
+
|
data/lib/tasks/.keep
ADDED
File without changes
|
@@ -0,0 +1,25 @@
|
|
1
|
+
def say(msg, &block)
|
2
|
+
print "#{msg}..."
|
3
|
+
|
4
|
+
if block_given?
|
5
|
+
yield
|
6
|
+
puts " Done."
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :googlecharts do
|
11
|
+
desc "Update google charts javascript dependent files, from latest Builds on google developers website"
|
12
|
+
task :update => [:jsapi, :loader]
|
13
|
+
task :jsapi do
|
14
|
+
say "Grabbing Core from google jsapi codebase..." do
|
15
|
+
sh "curl -# https://www.google.com/jsapi -L --compressed -o lib/daru/view/adapters/js/googlecharts_js/google_visualr.js"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
task :loader do
|
20
|
+
say "Grabbing loader.js from the google website..." do
|
21
|
+
sh "curl -# https://www.gstatic.com/charts/loader.js -L --compressed -o lib/daru/view/adapters/js/googlecharts_js/loader.js"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|