diff --git a/spec/plot_spec.rb b/spec/plot_spec.rb index 240cc85..ddbed39 100644 --- a/spec/plot_spec.rb +++ b/spec/plot_spec.rb @@ -21,11 +21,15 @@ context 'chart using DataFrame' do it { expect(plot_df).to be_a Daru::View::Plot } it { expect(plot_df.chart.class).to eq Nyaplot::Plot } + it { expect(plot_df.data).to eq df} + it { expect(plot_df.options).to eq type: :line, x: :a, y: :c} end context 'chart using Vector' do it { expect(plot_dv).to be_a Daru::View::Plot } it { expect(plot_dv.chart).to be_a Nyaplot::Plot } + it { expect(plot_dv.data).to eq dv} + it { expect(plot_dv.options).to eq type: :line} end context 'fails when other than DataFrame and Vector is as data' do @@ -41,7 +45,19 @@ context 'Highcharts library' do before { Daru::View.plotting_library = :highcharts } let(:lib) { Daru::View.plotting_library } - let(:plot_array) { Daru::View::Plot.new([1, 2, 3]) } + let(:df) do + Daru::DataFrame.new( + { + a: [1, 2, 3, 4, 5, 6], + b: [1, 5, 2, 5, 1, 0], + c: [1, 6, 7, 2, 6, 0] + }, index: 'a'..'f' + ) + end + let(:dv) { Daru::Vector.new [1, 2, 3] } + let(:plot_df) { Daru::View::Plot.new(df, type: :line, x: :a, y: :c) } + let(:plot_dv) { Daru::View::Plot.new(dv, type: :line) } + let(:plot_array) { Daru::View::Plot.new([1, 2, 3], type: :line) } it 'check plotting library' do expect(lib).to eq(:highcharts) end @@ -49,14 +65,22 @@ it 'Highcharts chart using Array' do expect(plot_array).to be_a Daru::View::Plot expect(plot_array.chart).to be_a LazyHighCharts::HighChart + expect(plot_array.data).to eq [1, 2, 3] + expect(plot_array.options).to eq type: :line end it 'Highcharts chart using DataFrame' do - # todo + expect(plot_df).to be_a Daru::View::Plot + expect(plot_df.chart).to be_a LazyHighCharts::HighChart + expect(plot_df.data).to eq df + expect(plot_df.options).to eq type: :line, x: :a, y: :c end it 'Highcharts chart using Vector' do - # todo + expect(plot_dv).to be_a Daru::View::Plot + expect(plot_dv.chart).to be_a LazyHighCharts::HighChart + expect(plot_dv.data).to eq dv + expect(plot_dv.options).to eq type: :line end end end # initialize context end @@ -67,8 +91,21 @@ context 'Googlecharts library' do before { Daru::View.plotting_library = :googlecharts } let(:lib) { Daru::View.plotting_library } + let(:options) {{width: 800, height: 720}} + let(:df) do + Daru::DataFrame.new( + { + a: [1, 2, 3, 4, 5, 6], + b: [1, 5, 2, 5, 1, 0], + c: [1, 6, 7, 2, 6, 0] + }, index: 'a'..'f' + ) + end + let(:dv) { Daru::Vector.new [1, 2, 3] } + let(:plot_df) { Daru::View::Plot.new(df, options) } + let(:plot_dv) { Daru::View::Plot.new(dv, options) } let(:plot_array) { Daru::View::Plot.new( - [['col1', 'col2', 'col3'],[1, 2, 3]]) } + [['col1', 'col2', 'col3'],[1, 2, 3]], options) } it 'check plotting library' do expect(lib).to eq(:googlecharts) end @@ -76,14 +113,22 @@ it 'Googlecharts chart using Array' do expect(plot_array).to be_a Daru::View::Plot expect(plot_array.chart).to be_a GoogleVisualr::Interactive::LineChart + expect(plot_array.data).to eq [[1, 2, 3]] + expect(plot_array.options).to eq options end it 'Googlecharts chart using DataFrame' do - # todo + expect(plot_df).to be_a Daru::View::Plot + expect(plot_df.chart).to be_a GoogleVisualr::Interactive::LineChart + expect(plot_df.data).to eq df + expect(plot_df.options).to eq options end it 'Googlecharts chart using Vector' do - # todo + expect(plot_dv).to be_a Daru::View::Plot + expect(plot_dv.chart).to be_a GoogleVisualr::Interactive::LineChart + expect(plot_dv.data).to eq dv + expect(plot_dv.options).to eq options end end end # initialize context end