technical_graph 0.5.1 → 0.6.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.
data/test/helper.rb DELETED
@@ -1,23 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'test/unit'
11
- require 'shoulda'
12
- require 'rspec'
13
-
14
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
15
- $LOAD_PATH.unshift(File.dirname(__FILE__))
16
- require 'technical_graph'
17
-
18
- # default drawer class
19
- #DRAWER_CLASS = :rmagick
20
- DRAWER_CLASS = :rasem
21
-
22
- class Test::Unit::TestCase
23
- end
@@ -1,92 +0,0 @@
1
- require 'helper'
2
-
3
- class TestTechnicalAutocolor < Test::Unit::TestCase
4
- context 'initial options' do
5
- should 'draw multilayer graph' do
6
- @tg = TechnicalGraph.new(
7
- {
8
- :truncate_string => "%.1f",
9
-
10
- :x_axis_label => 'x',
11
- :y_axis_label => 'y',
12
-
13
- :axis_antialias => true,
14
- :layers_antialias => true,
15
- :font_antialias => true,
16
-
17
- :layers_font_size => 11,
18
- :axis_font_size => 11,
19
- :axis_label_font_size => 20,
20
-
21
- #:x_axis_count => 20,
22
- #:y_axis_count => 20,
23
- #:x_axis_interval => 1.0,
24
- #:y_axis_interval => 1.0,
25
- #:x_axis_fixed_interval => false,
26
- #:y_axis_fixed_interval => false,
27
-
28
- #:x_min => -10.0,
29
- #:x_max => 10.0,
30
- #:y_min => -10.0,
31
- #:y_max => 10.0,
32
-
33
- #:width => 4000,
34
- #:height => 3000,
35
-
36
- :legend => true,
37
- :legend_auto => true,
38
- :legend_width => 90,
39
- :legend_margin => 60,
40
- :legend_x => 50,
41
- :legend_y => 50,
42
- }
43
- )
44
-
45
- max = 50
46
-
47
- # adding simple layer
48
- layer_params_a = {
49
- :antialias => true,
50
- :label => 'first'
51
- }
52
- layer_params_b = {
53
- :antialias => true,
54
- :label => 'second'
55
- }
56
- layer_params_c = {
57
- :antialias => true,
58
- :label => 'third'
59
- }
60
- layer_params_d = {
61
- :antialias => true,
62
- :label => 'fourth'
63
- }
64
- layer_data_a = Array.new
65
- layer_data_b = Array.new
66
- layer_data_c = Array.new
67
- layer_data_d = Array.new
68
- (0..max).each do |i|
69
- layer_data_a << { :x => -10.0 + i.to_f, :y => 10.0 * Math.cos(i.to_f * (4.0 * 3.14 / max.to_f)) }
70
- layer_data_b << { :x => -10.0 + i.to_f, :y => 10.0 * Math.cos(0.3 + i.to_f * (4.0 * 3.14 / max.to_f)) }
71
- layer_data_c << { :x => -10.0 + i.to_f, :y => 10.0 * Math.cos(0.6 + i.to_f * (4.0 * 3.14 / max.to_f)) }
72
- layer_data_d << { :x => -10.0 + i.to_f, :y => 10.0 * Math.cos(0.9 + i.to_f * (4.0 * 3.14 / max.to_f)) }
73
- end
74
- @tg.add_layer(layer_data_a, layer_params_a)
75
- @tg.add_layer(layer_data_b, layer_params_b)
76
- @tg.add_layer(layer_data_c, layer_params_c)
77
- @tg.add_layer(layer_data_d, layer_params_d)
78
-
79
-
80
- @tg.layers.last.raw_data.size.should > 0
81
- @tg.layers.last.processed_data.size.should > 0
82
- @tg.layers.size.should == 4
83
-
84
- @tg.render
85
-
86
- @tg.image_drawer.save_to_file("samples/tests/test_autocolor.#{@tg.best_output_format}")
87
- @tg.image_drawer.to_format(@tg.best_output_format).class.should == String
88
-
89
- end
90
- end
91
-
92
- end
@@ -1,68 +0,0 @@
1
- require 'helper'
2
-
3
- class TestTechnicalAxisEnlarge < Test::Unit::TestCase
4
- context 'initial options' do
5
- should 'enlarge image' do
6
- @tg = TechnicalGraph.new(
7
- {
8
- :truncate_string => "%.1f",
9
-
10
- :x_axis_label => 'x',
11
- :y_axis_label => 'y',
12
-
13
- :axis_antialias => true,
14
- :layers_antialias => true,
15
- :font_antialias => true,
16
-
17
- :layers_font_size => 8,
18
- :axis_font_size => 8,
19
- :axis_label_font_size => 20,
20
-
21
- :x_axis_count => 50,
22
- :y_axis_count => 50,
23
- #:x_axis_interval => 1.0,
24
- #:y_axis_interval => 1.0,
25
- :x_axis_fixed_interval => false,
26
- :y_axis_fixed_interval => false,
27
-
28
- #:x_min => -10.0,
29
- #:x_max => 10.0,
30
- #:y_min => -10.0,
31
- #:y_max => 10.0,
32
-
33
- :width => 800,
34
- :height => 600,
35
-
36
- :axis_density_enlarge_image => true,
37
- :x_axis_min_distance => 50,
38
- :y_axis_min_distance => 50,
39
- }
40
- )
41
-
42
- max = 50
43
-
44
- # adding simple layer
45
- layer_params = {
46
- :antialias => false,
47
- #:color => 'red'
48
- :color => '#FFFF00'
49
- }
50
- layer_data = Array.new
51
- (0..max).each do |i|
52
- layer_data << { :x => -10.0 + i.to_f, :y => 10.0 * Math.cos(i.to_f * (4.0 * 3.14 / max.to_f)) }
53
- end
54
- @tg.add_layer(layer_data, layer_params)
55
- # should be added
56
- @tg.layers.last.raw_data.size.should > 0
57
- @tg.layers.last.processed_data.size.should > 0
58
- # checking ranger for layer
59
-
60
- @tg.render
61
-
62
- @tg.image_drawer.save_to_file("samples/tests/test_axis_enlarge.#{@tg.best_output_format}")
63
- @tg.image_drawer.to_format(@tg.best_output_format).class.should == String
64
-
65
- end
66
- end
67
-
68
- end
@@ -1,64 +0,0 @@
1
- require 'helper'
2
-
3
- class TestTechnicalFix1 < Test::Unit::TestCase
4
- context 'y_min = y_max' do
5
- should 'draw graph without error - NaN' do
6
- @tg = TechnicalGraph.new(
7
- {
8
- # code from HomeIO
9
- :x_axis_label => 'label',
10
- :y_axis_label => 'value',
11
-
12
- :x_axis_interval => 1.0,
13
- :y_axis_count => 10,
14
- :x_axis_fixed_interval => true,
15
- :y_axis_fixed_interval => false,
16
- :width => 800,
17
- :height => 600,
18
-
19
- :axis_antialias => false,
20
- :layers_font_size => 10,
21
- :axis_font_size => 10,
22
- :axis_label_font_size => 24,
23
-
24
- :x_min => -10.0,
25
- :x_max => 40.0,
26
- :y_max => 10.0,
27
- :y_min => 10.0
28
- }
29
- )
30
-
31
- max = 50
32
- layer_data_a = Array.new
33
- (0..max).each do |i|
34
- layer_data_a << { :x => -10.0 + i.to_f, :y => 10.0 }
35
- end
36
- @tg.add_layer(layer_data_a)
37
- @tg.render
38
- @tg.image_drawer.to_format(@tg.best_output_format).class.should == String
39
-
40
- end
41
-
42
- should 'draw graph without another error' do
43
- @tg = TechnicalGraph.new(
44
- {
45
- :x_min => -10.0,
46
- :x_max => 40.0,
47
- :y_max => 10.0,
48
- :y_min => 10.0
49
- }
50
- )
51
-
52
- max = 50
53
- layer_data_a = Array.new
54
- (0..max).each do |i|
55
- layer_data_a << { :x => -10.0 + i.to_f, :y => 10.0 }
56
- end
57
- @tg.add_layer(layer_data_a)
58
- @tg.render
59
- @tg.image_drawer.to_format(@tg.best_output_format).class.should == String
60
-
61
- end
62
- end
63
-
64
- end
@@ -1,115 +0,0 @@
1
- require 'helper'
2
-
3
- class TestTechnicalGraph < Test::Unit::TestCase
4
- context 'initial options' do
5
- setup do
6
- @technical_graph = TechnicalGraph.new
7
- end
8
-
9
- should "has options with default values" do
10
- @technical_graph.options.class.should == Hash
11
- @technical_graph.options[:width] > 0
12
- @technical_graph.options[:height] > 0
13
- end
14
-
15
- should "has options with custom values" do
16
- s = 10
17
- tg = TechnicalGraph.new({ :height => s, :width => s })
18
- @technical_graph.options[:width] == s
19
- @technical_graph.options[:height] == s
20
-
21
- @technical_graph.image_drawer.width == s
22
- @technical_graph.image_drawer.height == s
23
- end
24
-
25
- should "has changeable options" do
26
- s = 20
27
- tg = TechnicalGraph.new
28
- tg.image_drawer.width = s
29
- tg.image_drawer.height = s
30
- @technical_graph.options[:width] == s
31
- @technical_graph.options[:height] == s
32
- end
33
- end
34
-
35
- context 'basic layer operation and saving file' do
36
- setup do
37
- @tg = TechnicalGraph.new
38
- @data_size = 100
39
-
40
- # sample data
41
- @data = Array.new
42
- @second_data = Array.new
43
- (0...@data_size).each do |i|
44
- @data << { :x => Time.now.to_i - 3600 + i, :y => Math.sin(i.to_f / 10.0) }
45
- @second_data << { :x => Time.now.to_i - 1800 + i*2, :y => Math.cos(i.to_f / 10.0) }
46
- end
47
- end
48
-
49
- should 'has ability do add new layer' do
50
- layers = @tg.layers.size
51
- @tg.add_layer(@data)
52
- @tg.layers.size.should == layers + 1
53
-
54
- layer = @tg.layers.last
55
- layer.raw_data.size.should == @data_size
56
- layer.processed_data.size.should == @data_size
57
- end
58
-
59
- should 'has ability to manipulate layers, add more data' do
60
- @tg.add_layer(@data)
61
- layer = @tg.layers.last
62
- layer.class.should == DataLayer
63
-
64
- layer.raw_data.size.should == @data_size
65
- layer.processed_data.size.should == @data_size
66
-
67
- # adding second data
68
- layer.append_data(@second_data)
69
- layer.raw_data.size.should == 2 * @data_size
70
- layer.processed_data.size.should == 2 * @data_size
71
-
72
- # @tg.render
73
- # @tg.image.save_to_file("samples/tests/test1.#{@th.best_output_format}")
74
- end
75
-
76
- should 'has ability to filter records with similar x\'es' do
77
- # was turned off by default, performance issue
78
- @tg.add_layer([], {:perform_parameter_uniq => true})
79
- layer = @tg.layers.last
80
- layer.raw_data.size.should == 0
81
- layer.processed_data.size.should == 0
82
- layer.append_data([{ :x => 0, :y => 1 }])
83
- layer.raw_data.size.should == 1
84
- layer.processed_data.size.should == 1
85
-
86
- # uniq check
87
- layer.append_data([{ :x => 0, :y => 1 }])
88
- layer.append_data([{ :x => 0, :y => 1 }])
89
- layer.raw_data.size.should == 1
90
- layer.processed_data.size.should == 1
91
- layer.append_data([{ :x => 2, :y => 1 }])
92
- layer.raw_data.size.should == 2
93
- layer.processed_data.size.should == 2
94
- end
95
-
96
- should 'has ability to filter bad records' do
97
- @tg.add_layer
98
- layer = @tg.layers.last
99
- layer.raw_data.size.should == 0
100
- layer.processed_data.size.should == 0
101
- layer.append_data([{ :x => 0, :y => 1 }])
102
- layer.raw_data.size.should == 1
103
- layer.processed_data.size.should == 1
104
-
105
- # uniq check
106
- layer.append_data([{ :z => 0, :y => 1 }])
107
- layer.append_data([{ }])
108
- layer.raw_data.size.should == 1
109
- layer.processed_data.size.should == 1
110
- end
111
-
112
- end
113
-
114
-
115
- end
@@ -1,314 +0,0 @@
1
- require 'helper'
2
-
3
- class TestTechnicalGraphAxis < Test::Unit::TestCase
4
- context 'ranges calculation' do
5
- setup do
6
- end
7
-
8
- should 'provide defined ranges' do
9
- x_min = 0.0
10
- x_max = 10.0
11
- y_min = -5.0
12
- y_max = 5.0
13
-
14
- @tg = TechnicalGraph.new(
15
- {
16
- :x_min => x_min,
17
- :x_max => x_max,
18
- :y_min => y_min,
19
- :y_max => y_max,
20
- :xy_behaviour => :fixed
21
- }
22
- )
23
- @tg.render
24
-
25
- @tg.data_processor.x_min.should == x_min
26
- @tg.data_processor.x_max.should == x_max
27
- @tg.data_processor.y_min.should == y_min
28
- @tg.data_processor.y_max.should == y_max
29
- end
30
-
31
- should 'calculate ranges per layer' do
32
- # adding simple layer
33
- layer_data = [
34
- { :x => -1, :y => 3.0 },
35
- { :x => 3, :y => -8.0 },
36
- { :x => 0, :y => 3.0 },
37
- { :x => 10, :y => 10.0 }
38
- ]
39
- dl = DataLayer.new(layer_data)
40
-
41
- dl.x_min.should == -1
42
- dl.x_max.should == 10
43
- dl.y_min.should == -8.0
44
- dl.y_max.should == 10.0
45
- end
46
-
47
-
48
- should 'provide ranges calculated using data layer, and multiple layers' do
49
- x_min = 0.0
50
- x_max = 1.0
51
- y_min = -1.0
52
- y_max = 1.0
53
-
54
- @tg = TechnicalGraph.new(
55
- {
56
- :x_min => x_min,
57
- :x_max => x_max,
58
- :y_min => y_min,
59
- :y_max => y_max,
60
- :xy_behaviour => :default
61
- }
62
- )
63
-
64
- # adding simple layer
65
- layer_data = [
66
- { :x => -1, :y => 3.0 },
67
- { :x => 3, :y => -8.0 },
68
- { :x => 0, :y => 3.0 },
69
- { :x => 10, :y => 10.0 }
70
- ]
71
- @tg.add_layer(layer_data)
72
- # should be added
73
- @tg.layers.last.raw_data.size > 0
74
- @tg.layers.last.processed_data.size > 0
75
- # checking ranger for layer
76
-
77
- @tg.render
78
-
79
-
80
- @tg.data_processor.x_min.should_not == x_min
81
- @tg.data_processor.x_max.should_not == x_max
82
- @tg.data_processor.y_min.should_not == y_min
83
- @tg.data_processor.y_max.should_not == y_max
84
-
85
- @tg.data_processor.x_min.should == -1
86
- @tg.data_processor.x_max.should == 10
87
- @tg.data_processor.y_min.should == -8.0
88
- @tg.data_processor.y_max.should == 10.0
89
-
90
-
91
-
92
- # adding another layer
93
-
94
- # adding simple layer
95
- layer_data = [
96
- { :x => -21, :y => -93.0 },
97
- { :x => -5, :y => 3.0 },
98
- { :x => 39, :y => -8.0 },
99
- { :x => 0, :y => 333.0 },
100
- { :x => 10, :y => 50.0 }
101
- ]
102
- @tg.add_layer(layer_data)
103
- # should be added
104
- @tg.layers.last.raw_data.size > 1
105
- @tg.layers.last.processed_data.size > 1
106
-
107
- @tg.render
108
-
109
- @tg.data_processor.x_min.should_not == x_min
110
- @tg.data_processor.x_max.should_not == x_max
111
- @tg.data_processor.y_min.should_not == y_min
112
- @tg.data_processor.y_max.should_not == y_max
113
-
114
- @tg.data_processor.x_min.should_not == -1.0
115
- @tg.data_processor.x_max.should_not == 10.0
116
- @tg.data_processor.y_min.should_not == -8.0
117
- @tg.data_processor.y_max.should_not == 10.0
118
-
119
- @tg.data_processor.x_min.should == -21.0
120
- @tg.data_processor.x_max.should == 39.0
121
- @tg.data_processor.y_min.should == -93.0
122
- @tg.data_processor.y_max.should == 333.0
123
- end
124
-
125
- should 'provide ranges calculated with zoom' do
126
- x_min = 0.0
127
- x_max = 1.0
128
- y_min = -1.0
129
- y_max = 1.0
130
-
131
- @tg = TechnicalGraph.new(
132
- {
133
- :x_min => x_min,
134
- :x_max => x_max,
135
- :y_min => y_min,
136
- :y_max => y_max,
137
- :xy_behaviour => :default
138
- }
139
- )
140
-
141
- # adding simple layer
142
- layer_data = [
143
- { :x => -5, :y => 5.0 },
144
- { :x => 2, :y => -5.0 },
145
- { :x => 0, :y => 5.0 },
146
- { :x => 5, :y => 5.0 }
147
- ]
148
- @tg.add_layer(layer_data)
149
- # should be added
150
- @tg.layers.last.raw_data.size > 0
151
- @tg.layers.last.processed_data.size > 0
152
- # checking ranger for layer
153
-
154
- @tg.render
155
-
156
-
157
- @tg.data_processor.x_min.should_not == x_min
158
- @tg.data_processor.x_max.should_not == x_max
159
- @tg.data_processor.y_min.should_not == y_min
160
- @tg.data_processor.y_max.should_not == y_max
161
-
162
- @tg.data_processor.x_min.should == -5
163
- @tg.data_processor.x_max.should == 5
164
- @tg.data_processor.y_min.should == -5.0
165
- @tg.data_processor.y_max.should == 5.0
166
-
167
- @tg.data_processor.zoom = 2.0
168
-
169
- @tg.data_processor.x_min.should == -10.0
170
- @tg.data_processor.x_max.should == 10.0
171
- @tg.data_processor.y_min.should == -10.0
172
- @tg.data_processor.y_max.should == 10.0
173
-
174
- @tg.data_processor.x_min.should_not == -5
175
- @tg.data_processor.x_max.should_not == 5
176
- @tg.data_processor.y_min.should_not == -5.0
177
- @tg.data_processor.y_max.should_not == 5.0
178
-
179
- @tg.data_processor.raw_x_min.should == -5
180
- @tg.data_processor.raw_x_max.should == 5
181
- @tg.data_processor.raw_y_min.should == -5.0
182
- @tg.data_processor.raw_y_max.should == 5.0
183
- end
184
-
185
-
186
- should 'calculate axis with fixed interval' do
187
- x_min = -5.0
188
- x_max = 5.0
189
- y_min = -5.0
190
- y_max = 5.0
191
-
192
- @tg = TechnicalGraph.new(
193
- {
194
- :x_min => x_min,
195
- :x_max => x_max,
196
- :y_min => y_min,
197
- :y_max => y_max,
198
- :xy_behaviour => :fixed,
199
-
200
- :y_axis_count => 10,
201
- :x_axis_count => 10,
202
- :y_axis_interval => 1.0,
203
- :x_axis_interval => 4.0,
204
- :x_axis_fixed_interval => true,
205
- :y_axis_fixed_interval => true,
206
-
207
- :adjust_axis_to_zero => false
208
- }
209
- )
210
-
211
- # adding simple layer
212
- layer_data = [
213
- { :x => -1, :y => 2.0 },
214
- { :x => 1, :y => -2.0 },
215
- { :x => 0, :y => 2.0 },
216
- { :x => 1, :y => 2.0 }
217
- ]
218
- @tg.add_layer(layer_data)
219
- # should be added
220
- @tg.layers.last.raw_data.size > 0
221
- @tg.layers.last.processed_data.size > 0
222
- # checking ranger for layer
223
-
224
- @tg.render
225
-
226
- @tg.axis.value_axis.should == [-5.0, -4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0]
227
- @tg.axis.parameter_axis.should == [-5.0, -1.0, 3.0]
228
- end
229
-
230
-
231
- should 'calculate axis with fixed count' do
232
- x_min = -8.0
233
- x_max = 8.0
234
- y_min = -4.0
235
- y_max = 4.0
236
-
237
- @tg = TechnicalGraph.new(
238
- {
239
- :x_min => x_min,
240
- :x_max => x_max,
241
- :y_min => y_min,
242
- :y_max => y_max,
243
- :xy_behaviour => :fixed,
244
-
245
- :x_axis_count => 8,
246
- :y_axis_count => 4,
247
- :x_axis_interval => 2.0,
248
- :y_axis_interval => 1.0,
249
- :x_axis_fixed_interval => false,
250
- :y_axis_fixed_interval => false
251
- }
252
- )
253
-
254
- # adding simple layer
255
- layer_data = [
256
- { :x => -1, :y => 2.0 },
257
- { :x => 1, :y => -2.0 },
258
- { :x => 0, :y => 2.0 },
259
- { :x => 1, :y => 2.0 }
260
- ]
261
- @tg.add_layer(layer_data)
262
- # should be added
263
- @tg.layers.last.raw_data.size > 0
264
- @tg.layers.last.processed_data.size > 0
265
- # checking ranger for layer
266
-
267
- @tg.render
268
-
269
- @tg.axis.parameter_axis.should == [-8.0, -6.0, -4.0, -2.0, 0.0, 2.0, 4.0, 6.0]
270
- @tg.axis.value_axis.should == [-4.0, -2.0, 0.0, 2.0]
271
-
272
- @tg.image_drawer.save_to_file("samples/tests/test1.#{@tg.best_output_format}")
273
- end
274
-
275
-
276
- should 'draw simple graph' do
277
- @tg = TechnicalGraph.new(
278
- {
279
- :x_axis_count => 10,
280
- :y_axis_count => 10,
281
- :x_axis_interval => 1.0,
282
- :y_axis_interval => 1.0,
283
- :x_axis_fixed_interval => false,
284
- :y_axis_fixed_interval => false,
285
-
286
- :x_min => -10.0,
287
- :x_max => 10.0,
288
- :y_min => -10.0,
289
- :y_max => 10.0
290
- }
291
- )
292
-
293
-
294
-
295
- # adding simple layer
296
- layer_data = Array.new
297
- (0..20).each do |i|
298
- layer_data << {:x => Math.sin(i.to_f/10.0) * 10.0, :y => Math.cos(i.to_f/10.0) * 10.0 }
299
- end
300
- @tg.add_layer(layer_data)
301
- # should be added
302
- @tg.layers.last.raw_data.size > 0
303
- @tg.layers.last.processed_data.size > 0
304
- # checking ranger for layer
305
-
306
- @tg.render
307
-
308
- @tg.image_drawer.save_to_file("samples/tests/test2.#{@tg.best_output_format}")
309
- end
310
-
311
- end
312
-
313
- end
314
-