daru 0.1.5 → 0.1.6
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 +4 -4
- data/.rubocop.yml +20 -7
- data/CONTRIBUTING.md +1 -1
- data/History.md +48 -1
- data/README.md +3 -3
- data/benchmarks/statistics.rb +6 -6
- data/benchmarks/where_clause.rb +1 -1
- data/benchmarks/where_vs_filter.rb +1 -1
- data/daru.gemspec +3 -2
- data/lib/daru.rb +14 -6
- data/lib/daru/accessors/gsl_wrapper.rb +1 -1
- data/lib/daru/accessors/nmatrix_wrapper.rb +2 -0
- data/lib/daru/category.rb +1 -1
- data/lib/daru/core/group_by.rb +32 -15
- data/lib/daru/core/query.rb +4 -4
- data/lib/daru/dataframe.rb +196 -48
- data/lib/daru/date_time/index.rb +7 -5
- data/lib/daru/formatters/table.rb +1 -0
- data/lib/daru/index/index.rb +121 -33
- data/lib/daru/index/multi_index.rb +83 -3
- data/lib/daru/io/csv/converters.rb +18 -0
- data/lib/daru/io/io.rb +80 -11
- data/lib/daru/io/sql_data_source.rb +10 -0
- data/lib/daru/iruby/templates/dataframe.html.erb +3 -50
- data/lib/daru/iruby/templates/dataframe_mi.html.erb +3 -56
- data/lib/daru/iruby/templates/dataframe_mi_tbody.html.erb +35 -0
- data/lib/daru/iruby/templates/dataframe_mi_thead.html.erb +21 -0
- data/lib/daru/iruby/templates/dataframe_tbody.html.erb +28 -0
- data/lib/daru/iruby/templates/dataframe_thead.html.erb +21 -0
- data/lib/daru/iruby/templates/vector.html.erb +3 -25
- data/lib/daru/iruby/templates/vector_mi.html.erb +3 -34
- data/lib/daru/iruby/templates/vector_mi_tbody.html.erb +26 -0
- data/lib/daru/iruby/templates/vector_mi_thead.html.erb +8 -0
- data/lib/daru/iruby/templates/vector_tbody.html.erb +17 -0
- data/lib/daru/iruby/templates/vector_thead.html.erb +8 -0
- data/lib/daru/maths/statistics/dataframe.rb +9 -11
- data/lib/daru/maths/statistics/vector.rb +139 -32
- data/lib/daru/plotting/gruff/dataframe.rb +13 -15
- data/lib/daru/plotting/nyaplot/category.rb +1 -1
- data/lib/daru/plotting/nyaplot/dataframe.rb +4 -4
- data/lib/daru/plotting/nyaplot/vector.rb +1 -2
- data/lib/daru/vector.rb +169 -80
- data/lib/daru/version.rb +1 -1
- data/spec/category_spec.rb +19 -19
- data/spec/core/group_by_spec.rb +47 -0
- data/spec/core/query_spec.rb +55 -50
- data/spec/daru_spec.rb +22 -0
- data/spec/dataframe_spec.rb +118 -6
- data/spec/date_time/index_spec.rb +34 -16
- data/spec/extensions/rserve_spec.rb +1 -1
- data/spec/fixtures/boolean_converter_test.csv +5 -0
- data/spec/fixtures/eciresults.html +394 -0
- data/spec/fixtures/empty_rows_test.csv +17 -0
- data/spec/fixtures/macau.html +3691 -0
- data/spec/fixtures/macd_data.csv +150 -0
- data/spec/fixtures/moneycontrol.html +6812 -0
- data/spec/fixtures/url_test.txt~ +0 -0
- data/spec/fixtures/valid_markup.html +62 -0
- data/spec/fixtures/wiki_climate.html +1243 -0
- data/spec/fixtures/wiki_table_info.html +631 -0
- data/spec/formatters/table_formatter_spec.rb +29 -0
- data/spec/index/categorical_index_spec.rb +33 -33
- data/spec/index/index_spec.rb +134 -41
- data/spec/index/multi_index_spec.rb +115 -31
- data/spec/io/io_spec.rb +201 -0
- data/spec/io/sql_data_source_spec.rb +31 -41
- data/spec/iruby/dataframe_spec.rb +17 -19
- data/spec/iruby/vector_spec.rb +26 -28
- data/spec/maths/statistics/vector_spec.rb +136 -14
- data/spec/plotting/gruff/category_spec.rb +3 -3
- data/spec/plotting/gruff/dataframe_spec.rb +14 -4
- data/spec/plotting/gruff/vector_spec.rb +9 -9
- data/spec/plotting/nyaplot/category_spec.rb +5 -9
- data/spec/plotting/nyaplot/dataframe_spec.rb +72 -47
- data/spec/plotting/nyaplot/vector_spec.rb +5 -11
- data/spec/shared/vector_display_spec.rb +12 -14
- data/spec/spec_helper.rb +21 -0
- data/spec/support/matchers.rb +5 -0
- data/spec/vector_spec.rb +222 -72
- metadata +68 -23
- data/spec/fixtures/stock_data.csv +0 -500
@@ -10,7 +10,7 @@ describe Daru::Vector, 'plotting category vector with gruff' do
|
|
10
10
|
expect(plot).to receive :data
|
11
11
|
dv.plot type: :bar
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
it 'plots bar graph with block' do
|
15
15
|
expect(plot).to receive :labels=
|
16
16
|
expect(plot).to receive :data
|
@@ -18,7 +18,7 @@ describe Daru::Vector, 'plotting category vector with gruff' do
|
|
18
18
|
dv.plot(type: :bar) { |p| p.title = 'hello' }
|
19
19
|
end
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
context 'pie' do
|
23
23
|
let(:plot) { instance_double 'Gruff::Pie' }
|
24
24
|
before { allow(Gruff::Pie).to receive(:new).and_return(plot) }
|
@@ -27,7 +27,7 @@ describe Daru::Vector, 'plotting category vector with gruff' do
|
|
27
27
|
dv.plot type: :pie
|
28
28
|
end
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
context 'sidebar' do
|
32
32
|
let(:plot) { instance_double 'Gruff::SideBar' }
|
33
33
|
before { allow(Gruff::SideBar).to receive(:new).and_return(plot) }
|
@@ -18,7 +18,7 @@ describe Daru::DataFrame, 'plotting dataframe using gruff' do
|
|
18
18
|
expect(plot).to receive(:data).exactly(3).times
|
19
19
|
df.plot type: :bar
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
it 'plots bar graph with block' do
|
23
23
|
expect(plot).to receive :labels=
|
24
24
|
expect(plot).to receive(:data).exactly(3).times
|
@@ -56,7 +56,7 @@ describe Daru::DataFrame, 'plotting dataframe using gruff' do
|
|
56
56
|
df.plot type: :scatter, x: :c, y: :a
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
context 'invalid type' do
|
61
61
|
it { expect { df.plot type: :lol }.to raise_error ArgumentError }
|
62
62
|
end
|
@@ -72,13 +72,23 @@ describe Daru::DataFrame, 'dataframe category plotting with gruff' do
|
|
72
72
|
}, index: 'a'..'f')
|
73
73
|
end
|
74
74
|
before { df.to_category :c }
|
75
|
-
|
75
|
+
|
76
76
|
context 'scatter' do
|
77
77
|
let(:plot) { instance_double 'Gruff::Scatter' }
|
78
|
-
before { allow(Gruff::Scatter).to receive(:new).and_return(plot) }
|
78
|
+
before { allow(Gruff::Scatter).to receive(:new).and_return(plot) }
|
79
79
|
it 'plots scatter plot categorized by category vector' do
|
80
80
|
expect(plot).to receive(:data).exactly(2).times
|
81
81
|
df.plot type: :scatter, x: :a, y: :b, categorized: { by: :c }
|
82
82
|
end
|
83
|
+
|
84
|
+
it 'plots with axes description' do
|
85
|
+
expect(plot).to receive(:data).exactly(2).times
|
86
|
+
expect(plot).to receive(:x_axis_label=).exactly(1).times
|
87
|
+
expect(plot).to receive(:y_axis_label=).exactly(1).times
|
88
|
+
df.plot type: :scatter, x: :a, y: :b, categorized: { by: :c } do |gruff_plot|
|
89
|
+
gruff_plot.x_axis_label = 'A data'
|
90
|
+
gruff_plot.y_axis_label = 'B data'
|
91
|
+
end
|
92
|
+
end
|
83
93
|
end
|
84
94
|
end
|
@@ -7,13 +7,13 @@ describe Daru::Vector, 'plotting vector with gruff' do
|
|
7
7
|
context 'line' do
|
8
8
|
let(:plot) { instance_double 'Gruff::Line' }
|
9
9
|
before { allow(Gruff::Line).to receive(:new).and_return(plot) }
|
10
|
-
|
10
|
+
|
11
11
|
it 'plots line graph without block' do
|
12
12
|
expect(plot).to receive(:labels=)
|
13
13
|
expect(plot).to receive(:data)
|
14
14
|
dv.plot type: :line
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it 'plots line graph with block' do
|
18
18
|
expect(plot).to receive :labels=
|
19
19
|
expect(plot).to receive :data
|
@@ -21,28 +21,28 @@ describe Daru::Vector, 'plotting vector with gruff' do
|
|
21
21
|
dv.plot(type: :line) { |p| p.title = 'hello' }
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
context 'bar' do
|
26
26
|
let(:plot) { instance_double 'Gruff::Bar' }
|
27
27
|
before { allow(Gruff::Bar).to receive(:new).and_return(plot) }
|
28
|
-
|
28
|
+
|
29
29
|
it 'plots bar graph' do
|
30
30
|
expect(plot).to receive :labels=
|
31
31
|
expect(plot).to receive :data
|
32
32
|
dv.plot type: :bar
|
33
33
|
end
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
context 'pie' do
|
37
37
|
let(:plot) { instance_double 'Gruff::Pie' }
|
38
38
|
before { allow(Gruff::Pie).to receive(:new).and_return(plot) }
|
39
|
-
|
39
|
+
|
40
40
|
it 'plots pie graph' do
|
41
41
|
expect(plot).to receive(:data).exactly(3).times
|
42
42
|
dv.plot type: :pie
|
43
43
|
end
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
context 'scatter' do
|
47
47
|
let(:plot) { instance_double 'Gruff::Scatter' }
|
48
48
|
before { allow(Gruff::Scatter).to receive(:new).and_return(plot) }
|
@@ -52,7 +52,7 @@ describe Daru::Vector, 'plotting vector with gruff' do
|
|
52
52
|
dv.plot type: :scatter
|
53
53
|
end
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
context 'sidebar' do
|
57
57
|
let(:plot) { instance_double 'Gruff::SideBar' }
|
58
58
|
before { allow(Gruff::SideBar).to receive(:new).and_return(plot) }
|
@@ -63,7 +63,7 @@ describe Daru::Vector, 'plotting vector with gruff' do
|
|
63
63
|
dv.plot type: :sidebar
|
64
64
|
end
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
context 'invalid type' do
|
68
68
|
it { expect { dv.plot type: :lol }.to raise_error ArgumentError }
|
69
69
|
end
|
@@ -7,7 +7,7 @@ describe Daru::Vector, 'plotting category' do
|
|
7
7
|
Daru::Vector.new ['III']*10 + ['II']*5 + ['I']*5,
|
8
8
|
type: :category,
|
9
9
|
categories: ['I', 'II', 'III']
|
10
|
-
end
|
10
|
+
end
|
11
11
|
before do
|
12
12
|
Daru.plotting_library = :nyaplot
|
13
13
|
allow(Nyaplot::Plot).to receive(:new).and_return(plot)
|
@@ -17,7 +17,6 @@ describe Daru::Vector, 'plotting category' do
|
|
17
17
|
expect(plot).to receive(:add).with(:bar, ['I', 'II', 'III'], [5, 5, 10])
|
18
18
|
expect(plot).to receive :x_label
|
19
19
|
expect(plot).to receive :y_label
|
20
|
-
expect(plot).to receive(:show)
|
21
20
|
dv.plot(type: :bar) do |p|
|
22
21
|
p.x_label 'Categories'
|
23
22
|
p.y_label 'Frequency'
|
@@ -26,23 +25,20 @@ describe Daru::Vector, 'plotting category' do
|
|
26
25
|
|
27
26
|
it 'plots bar graph without taking a block' do
|
28
27
|
expect(plot).to receive(:add).with(:bar, ["I", "II", "III"], [5, 5, 10])
|
29
|
-
expect(plot).to
|
30
|
-
dv.plot(type: :bar)
|
28
|
+
expect(dv.plot(type: :bar)).to eq plot
|
31
29
|
end
|
32
30
|
|
33
31
|
it 'plots bar graph with percentage' do
|
34
32
|
expect(plot).to receive(:add).with(:bar, ["I", "II", "III"], [25, 25, 50])
|
35
33
|
expect(plot).to receive(:yrange).with [0, 100]
|
36
|
-
expect(plot).to
|
37
|
-
dv.plot(type: :bar, method: :percentage)
|
34
|
+
expect(dv.plot(type: :bar, method: :percentage)).to eq plot
|
38
35
|
end
|
39
36
|
|
40
37
|
it 'plots bar graph with fraction' do
|
41
38
|
expect(plot).to receive(:add).with(:bar, ["I", "II", "III"], [0.25, 0.25, 0.50])
|
42
39
|
expect(plot).to receive(:yrange).with [0, 1]
|
43
|
-
expect(plot).to
|
44
|
-
|
45
|
-
end
|
40
|
+
expect(dv.plot(type: :bar, method: :fraction)).to eq plot
|
41
|
+
end
|
46
42
|
end
|
47
43
|
|
48
44
|
context 'other type' do
|
@@ -35,8 +35,7 @@ describe Daru::DataFrame, 'plotting' do
|
|
35
35
|
.with(numerics.to_nyaplotdf, :box, :x, :y1, :y2)
|
36
36
|
.ordered
|
37
37
|
|
38
|
-
expect(plot).to
|
39
|
-
data_frame.plot(type: :box)
|
38
|
+
expect(data_frame.plot(type: :box)).to eq plot
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
@@ -47,8 +46,7 @@ describe Daru::DataFrame, 'plotting' do
|
|
47
46
|
.with(data_frame.to_nyaplotdf, :scatter, :x, :y1)
|
48
47
|
.ordered
|
49
48
|
|
50
|
-
expect(plot).to
|
51
|
-
data_frame.plot(type: :scatter, x: :x, y: :y1)
|
49
|
+
expect(data_frame.plot(type: :scatter, x: :x, y: :y1)).to eq plot
|
52
50
|
end
|
53
51
|
|
54
52
|
it 'works without :y provided' do
|
@@ -56,8 +54,7 @@ describe Daru::DataFrame, 'plotting' do
|
|
56
54
|
.with(data_frame.to_nyaplotdf, :scatter, :x)
|
57
55
|
.ordered
|
58
56
|
|
59
|
-
expect(plot).to
|
60
|
-
data_frame.plot(type: :scatter, x: :x)
|
57
|
+
expect(data_frame.plot(type: :scatter, x: :x)).to eq plot
|
61
58
|
end
|
62
59
|
end
|
63
60
|
|
@@ -69,9 +66,10 @@ describe Daru::DataFrame, 'plotting' do
|
|
69
66
|
expect(plot).to receive(:add_with_df)
|
70
67
|
.with(data_frame.to_nyaplotdf, :scatter, :x, :y2)
|
71
68
|
.ordered
|
72
|
-
expect(plot).to receive(:show).ordered
|
73
69
|
|
74
|
-
|
70
|
+
expect(
|
71
|
+
data_frame.plot(type: :scatter, x: [:x, :x], y: [:y1, :y2])
|
72
|
+
).to eq plot
|
75
73
|
end
|
76
74
|
|
77
75
|
it 'works with multiple types provided' do
|
@@ -81,9 +79,11 @@ describe Daru::DataFrame, 'plotting' do
|
|
81
79
|
expect(plot).to receive(:add_with_df)
|
82
80
|
.with(data_frame.to_nyaplotdf, :line, :x, :y2)
|
83
81
|
.ordered
|
84
|
-
expect(plot).to receive(:show).ordered
|
85
82
|
|
86
|
-
|
83
|
+
expect(
|
84
|
+
data_frame.plot(
|
85
|
+
type: [:scatter, :line], x: [:x, :x], y: [:y1, :y2])
|
86
|
+
).to eq plot
|
87
87
|
end
|
88
88
|
|
89
89
|
it 'works with numeric var names' do
|
@@ -93,9 +93,9 @@ describe Daru::DataFrame, 'plotting' do
|
|
93
93
|
expect(plot).to receive(:add_with_df)
|
94
94
|
.with(data_frame.to_nyaplotdf, :line, :x, :y2)
|
95
95
|
.ordered
|
96
|
-
expect(plot).to receive(:show).ordered
|
97
96
|
|
98
|
-
|
97
|
+
expect(
|
98
|
+
data_frame.plot(
|
99
99
|
type: [:scatter, :line],
|
100
100
|
# FIXME: this didn't work due to default type: :scatter opts
|
101
101
|
#type1: :scatter,
|
@@ -104,7 +104,8 @@ describe Daru::DataFrame, 'plotting' do
|
|
104
104
|
x2: :x,
|
105
105
|
y1: :y1,
|
106
106
|
y2: :y2
|
107
|
-
|
107
|
+
)
|
108
|
+
).to eq plot
|
108
109
|
end
|
109
110
|
end
|
110
111
|
end
|
@@ -121,13 +122,13 @@ describe Daru::DataFrame, 'category plotting' do
|
|
121
122
|
end
|
122
123
|
let(:plot) { instance_double('Nyaplot::Plot') }
|
123
124
|
let(:diagram) { instance_double('Nyaplot::Diagram::Scatter') }
|
124
|
-
|
125
|
+
|
125
126
|
before do
|
126
127
|
df.to_category :c
|
127
128
|
allow(Nyaplot::Plot).to receive(:new).and_return(plot)
|
128
129
|
allow(plot).to receive(:add_with_df).and_return(diagram)
|
129
130
|
end
|
130
|
-
|
131
|
+
|
131
132
|
it 'plots scatter plot categoried by color with a block' do
|
132
133
|
expect(plot).to receive :add_with_df
|
133
134
|
expect(diagram).to receive(:title).exactly(3).times
|
@@ -136,7 +137,6 @@ describe Daru::DataFrame, 'category plotting' do
|
|
136
137
|
expect(plot).to receive :legend
|
137
138
|
expect(plot).to receive :xrange
|
138
139
|
expect(plot).to receive :yrange
|
139
|
-
expect(plot).to receive :show
|
140
140
|
df.plot(type: :scatter, x: :a, y: :b, categorized: {by: :c, method: :color}) do |p, d|
|
141
141
|
p.xrange [-10, 10]
|
142
142
|
p.yrange [-10, 10]
|
@@ -149,9 +149,11 @@ describe Daru::DataFrame, 'category plotting' do
|
|
149
149
|
expect(diagram).to receive(:color).exactly(3).times
|
150
150
|
expect(diagram).to receive(:tooltip_contents).exactly(3).times
|
151
151
|
expect(plot).to receive :legend
|
152
|
-
expect(
|
153
|
-
|
154
|
-
|
152
|
+
expect(
|
153
|
+
df.plot(
|
154
|
+
type: :scatter, x: :a, y: :b,
|
155
|
+
categorized: {by: :c, method: :color})
|
156
|
+
).to eq plot
|
155
157
|
end
|
156
158
|
|
157
159
|
it 'plots scatter plot categoried by custom colors' do
|
@@ -162,9 +164,8 @@ describe Daru::DataFrame, 'category plotting' do
|
|
162
164
|
expect(diagram).to receive(:color).with :green
|
163
165
|
expect(diagram).to receive(:tooltip_contents).exactly(3).times
|
164
166
|
expect(plot).to receive :legend
|
165
|
-
expect(plot
|
166
|
-
|
167
|
-
categorized: {by: :c, method: :color, color: [:red, :blue, :green]})
|
167
|
+
expect(df.plot(type: :scatter, x: :a, y: :b,
|
168
|
+
categorized: {by: :c, method: :color, color: [:red, :blue, :green]})).to eq plot
|
168
169
|
end
|
169
170
|
|
170
171
|
it 'plots scatter plot categoried by shape' do
|
@@ -173,9 +174,8 @@ describe Daru::DataFrame, 'category plotting' do
|
|
173
174
|
expect(diagram).to receive(:shape).exactly(3).times
|
174
175
|
expect(diagram).to receive(:tooltip_contents).exactly(3).times
|
175
176
|
expect(plot).to receive :legend
|
176
|
-
expect(plot
|
177
|
-
|
178
|
-
categorized: {by: :c, method: :shape})
|
177
|
+
expect(df.plot(type: :scatter, x: :a, y: :b,
|
178
|
+
categorized: {by: :c, method: :shape})).to eq plot
|
179
179
|
end
|
180
180
|
|
181
181
|
it 'plots scatter plot categoried by custom shapes' do
|
@@ -186,9 +186,13 @@ describe Daru::DataFrame, 'category plotting' do
|
|
186
186
|
expect(diagram).to receive(:shape).with 'diamond'
|
187
187
|
expect(diagram).to receive(:tooltip_contents).exactly(3).times
|
188
188
|
expect(plot).to receive :legend
|
189
|
-
expect(
|
190
|
-
|
191
|
-
|
189
|
+
expect(
|
190
|
+
df.plot(
|
191
|
+
type: :scatter, x: :a, y: :b,
|
192
|
+
categorized: {
|
193
|
+
by: :c, method: :shape,
|
194
|
+
shape: %w(circle triangle-up diamond)})
|
195
|
+
).to eq plot
|
192
196
|
end
|
193
197
|
|
194
198
|
it 'plots scatter plot categoried by size' do
|
@@ -197,9 +201,8 @@ describe Daru::DataFrame, 'category plotting' do
|
|
197
201
|
expect(diagram).to receive(:size).exactly(3).times
|
198
202
|
expect(diagram).to receive(:tooltip_contents).exactly(3).times
|
199
203
|
expect(plot).to receive :legend
|
200
|
-
expect(plot
|
201
|
-
|
202
|
-
categorized: {by: :c, method: :size})
|
204
|
+
expect(df.plot(type: :scatter, x: :a, y: :b,
|
205
|
+
categorized: {by: :c, method: :size})).to eq plot
|
203
206
|
end
|
204
207
|
|
205
208
|
it 'plots scatter plot categoried by cusom sizes' do
|
@@ -210,9 +213,17 @@ describe Daru::DataFrame, 'category plotting' do
|
|
210
213
|
expect(diagram).to receive(:size).with 300
|
211
214
|
expect(diagram).to receive(:tooltip_contents).exactly(3).times
|
212
215
|
expect(plot).to receive :legend
|
213
|
-
expect(
|
214
|
-
|
215
|
-
|
216
|
+
expect(
|
217
|
+
df.plot(
|
218
|
+
type: :scatter,
|
219
|
+
x: :a, y: :b,
|
220
|
+
categorized: {
|
221
|
+
by: :c,
|
222
|
+
method: :size,
|
223
|
+
size: [100, 200, 300]
|
224
|
+
}
|
225
|
+
)
|
226
|
+
).to eq plot
|
216
227
|
end
|
217
228
|
end
|
218
229
|
|
@@ -226,13 +237,13 @@ describe Daru::DataFrame, 'category plotting' do
|
|
226
237
|
end
|
227
238
|
let(:plot) { instance_double('Nyaplot::Plot') }
|
228
239
|
let(:diagram) { instance_double('Nyaplot::Diagram::Scatter') }
|
229
|
-
|
240
|
+
|
230
241
|
before do
|
231
242
|
df.to_category :c
|
232
243
|
allow(Nyaplot::Plot).to receive(:new).and_return(plot)
|
233
244
|
allow(plot).to receive(:add_with_df).and_return(diagram)
|
234
245
|
end
|
235
|
-
|
246
|
+
|
236
247
|
it 'plots line plot categoried by color with a block' do
|
237
248
|
expect(plot).to receive :add_with_df
|
238
249
|
expect(diagram).to receive(:title).exactly(3).times
|
@@ -240,7 +251,6 @@ describe Daru::DataFrame, 'category plotting' do
|
|
240
251
|
expect(plot).to receive :legend
|
241
252
|
expect(plot).to receive :xrange
|
242
253
|
expect(plot).to receive :yrange
|
243
|
-
expect(plot).to receive :show
|
244
254
|
df.plot(type: :line, x: :a, y: :b, categorized: {by: :c, method: :color}) do |p, d|
|
245
255
|
p.xrange [-10, 10]
|
246
256
|
p.yrange [-10, 10]
|
@@ -252,8 +262,12 @@ describe Daru::DataFrame, 'category plotting' do
|
|
252
262
|
expect(diagram).to receive(:title).exactly(3).times
|
253
263
|
expect(diagram).to receive(:color).exactly(3).times
|
254
264
|
expect(plot).to receive :legend
|
255
|
-
expect(
|
256
|
-
|
265
|
+
expect(
|
266
|
+
df.plot(
|
267
|
+
type: :line, x: :a, y: :b,
|
268
|
+
categorized: {by: :c, method: :color}
|
269
|
+
)
|
270
|
+
).to eq plot
|
257
271
|
end
|
258
272
|
|
259
273
|
it 'plots line plot categoried by custom colors' do
|
@@ -263,9 +277,12 @@ describe Daru::DataFrame, 'category plotting' do
|
|
263
277
|
expect(diagram).to receive(:color).with :blue
|
264
278
|
expect(diagram).to receive(:color).with :green
|
265
279
|
expect(plot).to receive :legend
|
266
|
-
expect(
|
267
|
-
|
268
|
-
|
280
|
+
expect(
|
281
|
+
df.plot(
|
282
|
+
type: :line, x: :a, y: :b,
|
283
|
+
categorized: {by: :c, method: :color, color: [:red, :blue, :green]}
|
284
|
+
)
|
285
|
+
).to eq plot
|
269
286
|
end
|
270
287
|
|
271
288
|
it 'plots line plot categoried by stroke width' do
|
@@ -273,8 +290,12 @@ describe Daru::DataFrame, 'category plotting' do
|
|
273
290
|
expect(diagram).to receive(:title).exactly(3).times
|
274
291
|
expect(diagram).to receive(:stroke_width).exactly(3).times
|
275
292
|
expect(plot).to receive :legend
|
276
|
-
expect(
|
277
|
-
|
293
|
+
expect(
|
294
|
+
df.plot(
|
295
|
+
type: :line, x: :a, y: :b,
|
296
|
+
categorized: {by: :c, method: :stroke_width}
|
297
|
+
)
|
298
|
+
).to eq plot
|
278
299
|
end
|
279
300
|
|
280
301
|
it 'plots line plot categoried by custom stroke widths' do
|
@@ -284,9 +305,13 @@ describe Daru::DataFrame, 'category plotting' do
|
|
284
305
|
expect(diagram).to receive(:stroke_width).with 200
|
285
306
|
expect(diagram).to receive(:stroke_width).with 300
|
286
307
|
expect(plot).to receive :legend
|
287
|
-
expect(
|
288
|
-
|
289
|
-
|
308
|
+
expect(
|
309
|
+
df.plot(
|
310
|
+
type: :line, x: :a, y: :b,
|
311
|
+
categorized: {
|
312
|
+
by: :c, method: :stroke_width, stroke_width: [100, 200, 300]}
|
313
|
+
)
|
314
|
+
).to eq plot
|
290
315
|
end
|
291
316
|
end
|
292
317
|
|