technical_graph 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,306 @@
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.data.size > 0
74
+ # checking ranger for layer
75
+
76
+ @tg.render
77
+
78
+
79
+ @tg.data_processor.x_min.should_not == x_min
80
+ @tg.data_processor.x_max.should_not == x_max
81
+ @tg.data_processor.y_min.should_not == y_min
82
+ @tg.data_processor.y_max.should_not == y_max
83
+
84
+ @tg.data_processor.x_min.should == -1
85
+ @tg.data_processor.x_max.should == 10
86
+ @tg.data_processor.y_min.should == -8.0
87
+ @tg.data_processor.y_max.should == 10.0
88
+
89
+
90
+
91
+ # adding another layer
92
+
93
+ # adding simple layer
94
+ layer_data = [
95
+ { :x => -21, :y => -93.0 },
96
+ { :x => -5, :y => 3.0 },
97
+ { :x => 39, :y => -8.0 },
98
+ { :x => 0, :y => 333.0 },
99
+ { :x => 10, :y => 50.0 }
100
+ ]
101
+ @tg.add_layer(layer_data)
102
+ # should be added
103
+ @tg.layers.last.data.size > 1
104
+
105
+ @tg.render
106
+
107
+ @tg.data_processor.x_min.should_not == x_min
108
+ @tg.data_processor.x_max.should_not == x_max
109
+ @tg.data_processor.y_min.should_not == y_min
110
+ @tg.data_processor.y_max.should_not == y_max
111
+
112
+ @tg.data_processor.x_min.should_not == -1.0
113
+ @tg.data_processor.x_max.should_not == 10.0
114
+ @tg.data_processor.y_min.should_not == -8.0
115
+ @tg.data_processor.y_max.should_not == 10.0
116
+
117
+ @tg.data_processor.x_min.should == -21.0
118
+ @tg.data_processor.x_max.should == 39.0
119
+ @tg.data_processor.y_min.should == -93.0
120
+ @tg.data_processor.y_max.should == 333.0
121
+ end
122
+
123
+ should 'provide ranges calculated with zoom' do
124
+ x_min = 0.0
125
+ x_max = 1.0
126
+ y_min = -1.0
127
+ y_max = 1.0
128
+
129
+ @tg = TechnicalGraph.new(
130
+ {
131
+ :x_min => x_min,
132
+ :x_max => x_max,
133
+ :y_min => y_min,
134
+ :y_max => y_max,
135
+ :xy_behaviour => :default
136
+ }
137
+ )
138
+
139
+ # adding simple layer
140
+ layer_data = [
141
+ { :x => -5, :y => 5.0 },
142
+ { :x => 2, :y => -5.0 },
143
+ { :x => 0, :y => 5.0 },
144
+ { :x => 5, :y => 5.0 }
145
+ ]
146
+ @tg.add_layer(layer_data)
147
+ # should be added
148
+ @tg.layers.last.data.size > 0
149
+ # checking ranger for layer
150
+
151
+ @tg.render
152
+
153
+
154
+ @tg.data_processor.x_min.should_not == x_min
155
+ @tg.data_processor.x_max.should_not == x_max
156
+ @tg.data_processor.y_min.should_not == y_min
157
+ @tg.data_processor.y_max.should_not == y_max
158
+
159
+ @tg.data_processor.x_min.should == -5
160
+ @tg.data_processor.x_max.should == 5
161
+ @tg.data_processor.y_min.should == -5.0
162
+ @tg.data_processor.y_max.should == 5.0
163
+
164
+ @tg.data_processor.zoom = 2.0
165
+
166
+ @tg.data_processor.x_min.should == -10.0
167
+ @tg.data_processor.x_max.should == 10.0
168
+ @tg.data_processor.y_min.should == -10.0
169
+ @tg.data_processor.y_max.should == 10.0
170
+
171
+ @tg.data_processor.x_min.should_not == -5
172
+ @tg.data_processor.x_max.should_not == 5
173
+ @tg.data_processor.y_min.should_not == -5.0
174
+ @tg.data_processor.y_max.should_not == 5.0
175
+
176
+ @tg.data_processor.raw_x_min.should == -5
177
+ @tg.data_processor.raw_x_max.should == 5
178
+ @tg.data_processor.raw_y_min.should == -5.0
179
+ @tg.data_processor.raw_y_max.should == 5.0
180
+ end
181
+
182
+
183
+ should 'calculate axis with fixed interval' do
184
+ x_min = -5.0
185
+ x_max = 5.0
186
+ y_min = -5.0
187
+ y_max = 5.0
188
+
189
+ @tg = TechnicalGraph.new(
190
+ {
191
+ :x_min => x_min,
192
+ :x_max => x_max,
193
+ :y_min => y_min,
194
+ :y_max => y_max,
195
+ :xy_behaviour => :fixed,
196
+
197
+ :y_axises_count => 10,
198
+ :x_axises_count => 10,
199
+ :y_axises_interval => 1.0,
200
+ :x_axises_interval => 4.0,
201
+ :x_axises_fixed_interval => true,
202
+ :y_axises_fixed_interval => true
203
+ }
204
+ )
205
+
206
+ # adding simple layer
207
+ layer_data = [
208
+ { :x => -1, :y => 2.0 },
209
+ { :x => 1, :y => -2.0 },
210
+ { :x => 0, :y => 2.0 },
211
+ { :x => 1, :y => 2.0 }
212
+ ]
213
+ @tg.add_layer(layer_data)
214
+ # should be added
215
+ @tg.layers.last.data.size > 0
216
+ # checking ranger for layer
217
+
218
+ @tg.render
219
+
220
+ @tg.axis.value_axises.should == [-5.0, -4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0]
221
+ @tg.axis.parameter_axises.should == [-5.0, -1.0, 3.0]
222
+ end
223
+
224
+
225
+ should 'calculate axis with fixed count' do
226
+ x_min = -8.0
227
+ x_max = 8.0
228
+ y_min = -4.0
229
+ y_max = 4.0
230
+
231
+ @tg = TechnicalGraph.new(
232
+ {
233
+ :x_min => x_min,
234
+ :x_max => x_max,
235
+ :y_min => y_min,
236
+ :y_max => y_max,
237
+ :xy_behaviour => :fixed,
238
+
239
+ :x_axises_count => 8,
240
+ :y_axises_count => 4,
241
+ :x_axises_interval => 2.0,
242
+ :y_axises_interval => 1.0,
243
+ :x_axises_fixed_interval => false,
244
+ :y_axises_fixed_interval => false
245
+ }
246
+ )
247
+
248
+ # adding simple layer
249
+ layer_data = [
250
+ { :x => -1, :y => 2.0 },
251
+ { :x => 1, :y => -2.0 },
252
+ { :x => 0, :y => 2.0 },
253
+ { :x => 1, :y => 2.0 }
254
+ ]
255
+ @tg.add_layer(layer_data)
256
+ # should be added
257
+ @tg.layers.last.data.size > 0
258
+ # checking ranger for layer
259
+
260
+ @tg.render
261
+
262
+ @tg.axis.parameter_axises.should == [-8.0, -6.0, -4.0, -2.0, 0.0, 2.0, 4.0, 6.0]
263
+ @tg.axis.value_axises.should == [-4.0, -2.0, 0.0, 2.0]
264
+
265
+ @tg.image_drawer.save_to_file('test1.png')
266
+ end
267
+
268
+
269
+ should 'draw simple graph' do
270
+ @tg = TechnicalGraph.new(
271
+ {
272
+ :x_axises_count => 10,
273
+ :y_axises_count => 10,
274
+ :x_axises_interval => 1.0,
275
+ :y_axises_interval => 1.0,
276
+ :x_axises_fixed_interval => false,
277
+ :y_axises_fixed_interval => false,
278
+
279
+ :x_min => -10.0,
280
+ :x_max => 10.0,
281
+ :y_min => -10.0,
282
+ :y_max => 10.0
283
+ }
284
+ )
285
+
286
+
287
+
288
+ # adding simple layer
289
+ layer_data = Array.new
290
+ (0..20).each do |i|
291
+ layer_data << {:x => Math.sin(i.to_f/10.0) * 10.0, :y => Math.cos(i.to_f/10.0) * 10.0 }
292
+ end
293
+ @tg.add_layer(layer_data)
294
+ # should be added
295
+ @tg.layers.last.data.size > 0
296
+ # checking ranger for layer
297
+
298
+ @tg.render
299
+
300
+ @tg.image_drawer.save_to_file('test2.png')
301
+ end
302
+
303
+ end
304
+
305
+ end
306
+
@@ -0,0 +1,46 @@
1
+ require 'helper'
2
+
3
+ class TestTechnicalGraph < Test::Unit::TestCase
4
+ context 'initial options' do
5
+ should 'draw simple graph' do
6
+ @tg = TechnicalGraph.new(
7
+ {
8
+ :x_axises_count => 20,
9
+ :y_axises_count => 20,
10
+ :x_axises_interval => 1.0,
11
+ :y_axises_interval => 1.0,
12
+ :x_axises_fixed_interval => false,
13
+ :y_axises_fixed_interval => false,
14
+
15
+ :x_min => -10.0,
16
+ :x_max => 10.0,
17
+ :y_min => -10.0,
18
+ :y_max => 10.0,
19
+
20
+ :width => 4000,
21
+ :height => 3000
22
+ }
23
+ )
24
+
25
+ max = 50
26
+
27
+ # adding simple layer
28
+ layer_params = {
29
+ :antialias => true
30
+ }
31
+ layer_data = Array.new
32
+ (0..max).each do |i|
33
+ layer_data << { :x => -10.0 + i.to_f, :y => 10.0 * Math.cos(i.to_f * (4.0 * 3.14 / max.to_f)) }
34
+ end
35
+ @tg.add_layer(layer_data, layer_params)
36
+ # should be added
37
+ @tg.layers.last.data.size > 0
38
+ # checking ranger for layer
39
+
40
+ @tg.render
41
+
42
+ @tg.image_drawer.save_to_file('test_simple.png')
43
+ end
44
+ end
45
+
46
+ end
metadata ADDED
@@ -0,0 +1,190 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: technical_graph
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ version: 0.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Aleksander Kwiatkowski
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-19 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :runtime
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ name: rmagick
33
+ version_requirements: *id001
34
+ prerelease: false
35
+ - !ruby/object:Gem::Dependency
36
+ type: :runtime
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ name: jeweler
47
+ version_requirements: *id002
48
+ prerelease: false
49
+ - !ruby/object:Gem::Dependency
50
+ type: :development
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ name: shoulda
61
+ version_requirements: *id003
62
+ prerelease: false
63
+ - !ruby/object:Gem::Dependency
64
+ type: :development
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ hash: 23
71
+ segments:
72
+ - 1
73
+ - 0
74
+ - 0
75
+ version: 1.0.0
76
+ name: bundler
77
+ version_requirements: *id004
78
+ prerelease: false
79
+ - !ruby/object:Gem::Dependency
80
+ type: :development
81
+ requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ name: rspec
91
+ version_requirements: *id005
92
+ prerelease: false
93
+ - !ruby/object:Gem::Dependency
94
+ type: :development
95
+ requirement: &id006 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ name: jeweler
105
+ version_requirements: *id006
106
+ prerelease: false
107
+ - !ruby/object:Gem::Dependency
108
+ type: :development
109
+ requirement: &id007 !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ name: rcov
119
+ version_requirements: *id007
120
+ prerelease: false
121
+ description: Create simple and neat graphs
122
+ email: bobikx@poczta.fm
123
+ executables: []
124
+
125
+ extensions: []
126
+
127
+ extra_rdoc_files:
128
+ - LICENSE.txt
129
+ - README.rdoc
130
+ files:
131
+ - .document
132
+ - .idea/dictionaries/olek.xml
133
+ - .rvmrc
134
+ - Gemfile
135
+ - Gemfile.lock
136
+ - LICENSE.txt
137
+ - README.rdoc
138
+ - Rakefile
139
+ - VERSION
140
+ - lib/technical_graph.rb
141
+ - lib/technical_graph/data_layer.rb
142
+ - lib/technical_graph/graph_axis.rb
143
+ - lib/technical_graph/graph_data_processor.rb
144
+ - lib/technical_graph/graph_image_drawer.rb
145
+ - lib/technical_graph/refactoring_backup/lib/technical_graph.rb
146
+ - lib/technical_graph/refactoring_backup/lib/technical_graph/axis_layer.rb
147
+ - lib/technical_graph/refactoring_backup/lib/technical_graph/axis_layer_draw_module.rb
148
+ - lib/technical_graph/refactoring_backup/test/test_technical_graph.rb
149
+ - lib/technical_graph/refactoring_backup/test/test_technical_graph_axis.rb
150
+ - samples/1.png
151
+ - test/helper.rb
152
+ - test/test_technical_graph.rb
153
+ - test/test_technical_graph_axis.rb
154
+ - test/test_technical_simple_graph.rb
155
+ has_rdoc: true
156
+ homepage: http://github.com/akwiatkowski/technical_graph
157
+ licenses:
158
+ - LGPLv3
159
+ post_install_message:
160
+ rdoc_options: []
161
+
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ none: false
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ hash: 3
170
+ segments:
171
+ - 0
172
+ version: "0"
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
+ none: false
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ hash: 3
179
+ segments:
180
+ - 0
181
+ version: "0"
182
+ requirements: []
183
+
184
+ rubyforge_project:
185
+ rubygems_version: 1.6.2
186
+ signing_key:
187
+ specification_version: 3
188
+ summary: Create simple and neat graphs
189
+ test_files: []
190
+