technical_graph 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/DOCUMENTATION.textile +244 -171
- data/Gemfile +26 -5
- data/Gemfile.lock +30 -14
- data/README.md +68 -39
- data/Rakefile +16 -14
- data/VERSION +1 -1
- data/lib/technical_graph.rb +45 -0
- data/lib/technical_graph/data_layer_processor_simple_smoother.rb +1 -1
- data/lib/technical_graph/gem.rb +12 -0
- data/lib/technical_graph/graph_axis.rb +14 -7
- data/lib/technical_graph/graph_color_library.rb +5 -5
- data/lib/technical_graph/graph_data_processor.rb +3 -1
- data/lib/technical_graph/graph_image_drawer.rb +35 -12
- data/lib/technical_graph/graph_image_drawer_chunky.rb +161 -0
- data/lib/technical_graph/graph_image_drawer_rmagick.rb +6 -2
- metadata +119 -135
- data/test/helper.rb +0 -23
- data/test/test_technical_autocolor.rb +0 -92
- data/test/test_technical_axis_enlarge.rb +0 -68
- data/test/test_technical_fix1.rb +0 -64
- data/test/test_technical_graph.rb +0 -115
- data/test/test_technical_graph_axis.rb +0 -314
- data/test/test_technical_multilayer.rb +0 -96
- data/test/test_technical_noise_removal.rb +0 -36
- data/test/test_technical_rasem.rb +0 -22
- data/test/test_technical_readme.rb +0 -525
- data/test/test_technical_simple_graph.rb +0 -64
- data/test/test_technical_smoother.rb +0 -214
- data/test/test_technical_smoother_adv.rb +0 -125
@@ -1,96 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestTechnicalMultilayer < 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
|
-
:color => 'red',
|
51
|
-
:label => 'first'
|
52
|
-
}
|
53
|
-
layer_params_b = {
|
54
|
-
:antialias => true,
|
55
|
-
:color => 'green',
|
56
|
-
:label => 'second'
|
57
|
-
}
|
58
|
-
layer_params_c = {
|
59
|
-
:antialias => true,
|
60
|
-
:color => 'blue',
|
61
|
-
:label => 'third'
|
62
|
-
}
|
63
|
-
layer_params_d = {
|
64
|
-
:antialias => true,
|
65
|
-
:color => 'purple',
|
66
|
-
:label => 'fourth'
|
67
|
-
}
|
68
|
-
layer_data_a = Array.new
|
69
|
-
layer_data_b = Array.new
|
70
|
-
layer_data_c = Array.new
|
71
|
-
layer_data_d = Array.new
|
72
|
-
(0..max).each do |i|
|
73
|
-
layer_data_a << { :x => -10.0 + i.to_f, :y => 10.0 * Math.cos(i.to_f * (4.0 * 3.14 / max.to_f)) }
|
74
|
-
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)) }
|
75
|
-
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)) }
|
76
|
-
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)) }
|
77
|
-
end
|
78
|
-
@tg.add_layer(layer_data_a, layer_params_a)
|
79
|
-
@tg.add_layer(layer_data_b, layer_params_b)
|
80
|
-
@tg.add_layer(layer_data_c, layer_params_c)
|
81
|
-
@tg.add_layer(layer_data_d, layer_params_d)
|
82
|
-
|
83
|
-
|
84
|
-
@tg.layers.last.raw_data.size.should > 0
|
85
|
-
@tg.layers.last.processed_data.size.should > 0
|
86
|
-
@tg.layers.size.should == 4
|
87
|
-
|
88
|
-
@tg.render
|
89
|
-
|
90
|
-
@tg.image_drawer.save_to_file("samples/tests/test_multilayer.#{@tg.best_output_format}")
|
91
|
-
@tg.image_drawer.to_format(@tg.best_output_format).class.should == String
|
92
|
-
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestTechnicalNoiseRemoval < Test::Unit::TestCase
|
4
|
-
context 'basic noise (wrong data) removal' do
|
5
|
-
|
6
|
-
should 'do linear dry test' do
|
7
|
-
layer_data = Array.new
|
8
|
-
size = 100
|
9
|
-
(0..size).each do |i|
|
10
|
-
layer_data << { :x => i.to_f, :y => 5.0 }
|
11
|
-
end
|
12
|
-
# noise, spike
|
13
|
-
layer_data << { :x => 50.1, :y => 12.0 }
|
14
|
-
|
15
|
-
layer_params = {
|
16
|
-
:noise_removal => true,
|
17
|
-
:noise_removal_level => 3,
|
18
|
-
:noise_removal_window_size => 10,
|
19
|
-
}
|
20
|
-
|
21
|
-
dl = DataLayer.new(layer_data, layer_params)
|
22
|
-
dlp = DataLayerProcessor.new(dl)
|
23
|
-
|
24
|
-
dlp.noise_removal.should == true
|
25
|
-
dlp.noise_removal_level.should == 3
|
26
|
-
dlp.noise_removal_window_size.should == 10
|
27
|
-
|
28
|
-
# start only noise removal for test
|
29
|
-
#dlp.noise_removal_process
|
30
|
-
# start everything
|
31
|
-
dl.process!
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestTechnicalRasem < Test::Unit::TestCase
|
4
|
-
context 'drawing SVG graphs using rasem' do
|
5
|
-
|
6
|
-
should 'do some initials' do
|
7
|
-
fake_drawer_class = Struct.new('GraphImageDrawerFake', :width, :height)
|
8
|
-
fake_drawer = fake_drawer_class.new
|
9
|
-
fake_drawer[:width] = 800
|
10
|
-
fake_drawer[:height] = 600
|
11
|
-
d = GraphImageDrawerRasem.new(fake_drawer)
|
12
|
-
d.x_axis([ 0, 100, 200, 300 ])
|
13
|
-
d.close
|
14
|
-
|
15
|
-
d.save("samples/tests/rasem_init.svg")
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
end
|
@@ -1,525 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
# run only latest test to create new graphs for documentation
|
4
|
-
DO_NOT_RUN_OLD_TESTS = true
|
5
|
-
README_RENDERED = :rmagick
|
6
|
-
|
7
|
-
class TestTechnicalReadme < Test::Unit::TestCase
|
8
|
-
context 'generate sample graphs using readme options description' do
|
9
|
-
setup do
|
10
|
-
@simple_data_array = [
|
11
|
-
{ :x => 0, :y => 0 },
|
12
|
-
{ :x => 1, :y => 1 },
|
13
|
-
{ :x => 2, :y => 2 },
|
14
|
-
{ :x => 3, :y => 2 },
|
15
|
-
{ :x => 4, :y => 1 },
|
16
|
-
{ :x => 5, :y => 0 },
|
17
|
-
]
|
18
|
-
@simple_data_array_b = [
|
19
|
-
{ :x => 0.5, :y => 0.5 },
|
20
|
-
{ :x => 1.5, :y => 0.5 },
|
21
|
-
{ :x => 2.5, :y => 1.5 },
|
22
|
-
{ :x => 3.5, :y => 1.0 },
|
23
|
-
{ :x => 4.5, :y => 1.5 },
|
24
|
-
{ :x => 5.5, :y => 1.5 },
|
25
|
-
]
|
26
|
-
@float_data_array = [
|
27
|
-
{ :x => 0, :y => 0 },
|
28
|
-
{ :x => 0.111, :y => 0.123 },
|
29
|
-
{ :x => 1.222, :y => 1.456 },
|
30
|
-
{ :x => 1.333, :y => 2.8756 },
|
31
|
-
{ :x => 2.555, :y => 1.042 },
|
32
|
-
{ :x => 2.888, :y => 0.988 },
|
33
|
-
]
|
34
|
-
end
|
35
|
-
|
36
|
-
#
|
37
|
-
should 'create simplest graph' do
|
38
|
-
return if DO_NOT_RUN_OLD_TESTS
|
39
|
-
@tg = TechnicalGraph.new({:drawer_class => README_RENDERED})
|
40
|
-
@tg.add_layer(@simple_data_array)
|
41
|
-
@tg.render
|
42
|
-
file_name = 'samples/readme/01_simplest.png'
|
43
|
-
@tg.image_drawer.save_to_file(file_name)
|
44
|
-
|
45
|
-
# test
|
46
|
-
@tg.image_drawer.to_format(@tg.best_output_format).class.should == String
|
47
|
-
File.exist?(file_name).should == true
|
48
|
-
end
|
49
|
-
|
50
|
-
#
|
51
|
-
should 'create 2-layer graph' do
|
52
|
-
return if DO_NOT_RUN_OLD_TESTS
|
53
|
-
@tg = TechnicalGraph.new({:drawer_class => README_RENDERED})
|
54
|
-
@tg.add_layer(@simple_data_array)
|
55
|
-
@tg.add_layer(@simple_data_array_b)
|
56
|
-
@tg.render
|
57
|
-
file_name = 'samples/readme/02_two_layers.png'
|
58
|
-
@tg.image_drawer.save_to_file(file_name)
|
59
|
-
|
60
|
-
# test
|
61
|
-
@tg.image_drawer.to_format(@tg.best_output_format).class.should == String
|
62
|
-
File.exist?(file_name).should == true
|
63
|
-
end
|
64
|
-
|
65
|
-
#
|
66
|
-
should 'change ranges' do
|
67
|
-
return if DO_NOT_RUN_OLD_TESTS
|
68
|
-
@tg = TechnicalGraph.new(
|
69
|
-
{
|
70
|
-
:x_min => -2,
|
71
|
-
:x_max => 10,
|
72
|
-
:y_min => -1,
|
73
|
-
:y_max => 10,
|
74
|
-
:drawer_class => README_RENDERED
|
75
|
-
})
|
76
|
-
@tg.add_layer(@simple_data_array)
|
77
|
-
@tg.render
|
78
|
-
file_name = 'samples/readme/03_changed_ranges.png'
|
79
|
-
@tg.image_drawer.save_to_file(file_name)
|
80
|
-
|
81
|
-
# test
|
82
|
-
@tg.image_drawer.to_format(@tg.best_output_format).class.should == String
|
83
|
-
File.exist?(file_name).should == true
|
84
|
-
end
|
85
|
-
|
86
|
-
should 'change ranges (fixed)' do
|
87
|
-
return if DO_NOT_RUN_OLD_TESTS
|
88
|
-
@tg = TechnicalGraph.new(
|
89
|
-
{
|
90
|
-
:x_min => 1,
|
91
|
-
:x_max => 2,
|
92
|
-
:y_min => 1,
|
93
|
-
:y_max => 2,
|
94
|
-
:xy_behaviour => :fixed,
|
95
|
-
:drawer_class => README_RENDERED
|
96
|
-
})
|
97
|
-
@tg.add_layer(@simple_data_array)
|
98
|
-
@tg.render
|
99
|
-
file_name = 'samples/readme/04_changed_ranges_fixed.png'
|
100
|
-
@tg.image_drawer.save_to_file(file_name)
|
101
|
-
|
102
|
-
# test
|
103
|
-
@tg.image_drawer.to_format(@tg.best_output_format).class.should == String
|
104
|
-
File.exist?(file_name).should == true
|
105
|
-
end
|
106
|
-
|
107
|
-
should 'fixed amount of axis' do
|
108
|
-
return if DO_NOT_RUN_OLD_TESTS
|
109
|
-
@tg = TechnicalGraph.new(
|
110
|
-
{
|
111
|
-
:x_axis_fixed_interval => false,
|
112
|
-
:y_axis_fixed_interval => false,
|
113
|
-
:y_axis_count => 20,
|
114
|
-
:x_axis_count => 20,
|
115
|
-
:drawer_class => README_RENDERED
|
116
|
-
})
|
117
|
-
@tg.add_layer(@simple_data_array)
|
118
|
-
@tg.render
|
119
|
-
file_name = 'samples/readme/05_axis_fixed_amount.png'
|
120
|
-
@tg.image_drawer.save_to_file(file_name)
|
121
|
-
|
122
|
-
# test
|
123
|
-
@tg.image_drawer.to_format(@tg.best_output_format).class.should == String
|
124
|
-
File.exist?(file_name).should == true
|
125
|
-
end
|
126
|
-
|
127
|
-
should 'fixed axis interval' do
|
128
|
-
return if DO_NOT_RUN_OLD_TESTS
|
129
|
-
@tg = TechnicalGraph.new(
|
130
|
-
{
|
131
|
-
:x_axis_fixed_interval => true,
|
132
|
-
:y_axis_fixed_interval => true,
|
133
|
-
:y_axis_interval => 0.8,
|
134
|
-
:x_axis_interval => 0.6,
|
135
|
-
:drawer_class => README_RENDERED
|
136
|
-
})
|
137
|
-
@tg.axis.x_axis_interval.should == 0.6
|
138
|
-
@tg.axis.y_axis_interval.should == 0.8
|
139
|
-
@tg.add_layer(@simple_data_array)
|
140
|
-
@tg.axis.x_axis_interval.should == 0.6
|
141
|
-
@tg.axis.y_axis_interval.should == 0.8
|
142
|
-
|
143
|
-
# axis_x = @tg.axis.calc_axis(@simple_data_array.first[:x], @simple_data_array.last[:x], 0.1, nil, true)
|
144
|
-
# axis_y = @tg.axis.calc_axis(@simple_data_array.first[:y], @simple_data_array.last[:y], 0.1, nil, true)
|
145
|
-
# puts axis_x.inspect
|
146
|
-
# puts axis_y.inspect
|
147
|
-
|
148
|
-
@tg.render
|
149
|
-
file_name = 'samples/readme/06_axis_fixed_interval.png'
|
150
|
-
@tg.image_drawer.save_to_file(file_name)
|
151
|
-
|
152
|
-
# test
|
153
|
-
@tg.image_drawer.to_format(@tg.best_output_format).class.should == String
|
154
|
-
File.exist?(file_name).should == true
|
155
|
-
end
|
156
|
-
|
157
|
-
should 'let choose axis label' do
|
158
|
-
return if DO_NOT_RUN_OLD_TESTS
|
159
|
-
@tg = TechnicalGraph.new(
|
160
|
-
{
|
161
|
-
:x_axis_label => 'parameter',
|
162
|
-
:y_axis_label => 'value',
|
163
|
-
:axis_label_font_size => 36,
|
164
|
-
:drawer_class => README_RENDERED
|
165
|
-
})
|
166
|
-
@tg.add_layer(@simple_data_array)
|
167
|
-
@tg.render
|
168
|
-
file_name = 'samples/readme/07_axis_label.png'
|
169
|
-
@tg.image_drawer.save_to_file(file_name)
|
170
|
-
|
171
|
-
# test
|
172
|
-
@tg.image_drawer.to_format(@tg.best_output_format).class.should == String
|
173
|
-
File.exist?(file_name).should == true
|
174
|
-
end
|
175
|
-
|
176
|
-
|
177
|
-
should 'test truncate string' do
|
178
|
-
return if DO_NOT_RUN_OLD_TESTS
|
179
|
-
@tg = TechnicalGraph.new(
|
180
|
-
{
|
181
|
-
:truncate_string => "%.3f",
|
182
|
-
:drawer_class => README_RENDERED
|
183
|
-
})
|
184
|
-
@layer_params = {
|
185
|
-
:value_labels => true
|
186
|
-
}
|
187
|
-
@tg.add_layer(@float_data_array, @layer_params)
|
188
|
-
@tg.render
|
189
|
-
file_name = 'samples/readme/08a_truncate_string.png'
|
190
|
-
@tg.image_drawer.save_to_file(file_name)
|
191
|
-
|
192
|
-
# test
|
193
|
-
@tg.image_drawer.to_format(@tg.best_output_format).class.should == String
|
194
|
-
File.exist?(file_name).should == true
|
195
|
-
end
|
196
|
-
|
197
|
-
should 'test truncate string 2' do
|
198
|
-
return if DO_NOT_RUN_OLD_TESTS
|
199
|
-
@tg = TechnicalGraph.new(
|
200
|
-
{
|
201
|
-
:truncate_string => "%.1f",
|
202
|
-
:drawer_class => README_RENDERED
|
203
|
-
})
|
204
|
-
@layer_params = {
|
205
|
-
:value_labels => true
|
206
|
-
}
|
207
|
-
@tg.add_layer(@float_data_array, @layer_params)
|
208
|
-
@tg.render
|
209
|
-
file_name = 'samples/readme/08b_truncate_string.png'
|
210
|
-
@tg.image_drawer.save_to_file(file_name)
|
211
|
-
|
212
|
-
# test
|
213
|
-
@tg.image_drawer.to_format(@tg.best_output_format).class.should == String
|
214
|
-
File.exist?(file_name).should == true
|
215
|
-
end
|
216
|
-
|
217
|
-
should 'test image size' do
|
218
|
-
return if DO_NOT_RUN_OLD_TESTS
|
219
|
-
@tg = TechnicalGraph.new(
|
220
|
-
{
|
221
|
-
:width => 600,
|
222
|
-
:height => 300,
|
223
|
-
:drawer_class => README_RENDERED,
|
224
|
-
})
|
225
|
-
@tg.add_layer(@simple_data_array)
|
226
|
-
@tg.render
|
227
|
-
file_name = 'samples/readme/09_image_size.png'
|
228
|
-
@tg.image_drawer.save_to_file(file_name)
|
229
|
-
|
230
|
-
# test
|
231
|
-
@tg.image_drawer.to_format(@tg.best_output_format).class.should == String
|
232
|
-
File.exist?(file_name).should == true
|
233
|
-
end
|
234
|
-
|
235
|
-
should 'test colors' do
|
236
|
-
return if DO_NOT_RUN_OLD_TESTS
|
237
|
-
@tg = TechnicalGraph.new(
|
238
|
-
{
|
239
|
-
:background_color => '#000000',
|
240
|
-
:background_hatch_color => '#222222',
|
241
|
-
:axis_color => '#FFFFFF',
|
242
|
-
:drawer_class => README_RENDERED,
|
243
|
-
})
|
244
|
-
@tg.add_layer(@simple_data_array, {:color => '#0000FF'})
|
245
|
-
@tg.render
|
246
|
-
file_name = 'samples/readme/10_colors.png'
|
247
|
-
@tg.image_drawer.save_to_file(file_name)
|
248
|
-
|
249
|
-
# test
|
250
|
-
@tg.image_drawer.to_format(@tg.best_output_format).class.should == String
|
251
|
-
File.exist?(file_name).should == true
|
252
|
-
end
|
253
|
-
|
254
|
-
should 'test renderer' do
|
255
|
-
return if DO_NOT_RUN_OLD_TESTS
|
256
|
-
|
257
|
-
@tg = TechnicalGraph.new(
|
258
|
-
{
|
259
|
-
:drawer_class => :rmagick,
|
260
|
-
})
|
261
|
-
@tg.add_layer(@simple_data_array)
|
262
|
-
@tg.render
|
263
|
-
file_name = 'samples/readme/11_renderer_rmagick.png'
|
264
|
-
@tg.image_drawer.save_to_file(file_name)
|
265
|
-
|
266
|
-
@tg = TechnicalGraph.new(
|
267
|
-
{
|
268
|
-
:drawer_class => :rasem
|
269
|
-
})
|
270
|
-
@tg.add_layer(@simple_data_array)
|
271
|
-
@tg.render
|
272
|
-
file_name = 'samples/readme/11_renderer_rasem.png'
|
273
|
-
@tg.image_drawer.save_to_file(file_name)
|
274
|
-
|
275
|
-
# test
|
276
|
-
@tg.image_drawer.to_format(@tg.best_output_format).class.should == String
|
277
|
-
File.exist?(file_name).should == true
|
278
|
-
end
|
279
|
-
|
280
|
-
should 'test anti-aliasing' do
|
281
|
-
return if DO_NOT_RUN_OLD_TESTS
|
282
|
-
|
283
|
-
@tg = TechnicalGraph.new(
|
284
|
-
{
|
285
|
-
:antialias => true,
|
286
|
-
:drawer_class => :rmagick
|
287
|
-
})
|
288
|
-
@tg.add_layer(@simple_data_array)
|
289
|
-
@tg.render
|
290
|
-
file_name = 'samples/readme/12_aa_true.png'
|
291
|
-
@tg.image_drawer.save_to_file(file_name)
|
292
|
-
|
293
|
-
# only for size comparison
|
294
|
-
@tg = TechnicalGraph.new(
|
295
|
-
{
|
296
|
-
:antialias => false,
|
297
|
-
:drawer_class => :rmagick
|
298
|
-
})
|
299
|
-
@tg.add_layer(@simple_data_array)
|
300
|
-
@tg.render
|
301
|
-
file_name = 'samples/readme/12_aa_false.png'
|
302
|
-
@tg.image_drawer.save_to_file(file_name)
|
303
|
-
|
304
|
-
# test
|
305
|
-
@tg.image_drawer.to_format(@tg.best_output_format).class.should == String
|
306
|
-
File.exist?(file_name).should == true
|
307
|
-
end
|
308
|
-
|
309
|
-
|
310
|
-
should 'test font sizes' do
|
311
|
-
return if DO_NOT_RUN_OLD_TESTS
|
312
|
-
|
313
|
-
@tg = TechnicalGraph.new(
|
314
|
-
{
|
315
|
-
:x_axis_label => 'parameter',
|
316
|
-
:y_axis_label => 'value',
|
317
|
-
:layers_font_size => 14,
|
318
|
-
:axis_font_size => 18,
|
319
|
-
:axis_label_font_size => 48,
|
320
|
-
:drawer_class => README_RENDERED
|
321
|
-
})
|
322
|
-
@tg.add_layer(@simple_data_array, {:value_labels => true})
|
323
|
-
@tg.render
|
324
|
-
file_name = 'samples/readme/13_font_sizes.png'
|
325
|
-
@tg.image_drawer.save_to_file(file_name)
|
326
|
-
|
327
|
-
# test
|
328
|
-
@tg.image_drawer.to_format(@tg.best_output_format).class.should == String
|
329
|
-
File.exist?(file_name).should == true
|
330
|
-
end
|
331
|
-
|
332
|
-
|
333
|
-
should 'test layer labels, colors and legend' do
|
334
|
-
return if DO_NOT_RUN_OLD_TESTS
|
335
|
-
|
336
|
-
@simple_data_array_second = @simple_data_array.collect{|a| {:x => a[:x] + 0.31, :y => a[:y] + 0.21 }}
|
337
|
-
@simple_data_array_third = @simple_data_array.collect{|a| {:x => a[:x] * 0.99 + 0.23, :y => a[:y] * 1.2 - 0.12 }}
|
338
|
-
|
339
|
-
@tg = TechnicalGraph.new(
|
340
|
-
{
|
341
|
-
:legend => true,
|
342
|
-
:legend_font_size => 20,
|
343
|
-
:drawer_class => README_RENDERED
|
344
|
-
})
|
345
|
-
@tg.add_layer(@simple_data_array, {:label => 'simple', :color => '#FFFF00'})
|
346
|
-
@tg.add_layer(@simple_data_array_second, {:label => 'offset', :color => '#00FFFF'})
|
347
|
-
@tg.add_layer(@simple_data_array_third, {:label => 'scaled', :color => '#FF00FF'})
|
348
|
-
|
349
|
-
@tg.render
|
350
|
-
file_name = 'samples/readme/14_simple_legend.png'
|
351
|
-
@tg.image_drawer.save_to_file(file_name)
|
352
|
-
|
353
|
-
# test
|
354
|
-
@tg.image_drawer.to_format(@tg.best_output_format).class.should == String
|
355
|
-
File.exist?(file_name).should == true
|
356
|
-
end
|
357
|
-
|
358
|
-
|
359
|
-
should 'test smoothing' do
|
360
|
-
return if DO_NOT_RUN_OLD_TESTS
|
361
|
-
|
362
|
-
@tg = TechnicalGraph.new(
|
363
|
-
{
|
364
|
-
:width => 2000,
|
365
|
-
:height => 1500,
|
366
|
-
:legend => true,
|
367
|
-
:x_axis_label => "Parameter",
|
368
|
-
:y_axis_label => "Value",
|
369
|
-
:drawer_class => README_RENDERED,
|
370
|
-
}
|
371
|
-
)
|
372
|
-
max = 250 #2000
|
373
|
-
|
374
|
-
@layer_data = Array.new
|
375
|
-
(0..max).each do |i|
|
376
|
-
x = -10.0 + (20.0 * i.to_f / max.to_f)
|
377
|
-
y = 10.0 * Math.cos(i.to_f * (2.0 * 3.14 / max.to_f))
|
378
|
-
|
379
|
-
y += rand * 2.0
|
380
|
-
|
381
|
-
@layer_data << { :x => x, :y => y }
|
382
|
-
end
|
383
|
-
|
384
|
-
# adding simple layer
|
385
|
-
@layer_params = {
|
386
|
-
:label => 'raw',
|
387
|
-
:value_labels => false,
|
388
|
-
:simple_smoother => false,
|
389
|
-
:simple_smoother_level => 1,
|
390
|
-
:simple_smoother_strategy => :gauss,
|
391
|
-
:simple_smoother_x => false,
|
392
|
-
}
|
393
|
-
@layer_params_b = @layer_params.clone.merge(
|
394
|
-
{
|
395
|
-
:label => 'smoothed - level 3',
|
396
|
-
:simple_smoother_level => 3,
|
397
|
-
:simple_smoother => true
|
398
|
-
})
|
399
|
-
@layer_params_e = @layer_params.clone.merge(
|
400
|
-
{
|
401
|
-
:label => 'smoothed - level 50',
|
402
|
-
:simple_smoother_level => 50,
|
403
|
-
:simple_smoother => true
|
404
|
-
})
|
405
|
-
|
406
|
-
@tg.add_layer(@layer_data.clone, @layer_params)
|
407
|
-
@tg.add_layer(@layer_data.clone, @layer_params_b)
|
408
|
-
@tg.add_layer(@layer_data.clone, @layer_params_e)
|
409
|
-
|
410
|
-
@tg.render
|
411
|
-
file_name = 'samples/readme/15_smoothing.png'
|
412
|
-
@tg.image_drawer.save_to_file(file_name)
|
413
|
-
|
414
|
-
# test
|
415
|
-
@tg.image_drawer.to_format(@tg.best_output_format).class.should == String
|
416
|
-
File.exist?(file_name).should == true
|
417
|
-
end
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
should 'test noise filtering' do
|
422
|
-
return if DO_NOT_RUN_OLD_TESTS
|
423
|
-
|
424
|
-
@tg = TechnicalGraph.new(
|
425
|
-
{
|
426
|
-
#:log_level => Logger::DEBUG,
|
427
|
-
:legend => true,
|
428
|
-
:drawer_class => README_RENDERED
|
429
|
-
}
|
430
|
-
)
|
431
|
-
max = 250 #2000
|
432
|
-
|
433
|
-
@layer_data = Array.new
|
434
|
-
(0..max).each do |i|
|
435
|
-
x = -10.0 + (20.0 * i.to_f / max.to_f)
|
436
|
-
y = -10.0 + (20.0 * i.to_f / max.to_f)
|
437
|
-
@layer_data << { :x => x, :y => y }
|
438
|
-
end
|
439
|
-
|
440
|
-
# custom spikes
|
441
|
-
[3, 36, 99, 187, 204].each do |i|
|
442
|
-
offset = 5.0
|
443
|
-
offset *= -1.0 if rand(100) % 2 == 1
|
444
|
-
@layer_data[i][:y] += offset
|
445
|
-
end
|
446
|
-
|
447
|
-
150.times do
|
448
|
-
i = rand(@layer_data.size)
|
449
|
-
offset = rand(80).to_f / 10.0
|
450
|
-
offset *= -1.0 if rand(100) % 2 == 1
|
451
|
-
|
452
|
-
@layer_data[i][:y] += offset
|
453
|
-
end
|
454
|
-
|
455
|
-
# adding simple layer
|
456
|
-
@layer_params = {
|
457
|
-
:label => 'raw',
|
458
|
-
:value_labels => false,
|
459
|
-
}
|
460
|
-
@layer_params_b = @layer_params.clone.merge(
|
461
|
-
{
|
462
|
-
:label => 'n.r. level 3, window 10',
|
463
|
-
:noise_removal_window_size => 10,
|
464
|
-
:noise_removal_level => 3,
|
465
|
-
:noise_removal => true
|
466
|
-
})
|
467
|
-
@layer_params_e = @layer_params.clone.merge(
|
468
|
-
{
|
469
|
-
:label => 'n.r level 10, window 30',
|
470
|
-
:noise_removal_window_size => 10,
|
471
|
-
:noise_removal_level => 30,
|
472
|
-
:noise_removal => true
|
473
|
-
})
|
474
|
-
|
475
|
-
@tg.add_layer(@layer_data.clone, @layer_params)
|
476
|
-
@tg.add_layer(@layer_data.clone, @layer_params_b)
|
477
|
-
@tg.add_layer(@layer_data.clone, @layer_params_e)
|
478
|
-
|
479
|
-
@tg.render
|
480
|
-
file_name = 'samples/readme/16_noise_removal.png'
|
481
|
-
@tg.image_drawer.save_to_file(file_name)
|
482
|
-
|
483
|
-
# test
|
484
|
-
@tg.image_drawer.to_format(@tg.best_output_format).class.should == String
|
485
|
-
File.exist?(file_name).should == true
|
486
|
-
end
|
487
|
-
|
488
|
-
|
489
|
-
should 'test axis enlargement' do
|
490
|
-
return if DO_NOT_RUN_OLD_TESTS
|
491
|
-
|
492
|
-
@tg = TechnicalGraph.new(
|
493
|
-
{
|
494
|
-
:log_level => Logger::DEBUG,
|
495
|
-
:drawer_class => README_RENDERED,
|
496
|
-
:axis_density_enlarge_image => true,
|
497
|
-
:x_axis_min_distance => 500,
|
498
|
-
:x_axis_interval => 1.0,
|
499
|
-
:x_axis_fixed_interval => true,
|
500
|
-
:width => 400
|
501
|
-
}
|
502
|
-
)
|
503
|
-
max = 250 #2000
|
504
|
-
|
505
|
-
@layer_data = Array.new
|
506
|
-
(0..max).each do |i|
|
507
|
-
x = -10.0 + (20.0 * i.to_f / max.to_f)
|
508
|
-
y = -10.0 + rand(2000).to_f / 100.0
|
509
|
-
@layer_data << { :x => x, :y => y }
|
510
|
-
end
|
511
|
-
|
512
|
-
@tg.add_layer(@layer_data)
|
513
|
-
|
514
|
-
@tg.render
|
515
|
-
file_name = 'samples/readme/17_axis_enlargement.png'
|
516
|
-
@tg.image_drawer.save_to_file(file_name)
|
517
|
-
|
518
|
-
# test
|
519
|
-
@tg.image_drawer.to_format(@tg.best_output_format).class.should == String
|
520
|
-
File.exist?(file_name).should == true
|
521
|
-
end
|
522
|
-
|
523
|
-
|
524
|
-
end
|
525
|
-
end
|