|
21 | 21 | context 'chart using DataFrame' do |
22 | 22 | it { expect(plot_df).to be_a Daru::View::Plot } |
23 | 23 | it { expect(plot_df.chart.class).to eq Nyaplot::Plot } |
| 24 | + it { expect(plot_df.data).to eq df} |
| 25 | + it { expect(plot_df.options).to eq type: :line, x: :a, y: :c} |
24 | 26 | end |
25 | 27 |
|
26 | 28 | context 'chart using Vector' do |
27 | 29 | it { expect(plot_dv).to be_a Daru::View::Plot } |
28 | 30 | it { expect(plot_dv.chart).to be_a Nyaplot::Plot } |
| 31 | + it { expect(plot_dv.data).to eq dv} |
| 32 | + it { expect(plot_dv.options).to eq type: :line} |
29 | 33 | end |
30 | 34 |
|
31 | 35 | context 'fails when other than DataFrame and Vector is as data' do |
|
41 | 45 | context 'Highcharts library' do |
42 | 46 | before { Daru::View.plotting_library = :highcharts } |
43 | 47 | let(:lib) { Daru::View.plotting_library } |
44 | | - let(:plot_array) { Daru::View::Plot.new([1, 2, 3]) } |
| 48 | + let(:df) do |
| 49 | + Daru::DataFrame.new( |
| 50 | + { |
| 51 | + a: [1, 2, 3, 4, 5, 6], |
| 52 | + b: [1, 5, 2, 5, 1, 0], |
| 53 | + c: [1, 6, 7, 2, 6, 0] |
| 54 | + }, index: 'a'..'f' |
| 55 | + ) |
| 56 | + end |
| 57 | + let(:dv) { Daru::Vector.new [1, 2, 3] } |
| 58 | + let(:plot_df) { Daru::View::Plot.new(df, type: :line, x: :a, y: :c) } |
| 59 | + let(:plot_dv) { Daru::View::Plot.new(dv, type: :line) } |
| 60 | + let(:plot_array) { Daru::View::Plot.new([1, 2, 3], type: :line) } |
45 | 61 | it 'check plotting library' do |
46 | 62 | expect(lib).to eq(:highcharts) |
47 | 63 | end |
48 | 64 |
|
49 | 65 | it 'Highcharts chart using Array' do |
50 | 66 | expect(plot_array).to be_a Daru::View::Plot |
51 | 67 | expect(plot_array.chart).to be_a LazyHighCharts::HighChart |
| 68 | + expect(plot_array.data).to eq [1, 2, 3] |
| 69 | + expect(plot_array.options).to eq type: :line |
52 | 70 | end |
53 | 71 |
|
54 | 72 | it 'Highcharts chart using DataFrame' do |
55 | | - # todo |
| 73 | + expect(plot_df).to be_a Daru::View::Plot |
| 74 | + expect(plot_df.chart).to be_a LazyHighCharts::HighChart |
| 75 | + expect(plot_df.data).to eq df |
| 76 | + expect(plot_df.options).to eq type: :line, x: :a, y: :c |
56 | 77 | end |
57 | 78 |
|
58 | 79 | it 'Highcharts chart using Vector' do |
59 | | - # todo |
| 80 | + expect(plot_dv).to be_a Daru::View::Plot |
| 81 | + expect(plot_dv.chart).to be_a LazyHighCharts::HighChart |
| 82 | + expect(plot_dv.data).to eq dv |
| 83 | + expect(plot_dv.options).to eq type: :line |
60 | 84 | end |
61 | 85 | end |
62 | 86 | end # initialize context end |
|
67 | 91 | context 'Googlecharts library' do |
68 | 92 | before { Daru::View.plotting_library = :googlecharts } |
69 | 93 | let(:lib) { Daru::View.plotting_library } |
| 94 | + let(:options) {{width: 800, height: 720}} |
| 95 | + let(:df) do |
| 96 | + Daru::DataFrame.new( |
| 97 | + { |
| 98 | + a: [1, 2, 3, 4, 5, 6], |
| 99 | + b: [1, 5, 2, 5, 1, 0], |
| 100 | + c: [1, 6, 7, 2, 6, 0] |
| 101 | + }, index: 'a'..'f' |
| 102 | + ) |
| 103 | + end |
| 104 | + let(:dv) { Daru::Vector.new [1, 2, 3] } |
| 105 | + let(:plot_df) { Daru::View::Plot.new(df, options) } |
| 106 | + let(:plot_dv) { Daru::View::Plot.new(dv, options) } |
70 | 107 | let(:plot_array) { Daru::View::Plot.new( |
71 | | - [['col1', 'col2', 'col3'],[1, 2, 3]]) } |
| 108 | + [['col1', 'col2', 'col3'],[1, 2, 3]], options) } |
72 | 109 | it 'check plotting library' do |
73 | 110 | expect(lib).to eq(:googlecharts) |
74 | 111 | end |
75 | 112 |
|
76 | 113 | it 'Googlecharts chart using Array' do |
77 | 114 | expect(plot_array).to be_a Daru::View::Plot |
78 | 115 | expect(plot_array.chart).to be_a GoogleVisualr::Interactive::LineChart |
| 116 | + expect(plot_array.data).to eq [[1, 2, 3]] |
| 117 | + expect(plot_array.options).to eq options |
79 | 118 | end |
80 | 119 |
|
81 | 120 | it 'Googlecharts chart using DataFrame' do |
82 | | - # todo |
| 121 | + expect(plot_df).to be_a Daru::View::Plot |
| 122 | + expect(plot_df.chart).to be_a GoogleVisualr::Interactive::LineChart |
| 123 | + expect(plot_df.data).to eq df |
| 124 | + expect(plot_df.options).to eq options |
83 | 125 | end |
84 | 126 |
|
85 | 127 | it 'Googlecharts chart using Vector' do |
86 | | - # todo |
| 128 | + expect(plot_dv).to be_a Daru::View::Plot |
| 129 | + expect(plot_dv.chart).to be_a GoogleVisualr::Interactive::LineChart |
| 130 | + expect(plot_dv.data).to eq dv |
| 131 | + expect(plot_dv.options).to eq options |
87 | 132 | end |
88 | 133 | end |
89 | 134 | end # initialize context end |
|
0 commit comments