daru-view 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,60 @@
|
|
1
|
+
# using code from lazy _high_charts gem with some modification
|
2
|
+
|
3
|
+
def say(msg, &block)
|
4
|
+
print "#{msg}..."
|
5
|
+
|
6
|
+
if block_given?
|
7
|
+
yield
|
8
|
+
puts " Done."
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
namespace :highcharts do
|
13
|
+
desc "Update highcharts.js from latest Builds on Highcharts codebase: http://code.highcharts.com/"
|
14
|
+
task :update => [:core, :stock]
|
15
|
+
task :core do
|
16
|
+
say "Grabbing Core from Highcharts codebase..." do
|
17
|
+
sh "mkdir -p lib/daru/view/adapters/js/highcharts_js/modules/"
|
18
|
+
sh "mkdir -p lib/daru/view/adapters/js/highcharts_js/adapters/"
|
19
|
+
|
20
|
+
sh "curl -# http://code.highcharts.com/highcharts.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/highcharts.js"
|
21
|
+
sh "curl -# http://code.highcharts.com/highcharts-more.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/highcharts-more.js"
|
22
|
+
sh "curl -# http://code.highcharts.com/highcharts-3d.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/highcharts-3d.js"
|
23
|
+
|
24
|
+
# Modules
|
25
|
+
sh "curl -# http://code.highcharts.com/modules/accessibility.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/modules/accessibility.js"
|
26
|
+
sh "curl -# http://code.highcharts.com/modules/annotations.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/modules/annotations.js"
|
27
|
+
sh "curl -# http://code.highcharts.com/modules/boost.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/modules/boost.js"
|
28
|
+
sh "curl -# http://code.highcharts.com/modules/broken-axis.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/modules/broken-axis.js"
|
29
|
+
sh "curl -# http://code.highcharts.com/modules/canvas-tools.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/modules/canvas-tools.js"
|
30
|
+
sh "curl -# http://code.highcharts.com/modules/data.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/modules/data.js"
|
31
|
+
sh "curl -# http://code.highcharts.com/modules/exporting.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/modules/exporting.js"
|
32
|
+
sh "curl -# http://code.highcharts.com/modules/drilldown.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/modules/drilldown.js"
|
33
|
+
sh "curl -# http://code.highcharts.com/modules/funnel.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/modules/funnel.js"
|
34
|
+
sh "curl -# http://code.highcharts.com/modules/heatmap.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/modules/heatmap.js"
|
35
|
+
sh "curl -# http://code.highcharts.com/modules/no-data-to-display.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/modules/no-data-to-display.js"
|
36
|
+
sh "curl -# http://code.highcharts.com/modules/offline-exporting.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/modules/offline-exporting.js"
|
37
|
+
sh "curl -# http://code.highcharts.com/modules/solid-gauge.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/modules/solid-gauge.js"
|
38
|
+
sh "curl -# http://code.highcharts.com/modules/treemap.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/modules/treemap.js"
|
39
|
+
|
40
|
+
sh "curl -# http://code.highcharts.com/adapters/mootools-adapter.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/adapters/mootools-adapter.js"
|
41
|
+
sh "curl -# http://code.highcharts.com/adapters/prototype-adapter.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/adapters/prototype-adapter.js"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
task :stock do
|
46
|
+
say "Grabbing Highcharts Stock JS from Upstream..." do
|
47
|
+
|
48
|
+
sh "mkdir -p lib/daru/view/adapters/js/highcharts_js/stock/modules/"
|
49
|
+
sh "mkdir -p lib/daru/view/adapters/js/highcharts_js/stock/adapters/"
|
50
|
+
|
51
|
+
sh "curl -# http://code.highcharts.com/stock/highstock.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/highstock.js"
|
52
|
+
sh "curl -# http://code.highcharts.com/stock/highcharts-more.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/stock/highcharts-more.js"
|
53
|
+
sh "curl -# http://code.highcharts.com/stock/modules/exporting.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/stock/modules/exporting.js"
|
54
|
+
sh "curl -# http://code.highcharts.com/stock/modules/funnel.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/stock/modules/funnel.js"
|
55
|
+
sh "curl -# http://code.highcharts.com/stock/adapters/mootools-adapter.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/stock/adapters/mootools-adapter.js"
|
56
|
+
sh "curl -# http://code.highcharts.com/stock/adapters/prototype-adapter.js -L --compressed -o lib/daru/view/adapters/js/highcharts_js/stock/adapters/prototype-adapter.js"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -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 :nyaplot do
|
11
|
+
desc "Update nyaplot.js from latest Builds on Nyaplotjs github repo and d3.js website"
|
12
|
+
task :update => [:nyaplot, :d3]
|
13
|
+
task :nyaplot do
|
14
|
+
say "Grabbing Core from Nyaplotjs codebase..." do
|
15
|
+
# TODO get the nyaplot js file
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
task :d3 do
|
20
|
+
say "Grabbing Highcharts Stock JS from Upstream..." do
|
21
|
+
# TODO : get the d3 and d3-downloaded
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Daru::View::Table, 'table using daru-data_tables' do
|
4
|
+
before { Daru::View.table_library = :datatables }
|
5
|
+
before(:each) do
|
6
|
+
@data_array = [[1, 15], [2, 30], [4, 40]]
|
7
|
+
@data_vec1 = Daru::Vector.new([1 ,2, 4])
|
8
|
+
@data_vec2 = Daru::Vector.new([15 ,30, 40])
|
9
|
+
@data_df = Daru::DataFrame.new(arr1: @data_vec1, arr2: @data_vec2)
|
10
|
+
|
11
|
+
@options = {width: 800, height: 720}
|
12
|
+
|
13
|
+
@plot = Daru::View::Table.new(@data_df, @options)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "initialization Tables" do
|
17
|
+
it "Table class must be Daru::DataTables::DataTable " do
|
18
|
+
expect(Daru::View::Table.new.table).to be_a Daru::DataTables::DataTable
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Daru::View::Plot, 'plotting with googlecharts' do
|
4
|
+
before { Daru::View.plotting_library = :googlecharts }
|
5
|
+
before(:each) do
|
6
|
+
@data_array = [[1, 15], [2, 30], [4, 40]]
|
7
|
+
@data_vec1 = Daru::Vector.new([1 ,2, 4])
|
8
|
+
@data_vec2 = Daru::Vector.new([15 ,30, 40])
|
9
|
+
@data_df = Daru::DataFrame.new(arr1: @data_vec1, arr2: @data_vec2)
|
10
|
+
|
11
|
+
@options = {width: 800, height: 720}
|
12
|
+
|
13
|
+
@plot = Daru::View::Plot.new(@data_df, @options)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "initialization Charts" do
|
17
|
+
it "Default chart GoogleVisualr::Interactive::LineChart " do
|
18
|
+
expect(Daru::View::Plot.new.chart).to be_a GoogleVisualr::Interactive::LineChart
|
19
|
+
end
|
20
|
+
it "Bar chart GoogleVisualr::Interactive::BarChart " do
|
21
|
+
expect(Daru::View::Plot.new([], type: :bar).chart).to be_a GoogleVisualr::Interactive::BarChart
|
22
|
+
end
|
23
|
+
it "Column chart GoogleVisualr::Interactive::ColumnChart " do
|
24
|
+
expect(Daru::View::Plot.new([], type: :column).chart).to be_a GoogleVisualr::Interactive::ColumnChart
|
25
|
+
end
|
26
|
+
# TODO: all other kinds of charts
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "initialization Tables" do
|
30
|
+
it "Table class must be GoogleVisualr::DataTable " do
|
31
|
+
expect(Daru::View::Table.new.table).to be_a GoogleVisualr::DataTable
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
# some specs from lazy_high_charts specs
|
4
|
+
describe Daru::View::Plot, 'plotting with highcharts' do
|
5
|
+
before { Daru::View.plotting_library = :highcharts }
|
6
|
+
before(:each) do
|
7
|
+
@data = [[1, 15], [2, 30], [4, 40]]
|
8
|
+
|
9
|
+
@placeholder = "placeholder"
|
10
|
+
@html_options = {:class => "stylin"}
|
11
|
+
@options = {:bars => {:show => true}}
|
12
|
+
|
13
|
+
@flot = Daru::View::Plot.new(@data, @options)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "initialization" do
|
17
|
+
it "shouldn't generate a nil placeholder" do
|
18
|
+
expect(Daru::View::Plot.new.chart.placeholder).not_to be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:plt) { Daru::View::Plot.new }
|
22
|
+
before { plt.chart.placeholder = @placeholder }
|
23
|
+
it "should take an optional 'placeholder' argument" do
|
24
|
+
expect(plt.chart.placeholder).to eq(@placeholder)
|
25
|
+
expect(Daru::View::Plot.new.chart.placeholder).not_to eq(@placeholder)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should generate different placeholders for different charts" do
|
29
|
+
a_different_placeholder = Daru::View::Plot.new.chart.placeholder
|
30
|
+
expect(Daru::View::Plot.new.chart.placeholder).not_to eq(a_different_placeholder)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should able take an optional html_options argument (defaulting to 300px height)" do
|
34
|
+
expect(Daru::View::Plot.new.chart.html_options).to eq({})
|
35
|
+
end
|
36
|
+
|
37
|
+
before { plt.chart.html_options = @html_options }
|
38
|
+
it "should able take an optional html_options argument (defaulting to 300px height)" do
|
39
|
+
expect(plt.chart.html_options).to eq(@html_options)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should set options by default" do
|
43
|
+
expect(Daru::View::Plot.new.chart.options).to eq({
|
44
|
+
:title => {:text => nil},
|
45
|
+
:legend => {:layout => "vertical", :style => {}},
|
46
|
+
:xAxis => {},
|
47
|
+
:yAxis => {:title => {:text => nil}, :labels => {}},
|
48
|
+
:tooltip => {:enabled => true},
|
49
|
+
:credits => {:enabled => false},
|
50
|
+
:plotOptions => {:areaspline => {}},
|
51
|
+
:chart => {:defaultSeriesType => "line", :renderTo => nil},
|
52
|
+
:subtitle => {}})
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should set data empty by default" do
|
56
|
+
expect(Daru::View::Plot.new.chart.series_data).to eq(
|
57
|
+
[{:type=>nil, :name=>nil, :data=>[]}])
|
58
|
+
end
|
59
|
+
|
60
|
+
let(:graph) { Daru::View::Plot.new }
|
61
|
+
it "should take a block setting attributes" do
|
62
|
+
graph.chart.tap do |f|
|
63
|
+
f.series_data = @data
|
64
|
+
f.options = @options
|
65
|
+
end
|
66
|
+
expect(graph.chart.series_data).to eq(@data)
|
67
|
+
expect(graph.chart.options).to eq(@options)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should take a block setting attributes" do
|
71
|
+
# Didn't understand why it fails :
|
72
|
+
# 1. when we do graph.chart do |f| ..
|
73
|
+
# 2. when we do graph.chart {|f| ..}
|
74
|
+
graph_chart = graph.chart.tap do |f|
|
75
|
+
f.options[:legend][:layout] = "horizontal"
|
76
|
+
end
|
77
|
+
expect(graph_chart.options[:legend][:layout]).to eq("horizontal")
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should take a block setting attributes" do
|
81
|
+
graph_chart = graph.chart.tap do |f|
|
82
|
+
f.options[:range_selector] = {}
|
83
|
+
f.options[:range_selector][:selected] = 1
|
84
|
+
end
|
85
|
+
expect(graph_chart.options[:range_selector][:selected]).to eq(1)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should change a block data without overriding options" do
|
89
|
+
graph = Daru::View::Plot.new.chart.tap do |f|
|
90
|
+
f.series(:name => 'John', :data => [3, 20])
|
91
|
+
f.series(:name => 'Jane', :data => [1, 3])
|
92
|
+
# without overriding
|
93
|
+
f.options[:chart][:defaultSeriesType] = "area"
|
94
|
+
f.options[:chart][:inverted] = true
|
95
|
+
f.options[:legend][:layout] = "horizontal"
|
96
|
+
f.options[:xAxis][:categories] = ["uno", "dos", "tres", "cuatro"]
|
97
|
+
end
|
98
|
+
# {type: nil, :name => nil, :data => []} series is added during
|
99
|
+
# the initialzation of chart. User can remove it using this line:
|
100
|
+
# graph.delete({type: nil, :name => nil, :data => []})
|
101
|
+
expect(graph.series_data).to eq([
|
102
|
+
{type: nil, :name => nil, :data => []},
|
103
|
+
{:name => "John", :data => [3, 20]},
|
104
|
+
{:name => "Jane", :data => [1, 3]}
|
105
|
+
])
|
106
|
+
expect(graph.options[:legend][:layout]).to eq("horizontal")
|
107
|
+
expect(graph.options[:xAxis][:categories]).to eq(["uno", "dos", "tres", "cuatro"])
|
108
|
+
expect(graph.options[:chart][:defaultSeriesType]).to eq("area")
|
109
|
+
expect(graph.options[:chart][:inverted]).to eq(true)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should change a block data with overriding entire options" do
|
113
|
+
graph = Daru::View::Plot.new.chart.tap do |f|
|
114
|
+
f.series(:name => 'John', :data => [3, 20])
|
115
|
+
f.series(:name => 'Jane', :data => [1, 3])
|
116
|
+
f.title({:text => nil})
|
117
|
+
# without overriding
|
118
|
+
f.xAxis(:categories => ["uno", "dos", "tres", "cuatro"], :labels => {:rotation => -45, :align => 'right'})
|
119
|
+
f.chart({:defaultSeriesType => "spline", :renderTo => "myRenderArea", :inverted => true})
|
120
|
+
end
|
121
|
+
expect(graph.options[:xAxis][:categories]).to eq(["uno", "dos", "tres", "cuatro"])
|
122
|
+
expect(graph.options[:xAxis][:labels][:rotation]).to eq(-45)
|
123
|
+
expect(graph.options[:xAxis][:labels][:align]).to eq("right")
|
124
|
+
expect(graph.options[:chart][:defaultSeriesType]).to eq("spline")
|
125
|
+
expect(graph.options[:chart][:renderTo]).to eq("myRenderArea")
|
126
|
+
expect(graph.options[:chart][:inverted]).to eq(true)
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should have subtitles" do
|
130
|
+
graph = Daru::View::Plot.new.chart.tap do |f|
|
131
|
+
f.series(:name => 'John', :data => [3, 20])
|
132
|
+
f.series(:name => 'Jane', :data => [1, 3])
|
133
|
+
f.title({:text => nil})
|
134
|
+
# without overriding
|
135
|
+
f.x_axis(:categories => ["uno", "dos", "tres", "cuatro"], :labels => {:rotation => -45, :align => 'right'})
|
136
|
+
f.chart({:defaultSeriesType => "spline", :renderTo => "myRenderArea", :inverted => true})
|
137
|
+
f.subtitle({:text => "Bar"})
|
138
|
+
end
|
139
|
+
expect(graph.options[:subtitle][:text]).to eq("Bar")
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should override entire option by default when resetting it again' do
|
143
|
+
graph = Daru::View::Plot.new.chart.tap do |f|
|
144
|
+
f.xAxis(categories: [3, 5, 7])
|
145
|
+
f.xAxis(title: {text: 'x title'})
|
146
|
+
end
|
147
|
+
expect(graph.options[:xAxis][:categories]).to eq(nil)
|
148
|
+
expect(graph.options[:xAxis][:title][:text]).to eq('x title')
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'should allow to build options step by step without overriding previously set values' do
|
152
|
+
graph = Daru::View::Plot.new.chart.tap do |f|
|
153
|
+
f.xAxis!(categories: [3, 5, 7])
|
154
|
+
f.xAxis!(title: {text: 'x title'})
|
155
|
+
end
|
156
|
+
expect(graph.options[:xAxis][:categories]).to eq([3, 5, 7])
|
157
|
+
expect(graph.options[:xAxis][:title][:text]).to eq('x title')
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'should merge options and data into a full options hash' do
|
161
|
+
graph = Daru::View::Plot.new.chart.tap do |f|
|
162
|
+
f.series(name: 'John', data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4])
|
163
|
+
f.series(name: 'Jane', data: [140.02, 41.63, 66.72, 113.21, 107.98, 105.71, 28.59, 114.23, 5.56, 93.71, 137.35, 93.16])
|
164
|
+
f.title({text: 'Example Data'})
|
165
|
+
f.xAxis(categories: %w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec), labels: {rotation: -45, align: 'right'})
|
166
|
+
f.options[:tooltip][:formatter] = "function(){ return '<b>'+ this.point.name +'</b>: '+ Highcharts.numberFormat(this.percentage, 2) +' %'; }"
|
167
|
+
end
|
168
|
+
|
169
|
+
json = graph.full_options
|
170
|
+
expect(json).to match /\"series\"/
|
171
|
+
expect(json).to match /\"title\"/
|
172
|
+
expect(json).to match /\"tooltip\": { \"enabled\": true,\"formatter\"/
|
173
|
+
expect(json).to match /\"data\": \[ 29.9,71.5,106.4,129.2,144.0,176.0,135.6,148.5,216.4,194.1,95.6,54.4 \]/
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
end
|
@@ -0,0 +1,447 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
# some specs from daru specs
|
4
|
+
describe Daru::View::Plot, 'plotting Vector with nyaplot library' do
|
5
|
+
let(:vector) { Daru::Vector.new([11, 22, 33], index: [:a, :b, :c]) }
|
6
|
+
let(:plot) { instance_double('Nyaplot::Plot') }
|
7
|
+
|
8
|
+
before do
|
9
|
+
Daru::View.plotting_library = :nyaplot
|
10
|
+
allow(Nyaplot::Plot).to receive(:new).and_return(plot)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'plots the vector' do
|
14
|
+
expect(plot).to receive(:add).with(:box, [11, 22, 33]).ordered
|
15
|
+
|
16
|
+
expect(Daru::View::Plot.new(vector, type: :box).chart).to eq plot
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'scatter' do
|
20
|
+
it 'is default type' do
|
21
|
+
expect(plot).to receive(:add).with(:scatter, instance_of(Array), instance_of(Array)).ordered
|
22
|
+
|
23
|
+
expect(Daru::View::Plot.new(vector).chart).to eq plot
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'sets x_axis to 0...size' do
|
27
|
+
expect(plot).to receive(:add).with(:scatter, [0, 1, 2], [11, 22, 33]).ordered
|
28
|
+
|
29
|
+
expect(Daru::View::Plot.new(vector, type: :scatter).chart).to eq plot
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
[:box, :histogram].each do |type|
|
34
|
+
context type.to_s do
|
35
|
+
it 'does not set x axis' do
|
36
|
+
expect(plot).to receive(:add).with(type, [11, 22, 33]).ordered
|
37
|
+
|
38
|
+
expect(Daru::View::Plot.new(vector, type: type).chart).to eq plot
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
[:bar, :line].each do |type| # FIXME: what other types 2D plot could have?..
|
44
|
+
context type.to_s do
|
45
|
+
it 'sets x axis to index' do
|
46
|
+
expect(plot).to receive(:add).with(type, [:a, :b, :c], [11, 22, 33]).ordered
|
47
|
+
|
48
|
+
expect(Daru::View::Plot.new(vector, type: type).chart).to eq plot
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# category vector
|
55
|
+
describe Daru::View::Plot, 'plotting Category Vector with nyaplot library' do
|
56
|
+
let(:plot) { instance_double('Nyaplot::Plot') }
|
57
|
+
let(:dv) do
|
58
|
+
Daru::Vector.new ['III']*10 + ['II']*5 + ['I']*5,
|
59
|
+
type: :category,
|
60
|
+
categories: ['I', 'II', 'III']
|
61
|
+
end
|
62
|
+
before do
|
63
|
+
Daru::View.plotting_library = :nyaplot
|
64
|
+
allow(Nyaplot::Plot).to receive(:new).and_return(plot)
|
65
|
+
end
|
66
|
+
context 'bar' do
|
67
|
+
it 'plots bar graph taking a block' do
|
68
|
+
expect(plot).to receive(:add).with(:bar, ['I', 'II', 'III'], [5, 5, 10])
|
69
|
+
expect(plot).to receive :x_label
|
70
|
+
expect(plot).to receive :y_label
|
71
|
+
# need to write with tap, below test
|
72
|
+
Daru::View::Plot.new(dv, type: :bar).chart.tap do |p|
|
73
|
+
p.x_label 'Categories'
|
74
|
+
p.y_label 'Frequency'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'plots bar graph without taking a block' do
|
79
|
+
expect(plot).to receive(:add).with(:bar, ["I", "II", "III"], [5, 5, 10])
|
80
|
+
expect(Daru::View::Plot.new(dv, type: :bar).chart).to eq plot
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'plots bar graph with percentage' do
|
84
|
+
expect(plot).to receive(:add).with(:bar, ["I", "II", "III"], [25, 25, 50])
|
85
|
+
expect(plot).to receive(:yrange).with [0, 100]
|
86
|
+
expect(Daru::View::Plot.new(dv, type: :bar, method: :percentage).chart).to eq plot
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'plots bar graph with fraction' do
|
90
|
+
expect(plot).to receive(:add).with(:bar, ["I", "II", "III"], [0.25, 0.25, 0.50])
|
91
|
+
expect(plot).to receive(:yrange).with [0, 1]
|
92
|
+
expect(Daru::View::Plot.new(dv, type: :bar, method: :fraction).chart).to eq plot
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'other type' do
|
97
|
+
it { expect { Daru::View::Plot.new(dv, type: :scatter) }.to raise_error ArgumentError }
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# testing DataFrame
|
102
|
+
class Nyaplot::DataFrame
|
103
|
+
# Because it does not allow to any equality testing
|
104
|
+
def == other
|
105
|
+
other.is_a?(Nyaplot::DataFrame) && rows == other.rows
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe Daru::View::Plot, 'plotting DataFrame with Nyaplot library' do
|
110
|
+
let(:data_frame) {
|
111
|
+
Daru::DataFrame.new({
|
112
|
+
x: [1, 2, 3, 4],
|
113
|
+
y1: [5, 7, 9, 11],
|
114
|
+
y2: [-3, -7, -11, -15],
|
115
|
+
cat: [:a, :b, :c, :d]
|
116
|
+
},
|
117
|
+
index: [:one, :two, :three, :four]
|
118
|
+
)
|
119
|
+
}
|
120
|
+
let(:plot) { instance_double('Nyaplot::Plot') }
|
121
|
+
|
122
|
+
before do
|
123
|
+
allow(Nyaplot::Plot).to receive(:new).and_return(plot)
|
124
|
+
end
|
125
|
+
|
126
|
+
context 'box' do
|
127
|
+
let(:numerics) { data_frame.only_numerics }
|
128
|
+
it 'plots numeric vectors' do
|
129
|
+
expect(plot).to receive(:add_with_df)
|
130
|
+
.with(numerics.to_nyaplotdf, :box, :x, :y1, :y2)
|
131
|
+
.ordered
|
132
|
+
|
133
|
+
expect(Daru::View::Plot.new(data_frame, type: :box).chart).to eq plot
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'other types' do
|
138
|
+
context 'single chart' do
|
139
|
+
it 'works with :y provided' do
|
140
|
+
expect(plot).to receive(:add_with_df)
|
141
|
+
.with(data_frame.to_nyaplotdf, :scatter, :x, :y1)
|
142
|
+
.ordered
|
143
|
+
|
144
|
+
expect(Daru::View::Plot.new(
|
145
|
+
data_frame,
|
146
|
+
type: :scatter, x: :x, y: :y1).chart
|
147
|
+
).to eq plot
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'works without :y provided' do
|
151
|
+
expect(plot).to receive(:add_with_df)
|
152
|
+
.with(data_frame.to_nyaplotdf, :scatter, :x)
|
153
|
+
.ordered
|
154
|
+
|
155
|
+
expect(Daru::View::Plot.new(
|
156
|
+
data_frame,
|
157
|
+
type: :scatter, x: :x).chart
|
158
|
+
).to eq plot
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context 'multiple charts' do
|
163
|
+
it 'works with single type provided' do
|
164
|
+
expect(plot).to receive(:add_with_df)
|
165
|
+
.with(data_frame.to_nyaplotdf, :scatter, :x, :y1)
|
166
|
+
.ordered
|
167
|
+
expect(plot).to receive(:add_with_df)
|
168
|
+
.with(data_frame.to_nyaplotdf, :scatter, :x, :y2)
|
169
|
+
.ordered
|
170
|
+
|
171
|
+
expect(
|
172
|
+
Daru::View::Plot.new(
|
173
|
+
data_frame, type: :scatter, x: [:x, :x], y: [:y1, :y2]).chart
|
174
|
+
).to eq plot
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'works with multiple types provided' do
|
178
|
+
expect(plot).to receive(:add_with_df)
|
179
|
+
.with(data_frame.to_nyaplotdf, :scatter, :x, :y1)
|
180
|
+
.ordered
|
181
|
+
expect(plot).to receive(:add_with_df)
|
182
|
+
.with(data_frame.to_nyaplotdf, :line, :x, :y2)
|
183
|
+
.ordered
|
184
|
+
|
185
|
+
expect(
|
186
|
+
Daru::View::Plot.new(
|
187
|
+
data_frame,
|
188
|
+
type: [:scatter, :line], x: [:x, :x], y: [:y1, :y2]).chart
|
189
|
+
).to eq plot
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'works with numeric var names' do
|
193
|
+
expect(plot).to receive(:add_with_df)
|
194
|
+
.with(data_frame.to_nyaplotdf, :scatter, :x, :y1)
|
195
|
+
.ordered
|
196
|
+
expect(plot).to receive(:add_with_df)
|
197
|
+
.with(data_frame.to_nyaplotdf, :line, :x, :y2)
|
198
|
+
.ordered
|
199
|
+
|
200
|
+
expect(
|
201
|
+
Daru::View::Plot.new(
|
202
|
+
data_frame,
|
203
|
+
type: [:scatter, :line],
|
204
|
+
# FIXME: this didn't work due to default type: :scatter opts
|
205
|
+
#type1: :scatter,
|
206
|
+
#type2: :line,
|
207
|
+
x1: :x,
|
208
|
+
x2: :x,
|
209
|
+
y1: :y1,
|
210
|
+
y2: :y2
|
211
|
+
).chart
|
212
|
+
).to eq plot
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
describe Daru::View::Plot, 'DataFrame category plotting with Nyaplot lib' do
|
219
|
+
context 'scatter' do
|
220
|
+
let(:df) do
|
221
|
+
Daru::DataFrame.new({
|
222
|
+
a: [1, 2, 4, -2, 5, 23, 0],
|
223
|
+
b: [3, 1, 3, -6, 2, 1, 0],
|
224
|
+
c: ['I', 'II', 'I', 'III', 'I', 'III', 'II']
|
225
|
+
})
|
226
|
+
end
|
227
|
+
let(:plot) { instance_double('Nyaplot::Plot') }
|
228
|
+
let(:diagram) { instance_double('Nyaplot::Diagram::Scatter') }
|
229
|
+
|
230
|
+
before do
|
231
|
+
df.to_category :c
|
232
|
+
allow(Nyaplot::Plot).to receive(:new).and_return(plot)
|
233
|
+
allow(plot).to receive(:add_with_df).and_return(diagram)
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'plots scatter plot categoried by color with a block' do
|
237
|
+
expect(plot).to receive :add_with_df
|
238
|
+
expect(diagram).to receive(:title).exactly(3).times
|
239
|
+
expect(diagram).to receive(:color).exactly(3).times
|
240
|
+
expect(diagram).to receive(:tooltip_contents).exactly(3).times
|
241
|
+
expect(plot).to receive :legend
|
242
|
+
expect(plot).to receive :xrange
|
243
|
+
expect(plot).to receive :yrange
|
244
|
+
Daru::View::Plot.new(
|
245
|
+
df, type: :scatter, x: :a, y: :b,
|
246
|
+
categorized: {by: :c, method: :color}
|
247
|
+
).chart.tap do |p, d|
|
248
|
+
p.xrange [-10, 10]
|
249
|
+
p.yrange [-10, 10]
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
it 'plots scatter plot categoried by color' do
|
254
|
+
expect(plot).to receive :add_with_df
|
255
|
+
expect(diagram).to receive(:title).exactly(3).times
|
256
|
+
expect(diagram).to receive(:color).exactly(3).times
|
257
|
+
expect(diagram).to receive(:tooltip_contents).exactly(3).times
|
258
|
+
expect(plot).to receive :legend
|
259
|
+
expect(
|
260
|
+
Daru::View::Plot.new(
|
261
|
+
df,
|
262
|
+
type: :scatter, x: :a, y: :b,
|
263
|
+
categorized: {by: :c, method: :color}).chart
|
264
|
+
).to eq plot
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'plots scatter plot categoried by custom colors' do
|
268
|
+
expect(plot).to receive :add_with_df
|
269
|
+
expect(diagram).to receive(:title).exactly(3).times
|
270
|
+
expect(diagram).to receive(:color).with :red
|
271
|
+
expect(diagram).to receive(:color).with :blue
|
272
|
+
expect(diagram).to receive(:color).with :green
|
273
|
+
expect(diagram).to receive(:tooltip_contents).exactly(3).times
|
274
|
+
expect(plot).to receive :legend
|
275
|
+
expect(
|
276
|
+
Daru::View::Plot.new(
|
277
|
+
df, type: :scatter, x: :a, y: :b,
|
278
|
+
categorized: {by: :c, method: :color, color: [:red, :blue, :green]}
|
279
|
+
).chart
|
280
|
+
).to eq plot
|
281
|
+
end
|
282
|
+
|
283
|
+
it 'plots scatter plot categoried by shape' do
|
284
|
+
expect(plot).to receive :add_with_df
|
285
|
+
expect(diagram).to receive(:title).exactly(3).times
|
286
|
+
expect(diagram).to receive(:shape).exactly(3).times
|
287
|
+
expect(diagram).to receive(:tooltip_contents).exactly(3).times
|
288
|
+
expect(plot).to receive :legend
|
289
|
+
expect(Daru::View::Plot.new(
|
290
|
+
df, type: :scatter, x: :a, y: :b,
|
291
|
+
categorized: {by: :c, method: :shape}).chart
|
292
|
+
).to eq plot
|
293
|
+
end
|
294
|
+
|
295
|
+
it 'plots scatter plot categoried by custom shapes' do
|
296
|
+
expect(plot).to receive :add_with_df
|
297
|
+
expect(diagram).to receive(:title).exactly(3).times
|
298
|
+
expect(diagram).to receive(:shape).with 'circle'
|
299
|
+
expect(diagram).to receive(:shape).with 'triangle-up'
|
300
|
+
expect(diagram).to receive(:shape).with 'diamond'
|
301
|
+
expect(diagram).to receive(:tooltip_contents).exactly(3).times
|
302
|
+
expect(plot).to receive :legend
|
303
|
+
expect(
|
304
|
+
Daru::View::Plot.new(
|
305
|
+
df,
|
306
|
+
type: :scatter, x: :a, y: :b,
|
307
|
+
categorized: {
|
308
|
+
by: :c, method: :shape,
|
309
|
+
shape: %w(circle triangle-up diamond)}).chart
|
310
|
+
).to eq plot
|
311
|
+
end
|
312
|
+
|
313
|
+
it 'plots scatter plot categoried by size' do
|
314
|
+
expect(plot).to receive :add_with_df
|
315
|
+
expect(diagram).to receive(:title).exactly(3).times
|
316
|
+
expect(diagram).to receive(:size).exactly(3).times
|
317
|
+
expect(diagram).to receive(:tooltip_contents).exactly(3).times
|
318
|
+
expect(plot).to receive :legend
|
319
|
+
expect(Daru::View::Plot.new(
|
320
|
+
df, type: :scatter, x: :a, y: :b,
|
321
|
+
categorized: {by: :c, method: :size}).chart).to eq plot
|
322
|
+
end
|
323
|
+
|
324
|
+
it 'plots scatter plot categoried by cusom sizes' do
|
325
|
+
expect(plot).to receive :add_with_df
|
326
|
+
expect(diagram).to receive(:title).exactly(3).times
|
327
|
+
expect(diagram).to receive(:size).with 100
|
328
|
+
expect(diagram).to receive(:size).with 200
|
329
|
+
expect(diagram).to receive(:size).with 300
|
330
|
+
expect(diagram).to receive(:tooltip_contents).exactly(3).times
|
331
|
+
expect(plot).to receive :legend
|
332
|
+
expect(
|
333
|
+
Daru::View::Plot.new(
|
334
|
+
df,
|
335
|
+
type: :scatter,
|
336
|
+
x: :a, y: :b,
|
337
|
+
categorized: {
|
338
|
+
by: :c,
|
339
|
+
method: :size,
|
340
|
+
size: [100, 200, 300]
|
341
|
+
}
|
342
|
+
).chart
|
343
|
+
).to eq plot
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
context 'line' do
|
348
|
+
let(:df) do
|
349
|
+
Daru::DataFrame.new({
|
350
|
+
a: [1, 2, 4, -2, 5, 23, 0],
|
351
|
+
b: [3, 1, 3, -6, 2, 1, 0],
|
352
|
+
c: ['I', 'II', 'I', 'III', 'I', 'III', 'II']
|
353
|
+
})
|
354
|
+
end
|
355
|
+
let(:plot) { instance_double('Nyaplot::Plot') }
|
356
|
+
let(:diagram) { instance_double('Nyaplot::Diagram::Scatter') }
|
357
|
+
|
358
|
+
before do
|
359
|
+
df.to_category :c
|
360
|
+
allow(Nyaplot::Plot).to receive(:new).and_return(plot)
|
361
|
+
allow(plot).to receive(:add_with_df).and_return(diagram)
|
362
|
+
end
|
363
|
+
|
364
|
+
it 'plots line plot categoried by color with a block' do
|
365
|
+
expect(plot).to receive :add_with_df
|
366
|
+
expect(diagram).to receive(:title).exactly(3).times
|
367
|
+
expect(diagram).to receive(:color).exactly(3).times
|
368
|
+
expect(plot).to receive :legend
|
369
|
+
expect(plot).to receive :xrange
|
370
|
+
expect(plot).to receive :yrange
|
371
|
+
Daru::View::Plot.new(
|
372
|
+
df, type: :line, x: :a, y: :b,
|
373
|
+
categorized: {by: :c, method: :color}).chart.tap do |p, d|
|
374
|
+
p.xrange [-10, 10]
|
375
|
+
p.yrange [-10, 10]
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
it 'plots line plot categoried by color' do
|
380
|
+
expect(plot).to receive :add_with_df
|
381
|
+
expect(diagram).to receive(:title).exactly(3).times
|
382
|
+
expect(diagram).to receive(:color).exactly(3).times
|
383
|
+
expect(plot).to receive :legend
|
384
|
+
expect(
|
385
|
+
Daru::View::Plot.new(df,
|
386
|
+
type: :line, x: :a, y: :b,
|
387
|
+
categorized: {by: :c, method: :color}
|
388
|
+
).chart
|
389
|
+
).to eq plot
|
390
|
+
end
|
391
|
+
|
392
|
+
it 'plots line plot categoried by custom colors' do
|
393
|
+
expect(plot).to receive :add_with_df
|
394
|
+
expect(diagram).to receive(:title).exactly(3).times
|
395
|
+
expect(diagram).to receive(:color).with :red
|
396
|
+
expect(diagram).to receive(:color).with :blue
|
397
|
+
expect(diagram).to receive(:color).with :green
|
398
|
+
expect(plot).to receive :legend
|
399
|
+
expect(
|
400
|
+
Daru::View::Plot.new(df,
|
401
|
+
type: :line, x: :a, y: :b,
|
402
|
+
categorized: {by: :c, method: :color, color: [:red, :blue, :green]}
|
403
|
+
).chart
|
404
|
+
).to eq plot
|
405
|
+
end
|
406
|
+
|
407
|
+
it 'plots line plot categoried by stroke width' do
|
408
|
+
expect(plot).to receive :add_with_df
|
409
|
+
expect(diagram).to receive(:title).exactly(3).times
|
410
|
+
expect(diagram).to receive(:stroke_width).exactly(3).times
|
411
|
+
expect(plot).to receive :legend
|
412
|
+
expect(
|
413
|
+
Daru::View::Plot.new(df,
|
414
|
+
type: :line, x: :a, y: :b,
|
415
|
+
categorized: {by: :c, method: :stroke_width}
|
416
|
+
).chart
|
417
|
+
).to eq plot
|
418
|
+
end
|
419
|
+
|
420
|
+
it 'plots line plot categoried by custom stroke widths' do
|
421
|
+
expect(plot).to receive :add_with_df
|
422
|
+
expect(diagram).to receive(:title).exactly(3).times
|
423
|
+
expect(diagram).to receive(:stroke_width).with 100
|
424
|
+
expect(diagram).to receive(:stroke_width).with 200
|
425
|
+
expect(diagram).to receive(:stroke_width).with 300
|
426
|
+
expect(plot).to receive :legend
|
427
|
+
expect(
|
428
|
+
Daru::View::Plot.new(df,
|
429
|
+
type: :line, x: :a, y: :b,
|
430
|
+
categorized: {
|
431
|
+
by: :c, method: :stroke_width, stroke_width: [100, 200, 300]}
|
432
|
+
).chart
|
433
|
+
).to eq plot
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
context "invalid type" do
|
438
|
+
let(:df) do
|
439
|
+
Daru::DataFrame.new({
|
440
|
+
a: [1, 2, 4, -2, 5, 23, 0],
|
441
|
+
b: [3, 1, 3, -6, 2, 1, 0],
|
442
|
+
c: ['I', 'II', 'I', 'III', 'I', 'III', 'II']
|
443
|
+
})
|
444
|
+
end
|
445
|
+
it { expect { Daru::View::Plot.new(df, type: :box, categorized: {by: :c, method: :color}).chart }.to raise_error ArgumentError }
|
446
|
+
end
|
447
|
+
end
|