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
data/DOCUMENTATION.textile
CHANGED
@@ -1,10 +1,23 @@
|
|
1
1
|
h1. How to use it
|
2
2
|
|
3
|
-
p. All
|
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
|
-
|
47
|
-
file_name
|
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
|
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
|
-
|
88
|
-
file_name = '
|
89
|
-
@tg.
|
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.
|
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
|
-
|
124
|
-
file_name = '
|
125
|
-
@tg.
|
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
|
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
|
-
|
172
|
-
file_name = '
|
173
|
-
@tg.
|
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
|
194
|
+
h2. Axis interval - fixed quantity
|
183
195
|
|
184
196
|
p. Axis can be calculated using two algorithms:
|
185
197
|
|
186
|
-
# fixed interval - axis
|
187
|
-
# fixed
|
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
|
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
|
-
|
213
|
-
file_name = '
|
214
|
-
@tg.
|
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
|
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
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
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 =>
|
294
|
+
:axis_label_font_size => 16
|
286
295
|
})
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
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.
|
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
|
-
|
327
|
-
file_name = '
|
328
|
-
@tg.
|
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
|
-
|
354
|
-
file_name = '
|
355
|
-
@tg.
|
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 =>
|
389
|
+
:width => 400,
|
384
390
|
:height => 300
|
385
391
|
})
|
386
392
|
@tg.add_layer(@simple_data_array)
|
387
|
-
|
388
|
-
file_name = '
|
389
|
-
@tg.
|
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
|
407
|
+
There are three color options per graph:
|
403
408
|
|
404
|
-
|
409
|
+
* options[:background_color] - background color of image
|
405
410
|
|
406
|
-
|
411
|
+
* options[:background_hatch_color] - background hatch color, used only in RMagick renderer
|
407
412
|
|
408
|
-
|
413
|
+
* options[:axis_color] - color of axis, default #000000
|
409
414
|
|
410
|
-
|
415
|
+
And one layer options:
|
411
416
|
|
412
|
-
|
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
|
-
|
434
|
-
file_name = '
|
435
|
-
@tg.
|
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.
|
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
|
-
|
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.
|
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
|
-
|
524
|
-
file_name = '
|
525
|
-
@tg.
|
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
|
-
|
535
|
-
file_name = '
|
536
|
-
@tg.
|
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
|
-
|
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
|
-
|
516
|
+
* options[:axis_font_size] - size of font used in axis
|
553
517
|
|
554
|
-
|
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 =>
|
538
|
+
:axis_label_font_size => 24
|
576
539
|
})
|
577
540
|
@tg.add_layer(@simple_data_array, {:value_labels => true})
|
578
|
-
|
579
|
-
file_name = '
|
580
|
-
@tg.
|
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
|
553
|
+
p. If you want to use legend you only have to set labels for layers and enable it by using:
|
591
554
|
|
592
|
-
|
555
|
+
* options[:legend] - set to true to enable legend, by default auto position mode is enabled
|
593
556
|
|
594
|
-
|
557
|
+
* layer_options[:label] - label used for legend
|
595
558
|
|
596
|
-
Position of legend is calculated
|
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
|
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 => '#
|
629
|
-
@tg.add_layer(@simple_data_array_second, {:label => 'offset', :color => '#
|
630
|
-
@tg.add_layer(@simple_data_array_third, {:label => 'scaled', :color => '#
|
631
|
-
|
632
|
-
file_name = '
|
633
|
-
@tg.
|
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
|
-
|
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
|
-
|
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
|
-
|
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 =>
|
667
|
-
:height =>
|
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 =
|
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
|
-
|
712
|
-
file_name = '
|
713
|
-
@tg.
|
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
|
-
|
783
|
-
file_name = '
|
784
|
-
@tg.
|
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
|
797
|
-
|
798
|
-
|
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
|
-
:
|
805
|
-
:x_axis_min_distance =>
|
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 =>
|
778
|
+
:width => 100
|
809
779
|
}
|
810
780
|
)
|
811
|
-
max =
|
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
|
-
|
823
|
-
file_name = '
|
824
|
-
@tg.
|
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
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
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)!
|