technical_graph 0.4.0 → 0.5.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.
@@ -186,6 +186,8 @@ class GraphImageDrawerRmagick
186
186
 
187
187
 
188
188
  def legend(legend_data)
189
+ legend_text_offset = (options[:legend_font_size] / 2.0).round - 4
190
+
189
191
  legend_data.each do |l|
190
192
  plot = axis_draw_object
191
193
  plot_text = layer_no_stroke(plot)
@@ -193,9 +195,10 @@ class GraphImageDrawerRmagick
193
195
  plot.fill(l[:color])
194
196
  plot.stroke(l[:color])
195
197
  plot_text.fill(l[:color])
198
+ plot_text.pointsize(options[:legend_font_size])
196
199
 
197
200
  plot.circle(l[:x], l[:y], l[:x] + 2, l[:y])
198
- plot_text.text(l[:x] + 5, l[:y], l[:label])
201
+ plot_text.text(l[:x] + 5, l[:y] + legend_text_offset, l[:label])
199
202
 
200
203
  plot.draw(@image)
201
204
  plot_text.draw(@image)
@@ -54,12 +54,13 @@ class TechnicalGraph
54
54
 
55
55
  # Create graph
56
56
  def render
57
- @image = @image_drawer.crate_blank_graph_image
58
- # recalculate ranges if needed
59
57
  @layers.each do |l|
60
58
  @data_processor.process_data_layer(l)
61
59
  end
62
60
 
61
+ # recalculate ranges if needed
62
+ @image = @image_drawer.crate_blank_graph_image
63
+
63
64
  # draw axis
64
65
  @axis.render_on_image(@image)
65
66
  # draw layers
@@ -202,7 +202,9 @@ class TestTechnicalGraphAxis < Test::Unit::TestCase
202
202
  :y_axis_interval => 1.0,
203
203
  :x_axis_interval => 4.0,
204
204
  :x_axis_fixed_interval => true,
205
- :y_axis_fixed_interval => true
205
+ :y_axis_fixed_interval => true,
206
+
207
+ :adjust_axis_to_zero => false
206
208
  }
207
209
  )
208
210
 
@@ -2,6 +2,7 @@ require 'helper'
2
2
 
3
3
  # run only latest test to create new graphs for documentation
4
4
  DO_NOT_RUN_OLD_TESTS = true
5
+ README_RENDERED = :rmagick
5
6
 
6
7
  class TestTechnicalReadme < Test::Unit::TestCase
7
8
  context 'generate sample graphs using readme options description' do
@@ -35,7 +36,7 @@ class TestTechnicalReadme < Test::Unit::TestCase
35
36
  #
36
37
  should 'create simplest graph' do
37
38
  return if DO_NOT_RUN_OLD_TESTS
38
- @tg = TechnicalGraph.new
39
+ @tg = TechnicalGraph.new({:drawer_class => README_RENDERED})
39
40
  @tg.add_layer(@simple_data_array)
40
41
  @tg.render
41
42
  file_name = 'samples/readme/01_simplest.png'
@@ -49,7 +50,7 @@ class TestTechnicalReadme < Test::Unit::TestCase
49
50
  #
50
51
  should 'create 2-layer graph' do
51
52
  return if DO_NOT_RUN_OLD_TESTS
52
- @tg = TechnicalGraph.new
53
+ @tg = TechnicalGraph.new({:drawer_class => README_RENDERED})
53
54
  @tg.add_layer(@simple_data_array)
54
55
  @tg.add_layer(@simple_data_array_b)
55
56
  @tg.render
@@ -70,6 +71,7 @@ class TestTechnicalReadme < Test::Unit::TestCase
70
71
  :x_max => 10,
71
72
  :y_min => -1,
72
73
  :y_max => 10,
74
+ :drawer_class => README_RENDERED
73
75
  })
74
76
  @tg.add_layer(@simple_data_array)
75
77
  @tg.render
@@ -89,7 +91,8 @@ class TestTechnicalReadme < Test::Unit::TestCase
89
91
  :x_max => 2,
90
92
  :y_min => 1,
91
93
  :y_max => 2,
92
- :xy_behaviour => :fixed
94
+ :xy_behaviour => :fixed,
95
+ :drawer_class => README_RENDERED
93
96
  })
94
97
  @tg.add_layer(@simple_data_array)
95
98
  @tg.render
@@ -109,6 +112,7 @@ class TestTechnicalReadme < Test::Unit::TestCase
109
112
  :y_axis_fixed_interval => false,
110
113
  :y_axis_count => 20,
111
114
  :x_axis_count => 20,
115
+ :drawer_class => README_RENDERED
112
116
  })
113
117
  @tg.add_layer(@simple_data_array)
114
118
  @tg.render
@@ -128,6 +132,7 @@ class TestTechnicalReadme < Test::Unit::TestCase
128
132
  :y_axis_fixed_interval => true,
129
133
  :y_axis_interval => 0.8,
130
134
  :x_axis_interval => 0.6,
135
+ :drawer_class => README_RENDERED
131
136
  })
132
137
  @tg.axis.x_axis_interval.should == 0.6
133
138
  @tg.axis.y_axis_interval.should == 0.8
@@ -155,7 +160,8 @@ class TestTechnicalReadme < Test::Unit::TestCase
155
160
  {
156
161
  :x_axis_label => 'parameter',
157
162
  :y_axis_label => 'value',
158
- :axis_label_font_size => 36
163
+ :axis_label_font_size => 36,
164
+ :drawer_class => README_RENDERED
159
165
  })
160
166
  @tg.add_layer(@simple_data_array)
161
167
  @tg.render
@@ -172,7 +178,8 @@ class TestTechnicalReadme < Test::Unit::TestCase
172
178
  return if DO_NOT_RUN_OLD_TESTS
173
179
  @tg = TechnicalGraph.new(
174
180
  {
175
- :truncate_string => "%.3f"
181
+ :truncate_string => "%.3f",
182
+ :drawer_class => README_RENDERED
176
183
  })
177
184
  @layer_params = {
178
185
  :value_labels => true
@@ -191,7 +198,8 @@ class TestTechnicalReadme < Test::Unit::TestCase
191
198
  return if DO_NOT_RUN_OLD_TESTS
192
199
  @tg = TechnicalGraph.new(
193
200
  {
194
- :truncate_string => "%.1f"
201
+ :truncate_string => "%.1f",
202
+ :drawer_class => README_RENDERED
195
203
  })
196
204
  @layer_params = {
197
205
  :value_labels => true
@@ -207,11 +215,12 @@ class TestTechnicalReadme < Test::Unit::TestCase
207
215
  end
208
216
 
209
217
  should 'test image size' do
210
- #return if DO_NOT_RUN_OLD_TESTS
218
+ return if DO_NOT_RUN_OLD_TESTS
211
219
  @tg = TechnicalGraph.new(
212
220
  {
213
221
  :width => 600,
214
- :height => 300
222
+ :height => 300,
223
+ :drawer_class => README_RENDERED,
215
224
  })
216
225
  @tg.add_layer(@simple_data_array)
217
226
  @tg.render
@@ -223,6 +232,294 @@ class TestTechnicalReadme < Test::Unit::TestCase
223
232
  File.exist?(file_name).should == true
224
233
  end
225
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
+
226
523
 
227
524
  end
228
525
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: technical_graph
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
8
+ - 5
9
9
  - 0
10
- version: 0.4.0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Aleksander Kwiatkowski
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-05 00:00:00 +01:00
18
+ date: 2011-11-12 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -29,11 +29,11 @@ dependencies:
29
29
  segments:
30
30
  - 0
31
31
  version: "0"
32
- name: rmagick
32
+ name: rasem
33
33
  version_requirements: *id001
34
34
  prerelease: false
35
35
  - !ruby/object:Gem::Dependency
36
- type: :runtime
36
+ type: :development
37
37
  requirement: &id002 !ruby/object:Gem::Requirement
38
38
  none: false
39
39
  requirements:
@@ -43,7 +43,7 @@ dependencies:
43
43
  segments:
44
44
  - 0
45
45
  version: "0"
46
- name: rasem
46
+ name: rdoc
47
47
  version_requirements: *id002
48
48
  prerelease: false
49
49
  - !ruby/object:Gem::Dependency