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.
@@ -1,10 +1,23 @@
1
1
  h1. How to use it
2
2
 
3
- p. All this examples are generated in test/test_technical_readme.rb.
3
+ p. All these examples are generated using spec/readme/technical_readme_spec.rb . There are some differences: filename is without path and is used rmagick renderer. Github has issues with SVG files.
4
4
 
5
5
 
6
6
 
7
7
 
8
+ h2. Default graph size
9
+
10
+ p. In this documentation I lowered default graph size so it looks nicer here. If you would like to do this insert something like this at the beginning of your code:
11
+
12
+ <pre>
13
+ <code>
14
+ GraphImageDrawer.width = 400
15
+ GraphImageDrawer.height = 300
16
+ </code>
17
+ </pre>
18
+
19
+
20
+
8
21
 
9
22
  h2. Simple graph
10
23
 
@@ -39,17 +52,16 @@ p. and add a layer.
39
52
  </code>
40
53
  </pre>
41
54
 
42
- p. We added data but we don't see anything. Now we have to render graph and save it to file.
55
+ p. We added data, but we don't see anything. Now we have to render graph and save it to file.
43
56
 
44
57
  <pre>
45
58
  <code>
46
- @tg.render
47
- file_name = 'samples/readme/01_simplest.png'
48
- @tg.image_drawer.save_to_file(file_name)
59
+ file_name = '01_simplest.png'
60
+ @tg.save_to_file(file_name)
49
61
  </code>
50
62
  </pre>
51
63
 
52
- p. And we got our first graph with one layer without any options changes, a bit raw.
64
+ p. And we got our first graph with one layer, without changing any options, a bit raw.
53
65
 
54
66
  !https://github.com/akwiatkowski/technical_graph/raw/master/samples/readme/01_simplest.png((01) simple graph)!
55
67
 
@@ -84,9 +96,9 @@ p. Maybe example with two layers?
84
96
  @tg = TechnicalGraph.new
85
97
  @tg.add_layer(@simple_data_array)
86
98
  @tg.add_layer(@simple_data_array_b)
87
- @tg.render
88
- file_name = 'samples/readme/02_two_layers.png'
89
- @tg.image_drawer.save_to_file(file_name)
99
+
100
+ file_name = '02_two_layers.png'
101
+ @tg.save_to_file(file_name)
90
102
  </code>
91
103
  </pre>
92
104
 
@@ -98,7 +110,7 @@ file_name = 'samples/readme/02_two_layers.png'
98
110
 
99
111
  h2. Ranges
100
112
 
101
- p. On default ranges are calculated automatically so all points are visible. You can override ranges setting.
113
+ p. By default ranges are calculated automatically so all points are visible. You can override ranges setting.
102
114
 
103
115
  <pre>
104
116
  <code>
@@ -120,16 +132,16 @@ p. On default ranges are calculated automatically so all points are visible. You
120
132
  })
121
133
 
122
134
  @tg.add_layer(@simple_data_array)
123
- @tg.render
124
- file_name = 'samples/readme/03_changed_ranges.png'
125
- @tg.image_drawer.save_to_file(file_name)
135
+
136
+ file_name = '03_changed_ranges.png'
137
+ @tg.save_to_file(file_name)
126
138
  </code>
127
139
  </pre>
128
140
 
129
141
  !https://github.com/akwiatkowski/technical_graph/raw/master/samples/readme/03_changed_ranges.png((03) changed ranges)!
130
142
 
131
143
 
132
- p. Keep in mind that ranges will be changed but any point of graph can enlarge ranges that all points will be visible, unless...
144
+ p. Keep in mind that ranges can be changed while rendering graph, but you can be sure - they can be only enlarged and all points will be visible. Unless...
133
145
 
134
146
 
135
147
 
@@ -168,9 +180,9 @@ Example:
168
180
  })
169
181
 
170
182
  @tg.add_layer(@simple_data_array)
171
- @tg.render
172
- file_name = 'samples/readme/04_changed_ranges_fixed.png'
173
- @tg.image_drawer.save_to_file(file_name)
183
+
184
+ file_name = '04_changed_ranges_fixed.png'
185
+ @tg.save_to_file(file_name)
174
186
  </code>
175
187
  </pre>
176
188
 
@@ -179,15 +191,14 @@ file_name = 'samples/readme/04_changed_ranges_fixed.png'
179
191
 
180
192
 
181
193
 
182
- h2. Axis interval - fixed count
194
+ h2. Axis interval - fixed quantity
183
195
 
184
196
  p. Axis can be calculated using two algorithms:
185
197
 
186
- # fixed interval - axis is every some distance,
187
- # fixed count - there is fixed amount of axis on graph.
198
+ # fixed interval - axis are placed every precise distance,
199
+ # fixed amount - there is fixed amount of axis on graph.
188
200
 
189
- p. Keep in mind that where is X (parameter) and Y (value) axis. If you want to set fixed amount you should set
190
- options[:x_axis_fixed_interval] and/or options[:y_axis_fixed_interval] to false, like in the example below.
201
+ p. Keep in mind that there is X (parameter) and Y (value) axis. If you want to set fixed amount, you should set options[:x_axis_fixed_interval] and/or options[:y_axis_fixed_interval] to false, like in the example below.
191
202
 
192
203
  <pre>
193
204
  <code>
@@ -209,9 +220,9 @@ options[:x_axis_fixed_interval] and/or options[:y_axis_fixed_interval] to false,
209
220
  })
210
221
 
211
222
  @tg.add_layer(@simple_data_array)
212
- @tg.render
213
- file_name = 'samples/readme/05_axis_fixed_amount.png'
214
- @tg.image_drawer.save_to_file(file_name)
223
+
224
+ file_name = '05_axis_fixed_amount.png'
225
+ @tg.save_to_file(file_name)
215
226
  </code>
216
227
  </pre>
217
228
 
@@ -227,8 +238,7 @@ p. Axis can be calculated using two algorithms:
227
238
  # fixed interval - axis is every some distance,
228
239
  # fixed count - there is fixed amount of axis on graph.
229
240
 
230
- p. Keep in mind that where is X (parameter) and Y (value) axis. If you want to set fixed amount you should set
231
- options[:x_axis_fixed_interval] and/or options[:y_axis_fixed_interval] to false, like in the example below.
241
+ p. Keep in mind that where is X (parameter) and Y (value) axis. If you want to set fixed interval you should set options[:x_axis_fixed_interval] and/or options[:y_axis_fixed_interval] to true, like in the example below.
232
242
 
233
243
  <pre>
234
244
  <code>
@@ -248,10 +258,10 @@ options[:x_axis_fixed_interval] and/or options[:y_axis_fixed_interval] to false,
248
258
  :y_axis_interval => 0.8,
249
259
  :x_axis_interval => 0.6,
250
260
  })
251
- @tg.add_layer(@simple_data_array)
252
- @tg.render
253
- file_name = 'samples/readme/06_axis_fixed_interval.png'
254
- @tg.image_drawer.save_to_file(file_name)
261
+ @tg.add_layer(@simple_data_array)
262
+
263
+ file_name = '06_axis_fixed_interval.png'
264
+ @tg.save_to_file(file_name)
255
265
  </code>
256
266
  </pre>
257
267
 
@@ -264,8 +274,7 @@ options[:x_axis_fixed_interval] and/or options[:y_axis_fixed_interval] to false,
264
274
 
265
275
  h2. Axis labels
266
276
 
267
- p. You can add label to X and Y axis. using options[:x_axis_label] and options[:y_axis_label], and you can choose font
268
- size using options[:axis_label_font_size].
277
+ p. You can add label to X and Y axis. using options[:x_axis_label] and options[:y_axis_label], and you can choose font size using options[:axis_label_font_size].
269
278
 
270
279
  <pre>
271
280
  <code>
@@ -282,12 +291,12 @@ size using options[:axis_label_font_size].
282
291
  {
283
292
  :x_axis_label => 'parameter',
284
293
  :y_axis_label => 'value',
285
- :axis_label_font_size => 36
294
+ :axis_label_font_size => 16
286
295
  })
287
- @@tg.add_layer(@simple_data_array)
288
- @tg.render
289
- file_name = 'samples/readme/07_axis_label.png'
290
- @tg.image_drawer.save_to_file(file_name)
296
+ @tg.add_layer(@simple_data_array)
297
+
298
+ file_name = '07_axis_label.png'
299
+ @tg.save_to_file(file_name)
291
300
  </code>
292
301
  </pre>
293
302
 
@@ -297,12 +306,9 @@ size using options[:axis_label_font_size].
297
306
 
298
307
  h2. Float numbers and value labels
299
308
 
300
- p. On default all float number are shown using 2 digits after dot. You can override it using options[:truncate_string]
301
- like in example below. If you want have values near graph points you can use proper layer options.
302
-
303
- p. Layers have also options, and it is useful for this example to turn on value labels.
309
+ p. By default all float number are shown with two digits after dot precision. You can override it using options[:truncate_string] like in example below. If you want to have values near graph points you can use proper layer options.
304
310
 
305
- layer_options[:value_labels]
311
+ p. Layers have also options, and it is useful for this example to turn on value labels to true - layer_options[:value_labels] = true .
306
312
 
307
313
  <pre>
308
314
  <code>
@@ -323,9 +329,9 @@ layer_options[:value_labels]
323
329
  :value_labels => true
324
330
  }
325
331
  @tg.add_layer(@float_data_array, @layer_params)
326
- @tg.render
327
- file_name = 'samples/readme/08a_truncate_string.png'
328
- @tg.image_drawer.save_to_file(file_name)
332
+
333
+ file_name = '08a_truncate_string.png'
334
+ @tg.save_to_file(file_name)
329
335
  </code>
330
336
  </pre>
331
337
 
@@ -350,9 +356,9 @@ file_name = 'samples/readme/08a_truncate_string.png'
350
356
  :value_labels => true
351
357
  }
352
358
  @tg.add_layer(@float_data_array, @layer_params)
353
- @tg.render
354
- file_name = 'samples/readme/08b_truncate_string.png'
355
- @tg.image_drawer.save_to_file(file_name)
359
+
360
+ file_name = '08b_truncate_string.png'
361
+ @tg.save_to_file(file_name)
356
362
  </code>
357
363
  </pre>
358
364
 
@@ -380,13 +386,13 @@ p. It would be very silly if this library had hard coded image size. You can cha
380
386
 
381
387
  @tg = TechnicalGraph.new(
382
388
  {
383
- :width => 600,
389
+ :width => 400,
384
390
  :height => 300
385
391
  })
386
392
  @tg.add_layer(@simple_data_array)
387
- @tg.render
388
- file_name = 'samples/readme/09_image_size.png'
389
- @tg.image_drawer.save_to_file(file_name)
393
+
394
+ file_name = '09_image_size.png'
395
+ @tg.save_to_file(file_name)
390
396
  </code>
391
397
  </pre>
392
398
 
@@ -396,20 +402,19 @@ file_name = 'samples/readme/09_image_size.png'
396
402
 
397
403
  h2. Colours
398
404
 
399
- p. If you think you have better artistic taste feel free to change colours used in graph :) Keep in mind that hatch
400
- color is not available in rasem renderer which is default now.
405
+ p. If you think you have better artistic taste feel free to change colours used in graph :) Keep in mind that hatch color is available only in rmagick renderer. Some short info about renderers is located in README.
401
406
 
402
- There are 3 color options per graph:
407
+ There are three color options per graph:
403
408
 
404
- # options[:background_color] - background color of image
409
+ * options[:background_color] - background color of image
405
410
 
406
- # options[:background_hatch_color] - background hatch color, used only in RMagick renderer
411
+ * options[:background_hatch_color] - background hatch color, used only in RMagick renderer
407
412
 
408
- # options[:axis_color] - color of axis, default #000000
413
+ * options[:axis_color] - color of axis, default #000000
409
414
 
410
- Ane 1 layer options
415
+ And one layer options:
411
416
 
412
- # layer_options[:color] - it is color of layer
417
+ * layer_options[:color] - it is color of layer
413
418
 
414
419
 
415
420
  <pre>
@@ -430,9 +435,9 @@ Ane 1 layer options
430
435
  :axis_color => '#FFFFFF'
431
436
  })
432
437
  @tg.add_layer(@simple_data_array, {:color => '#0000FF'})
433
- @tg.render
434
- file_name = 'samples/readme/10_colors.png'
435
- @tg.image_drawer.save_to_file(file_name)
438
+
439
+ file_name = '10_colors.png'
440
+ @tg.save_to_file(file_name)
436
441
  </code>
437
442
  </pre>
438
443
 
@@ -441,59 +446,14 @@ file_name = 'samples/readme/10_colors.png'
441
446
 
442
447
  h2. Image render
443
448
 
444
- p. From version 0.4.0 there are two render classes: Rasem and RMagick. Rasem is better for fast SVG rendering, but
445
- RMagick is better for bitmaps like PNG. Svg can be converted to bitmap using 'convert' command (ImageMagick). It is
446
- intended that Rasem will be default renderer, and RMagick renderer will be supported as long as possible.
447
-
448
- You can override default setting which is Rasem using:
449
+ p. There were two render classes since version 0.4.0: Rasem and RMagick. Now it is more complicated.
449
450
 
450
- <pre>
451
- <code>
452
- options[:drawer_class] = :rasem
453
- options[:drawer_class] = :rmagick
454
- </code>
455
- </pre>
456
-
457
- There is fallback - if you don't have install rmagick gem even if you set RMagick, technical_graph will use Rasem.
458
-
459
- <pre>
460
- <code>
461
- @simple_data_array = [
462
- { :x => 0, :y => 0 },
463
- { :x => 1, :y => 1 },
464
- { :x => 2, :y => 2 },
465
- { :x => 3, :y => 2 },
466
- { :x => 4, :y => 1 },
467
- { :x => 5, :y => 0 },
468
- ]
469
-
470
- @tg = TechnicalGraph.new(
471
- {
472
- :drawer_class => :rmagick
473
- })
474
- @tg.add_layer(@simple_data_array)
475
- @tg.render
476
- file_name = 'samples/readme/11_renderer_rmagick.png'
477
- @tg.image_drawer.save_to_file(file_name)
478
-
479
- @tg = TechnicalGraph.new(
480
- {
481
- :drawer_class => :rasem
482
- })
483
- @tg.add_layer(@simple_data_array)
484
- @tg.render
485
- file_name = 'samples/readme/11_renderer_rasem.png'
486
- @tg.image_drawer.save_to_file(file_name)
487
- </code>
488
- </pre>
489
-
490
- !https://github.com/akwiatkowski/technical_graph/raw/master/samples/readme/11_renderer_rmagick.png((11) RMagick)!
491
- !https://github.com/akwiatkowski/technical_graph/raw/master/samples/readme/11_renderer_rasem.png((11) Rasem)!
451
+ p. If you want SVG file you a very happy man, everything works and SVG looks good. If you want PNG you can use chunky_png but you are missing some important features like texts, dots, ... You can install rmagick and technical_graph will use power of rmagick to create very nice PNG graphs.
492
452
 
493
453
 
494
454
  h2. Anti-aliasing
495
455
 
496
- p. Anti-aliasing is only available using RMagick renderer. On default it is disabled.
456
+ p. Anti-aliasing is only available using RMagick renderer. By default it is disabled.
497
457
 
498
458
  <pre>
499
459
  <code>
@@ -520,9 +480,9 @@ Sample graph without anti-aliasing has 11kB, with 69kB. Does size matter to you?
520
480
  :drawer_class => :rmagick
521
481
  })
522
482
  @tg.add_layer(@simple_data_array)
523
- @tg.render
524
- file_name = 'samples/readme/12_aa_true.png'
525
- @tg.image_drawer.save_to_file(file_name)
483
+
484
+ file_name = '12_aa_true.png'
485
+ @tg.save_to_file(file_name)
526
486
 
527
487
  # only for size comparison
528
488
  @tg = TechnicalGraph.new(
@@ -531,13 +491,18 @@ file_name = 'samples/readme/12_aa_true.png'
531
491
  :drawer_class => :rmagick
532
492
  })
533
493
  @tg.add_layer(@simple_data_array)
534
- @tg.render
535
- file_name = 'samples/readme/12_aa_false.png'
536
- @tg.image_drawer.save_to_file(file_name)
494
+
495
+ file_name = '12_aa_false.png'
496
+ @tg.save_to_file(file_name)
537
497
  </code>
538
498
  </pre>
539
499
 
500
+ p. With anti-alias
501
+
540
502
  !https://github.com/akwiatkowski/technical_graph/raw/master/samples/readme/12_aa_true.png((12) Anti-aliasing enabled)!
503
+
504
+ p. Without anti-alias
505
+
541
506
  !https://github.com/akwiatkowski/technical_graph/raw/master/samples/readme/12_aa_false.png((12) Anti-aliasing disabled)!
542
507
 
543
508
 
@@ -546,13 +511,11 @@ h2. Font size
546
511
 
547
512
  p. You can set various font sizes.
548
513
 
549
- # options[:layers_font_size] - size of font used for values in graph, keep in mind that layer_options[:value_labels]
550
- must be enabled to see any result
514
+ * options[:layers_font_size] - size of font used for values in graph, keep in mind that layer_options[:value_labels] must be enabled to see any result
551
515
 
552
- # options[:axis_font_size] - size of font used in axis
516
+ * options[:axis_font_size] - size of font used in axis
553
517
 
554
- # options[:axis_label_font_size] - size of font used in options[:x_axis_label] and options[:y_axis_label], to see
555
- any result at least one of them must be set
518
+ * options[:axis_label_font_size] - size of font used in options[:x_axis_label] and options[:y_axis_label], to see any result at least one of them must be set
556
519
 
557
520
 
558
521
  <pre>
@@ -572,12 +535,12 @@ p. You can set various font sizes.
572
535
  :y_axis_label => 'value',
573
536
  :layers_font_size => 14,
574
537
  :axis_font_size => 18,
575
- :axis_label_font_size => 48
538
+ :axis_label_font_size => 24
576
539
  })
577
540
  @tg.add_layer(@simple_data_array, {:value_labels => true})
578
- @tg.render
579
- file_name = 'samples/readme/13_font_sizes.png'
580
- @tg.image_drawer.save_to_file(file_name)
541
+
542
+ file_name = '13_font_sizes.png'
543
+ @tg.save_to_file(file_name)
581
544
  </code>
582
545
  </pre>
583
546
 
@@ -587,17 +550,15 @@ file_name = 'samples/readme/13_font_sizes.png'
587
550
 
588
551
  h2. Legend
589
552
 
590
- p. If you want to use legend you only have to set labels for layers and turn legend enabled by using:
553
+ p. If you want to use legend you only have to set labels for layers and enable it by using:
591
554
 
592
- # options[:legend] - turn on legend, on default auto position mode is enabled
555
+ * options[:legend] - set to true to enable legend, by default auto position mode is enabled
593
556
 
594
- # layer_options[:label] - label used for legend
557
+ * layer_options[:label] - label used for legend
595
558
 
596
- Position of legend is calculated automatic - 8 corner places are checked for distance to all graph points. Point
597
- which has longest distance is used for legend position.
559
+ p. Position of legend is calculated magically - 8 corner places are checked for distance to all graph points. Point which has longest distance to graph points is used for legend position.
598
560
 
599
- Every layer has own color which can be set by user using code below. If you don't set there is bank of some fixed colors
600
- and random color generator.
561
+ p. Every layer has color which can be set by user using code below. If you don't set there is a bank of some fixed colors and random color generator.
601
562
 
602
563
  <pre>
603
564
  <code>
@@ -625,18 +586,19 @@ Graph sample code:
625
586
  {
626
587
  :legend => true
627
588
  })
628
- @tg.add_layer(@simple_data_array, {:label => 'simple', :color => '#FFFF00'})
629
- @tg.add_layer(@simple_data_array_second, {:label => 'offset', :color => '#00FFFF'})
630
- @tg.add_layer(@simple_data_array_third, {:label => 'scaled', :color => '#FF00FF'})
631
- @tg.render
632
- file_name = 'samples/readme/14_simple_legend.png'
633
- @tg.image_drawer.save_to_file(file_name)
589
+ @tg.add_layer(@simple_data_array, {:label => 'simple', :color => '#AA7722'})
590
+ @tg.add_layer(@simple_data_array_second, {:label => 'offset', :color => '#00AA55'})
591
+ @tg.add_layer(@simple_data_array_third, {:label => 'scaled', :color => '#3322BB'})
592
+
593
+ file_name = '14_simple_legend.png'
594
+ @tg.save_to_file(file_name)
634
595
  </code>
635
596
  </pre>
636
597
 
637
598
  !https://github.com/akwiatkowski/technical_graph/raw/master/samples/readme/14_simple_legend.png((14) Legend)!
638
599
 
639
- You can turn off auto position if you like:
600
+
601
+ p. If you like you can turn off auto position:
640
602
 
641
603
  <pre>
642
604
  <code>
@@ -648,29 +610,28 @@ options[:legend_y] = 100
648
610
 
649
611
  There are also other useful parameters
650
612
 
651
- # options[:legend_width] - width of longest label in pixels used for setting proper distance while drawing on right border
652
- default 100 and is enlarged auto. using font size
613
+ * options[:legend_width] - width of longest label in pixels used for setting proper distance while drawing on right border, default is 100 and it is enlarged auto. using font size
653
614
 
654
- # options[:legend_margin] - graph margin used not to draw legend on border, default 50
615
+ * options[:legend_margin] - graph margin used not to draw legend on border, default 50
655
616
 
656
617
 
657
618
 
658
619
  h2. Smoothing
659
620
 
660
- p. Useful when origin of data is a bit noisy. For best results you can add two layers: one raw, and second with smoothing.
621
+ p. Useful when origin of data is a bit noisy. For best results you can add two layers: one raw, and second with smoothing enabled.
661
622
 
662
623
  <pre>
663
624
  <code>
664
625
  @tg = TechnicalGraph.new(
665
626
  {
666
- :width => 2000,
667
- :height => 1500,
627
+ :width => 1000,
628
+ :height => 750,
668
629
  :legend => true,
669
630
  :x_axis_label => "Parameter",
670
631
  :y_axis_label => "Value"
671
632
  }
672
633
  )
673
- max = 250 #2000
634
+ max = 100
674
635
 
675
636
  @layer_data = Array.new
676
637
  (0..max).each do |i|
@@ -708,9 +669,9 @@ end
708
669
  @tg.add_layer(@layer_data.clone, @layer_params_b)
709
670
  @tg.add_layer(@layer_data.clone, @layer_params_e)
710
671
 
711
- @tg.render
712
- file_name = 'samples/readme/15_smoothing.png'
713
- @tg.image_drawer.save_to_file(file_name)
672
+
673
+ file_name = '15_smoothing.png'
674
+ @tg.save_to_file(file_name)
714
675
  </code>
715
676
  </pre>
716
677
 
@@ -720,8 +681,7 @@ file_name = 'samples/readme/15_smoothing.png'
720
681
 
721
682
  h2. Noise removal
722
683
 
723
- p. Useful when origin of data is a bit noisy. For best results you can add two layers: one raw, and second with noise removal.
724
- Can be used with smoothing.
684
+ p. Useful when origin of data is a bit noisy. For best results you can add two layers: one raw, and second with noise removal. It can be used with smoothing.
725
685
 
726
686
  <pre>
727
687
  <code>
@@ -779,9 +739,9 @@ end
779
739
  @tg.add_layer(@layer_data.clone, @layer_params_b)
780
740
  @tg.add_layer(@layer_data.clone, @layer_params_e)
781
741
 
782
- @tg.render
783
- file_name = 'samples/readme/16_noise_removal.png'
784
- @tg.image_drawer.save_to_file(file_name)
742
+
743
+ file_name = '16_noise_removal.png'
744
+ @tg.save_to_file(file_name)
785
745
  </code>
786
746
  </pre>
787
747
 
@@ -793,22 +753,32 @@ file_name = 'samples/readme/16_noise_removal.png'
793
753
 
794
754
  h2. Axis interval enlargement
795
755
 
796
- p. In case of large amount of data axis can be squeezed and graph is unreadable. You can set axis enlargement to kick in
797
- in these situations. When distance between axis is lower than set in options[:x_axis_min_distance] or
798
- options[:y_axis_min_distance] image dimensions are enlarged to maintain proper axis distances.
756
+ p. In case of large amount of data axis can be squeezed and graph is unreadable. You can set axis enlargement to help in these situations. When distance between axis is lower than set in options[:x_axis_min_distance] or options[:y_axis_min_distance] image dimensions are enlarged to maintain proper axis distances. There is default distance for X and Y axis of 30 pixels.
757
+
758
+ p. Possible options:
759
+
760
+ * options[:axis_density_enlarge_image] - enable both axis (X, Y)
761
+
762
+ * options[:x_axis_density_enlarge_image] - enable only X axis
763
+
764
+ * options[:y_axis_density_enlarge_image] - enable only Y axis
765
+
766
+ * options[:x_axis_min_distance] - minimum distance for X axis
767
+
768
+ * options[:y_axis_min_distance] - minimum distance for Y axis
799
769
 
800
770
  <pre>
801
771
  <code>
802
772
  @tg = TechnicalGraph.new(
803
773
  {
804
- :axis_density_enlarge_image => true,
805
- :x_axis_min_distance => 500,
774
+ :x_axis_density_enlarge_image => true,
775
+ :x_axis_min_distance => 30,
806
776
  :x_axis_interval => 1.0,
807
777
  :x_axis_fixed_interval => true,
808
- :width => 400
778
+ :width => 100
809
779
  }
810
780
  )
811
- max = 250
781
+ max = 20
812
782
 
813
783
  @layer_data = Array.new
814
784
  (0..max).each do |i|
@@ -819,18 +789,121 @@ end
819
789
 
820
790
  @tg.add_layer(@layer_data)
821
791
 
822
- @tg.render
823
- file_name = 'samples/readme/17_axis_enlargement.png'
824
- @tg.image_drawer.save_to_file(file_name)
792
+
793
+ file_name = '17_axis_enlargement.png'
794
+ @tg.save_to_file(file_name)
825
795
  </code>
826
796
  </pre>
827
797
 
828
798
  !https://github.com/akwiatkowski/technical_graph/raw/master/samples/readme/17_axis_enlargement.png((17) Axis enlargement)!
829
799
 
830
800
 
831
- h2. TODO
832
801
 
833
- # Axis density checking algorithm - more info
834
- # Smoother - parameters
835
- # Noise removal - para
836
- # Adjusting axis to zero
802
+ h2. Advanced smoothing parameters
803
+
804
+ p. The best way is to experiment with all parameters and choose which fit best.
805
+
806
+ p. Possible options:
807
+
808
+ * layer_options[:simple_smoother] - set true to enable
809
+
810
+ * layer_options[:simple_smoother_level] - higher -> more smooth
811
+
812
+ * layer_options[:simple_smoother_x] - use X offset smoothing, slower but a little better quality
813
+
814
+
815
+ <pre>
816
+ <code>
817
+ @tg = TechnicalGraph.new(
818
+ {
819
+ :width => 1600,
820
+ :height => 1200,
821
+ :legend => true,
822
+ :x_axis_label => "Parameter",
823
+ :y_axis_label => "Value",
824
+ :drawer_class => README_RENDERED,
825
+ }
826
+ )
827
+ max = 200
828
+
829
+ @layer_data = Array.new
830
+ (0..max).each do |i|
831
+ x = -10.0 + (20.0 * i.to_f / max.to_f)
832
+ y = 10.0 * Math.cos(i.to_f * (2.0 * 3.14 / max.to_f))
833
+
834
+ y += rand * 2.0
835
+
836
+ @layer_data << { :x => x, :y => y }
837
+ end
838
+
839
+ # adding simple layer
840
+ @layer_params = {
841
+ :label => 'raw',
842
+ :value_labels => false
843
+ }
844
+
845
+ @layer_params_smooth_wox = @layer_params.clone.merge(
846
+ {
847
+ :label => 'without X smoothing',
848
+ :simple_smoother => true,
849
+ :simple_smoother_level => 5,
850
+ :simple_smoother_strategy => :gauss,
851
+ :simple_smoother_x => false,
852
+ }
853
+ )
854
+
855
+ @layer_params_smooth_wx = @layer_params.clone.merge(
856
+ {
857
+ :label => 'with X smoothing',
858
+ :simple_smoother => true,
859
+ :simple_smoother_level => 5,
860
+ :simple_smoother_x => true,
861
+ }
862
+ )
863
+
864
+ @tg.add_layer(@layer_data.clone, @layer_params_smooth_wox)
865
+ @tg.add_layer(@layer_data.clone, @layer_params_smooth_wx)
866
+ @tg.add_layer(@layer_data.clone, @layer_params)
867
+
868
+ file_name = '18_adv_smoothing.png'
869
+ @tg.save_to_file(file_name)
870
+ </code>
871
+ </pre>
872
+
873
+ !https://github.com/akwiatkowski/technical_graph/raw/master/samples/readme/18_adv_smoothing.png((18) Smoothing 2)!
874
+
875
+
876
+
877
+
878
+
879
+ h2. Adjusting axis to zero
880
+
881
+ p. Axis are placed automatically. It would look better if axis were located on zeroes. Fortunately it is enabled by default, but check out how it would look.
882
+
883
+ p. Possible options:
884
+
885
+ * layer_options[:adjust_axis_to_zero] - set true to enable
886
+
887
+ <pre>
888
+ <code>
889
+ @tg = TechnicalGraph.new({:adjust_axis_to_zero => false})
890
+ max = 200
891
+
892
+ @layer_data = Array.new
893
+ (0..max).each do |i|
894
+ x = -10.0 + (20.0 * i.to_f / max.to_f) + 0.11
895
+ y = 10.0 * Math.cos(i.to_f * (2.0 * 3.14 / max.to_f))
896
+
897
+ y += rand * 2.0
898
+
899
+ @layer_data << { :x => x, :y => y }
900
+ end
901
+
902
+ @tg.add_layer(@layer_data)
903
+
904
+ file_name = '19_axis_not_adjust.png'
905
+ @tg.save_to_file(file_name)
906
+ </code>
907
+ </pre>
908
+
909
+ !https://github.com/akwiatkowski/technical_graph/raw/master/samples/readme/19_axis_not_adjust.png((19) Not adjusted axis)!