technical_graph 0.1.2 → 0.2.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.
- data/README.md +4 -3
- data/VERSION +1 -1
- data/lib/technical_graph/data_layer.rb +7 -2
- data/lib/technical_graph/graph_color_library.rb +52 -0
- data/test/test_technical_autocolor.rb +91 -0
- metadata +5 -3
data/README.md
CHANGED
@@ -123,17 +123,18 @@ size will be enlarged to maintain set distanced between axis.
|
|
123
123
|
|
124
124
|
Legend options:
|
125
125
|
|
126
|
-
* options[:legend] - draw legend
|
126
|
+
* options[:legend] - do you want to draw legend?, default false
|
127
127
|
* options[:legend_auto] - let legend position to be chosen by algorithm, default true
|
128
128
|
* options[:legend_width] - width used for setting proper distance while drawing on right, default 100, legend height is calculated
|
129
129
|
* options[:legend_margin] - graph margin used not to draw legend on border, default 50
|
130
|
-
* options[:legend_x] - legend X position, default 50
|
131
|
-
* options[:legend_y] - legend Y position, default 50
|
130
|
+
* options[:legend_x] - legend X position, used when options[:legend_auto] is false, default 50
|
131
|
+
* options[:legend_y] - legend Y position, used when options[:legend_auto] is false, default 50
|
132
132
|
|
133
133
|
|
134
134
|
Layer options Hash
|
135
135
|
------------------
|
136
136
|
|
137
|
+
* layer_options[:label] - label used in legend
|
137
138
|
* layer_options[:color] - color of graph layer, ex.: 'red', 'green', '#FFFF00'
|
138
139
|
* layer_options[:antialias] - use anti-aliasing for this, default false, override options[:layers_antialias]
|
139
140
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -1,5 +1,7 @@
|
|
1
1
|
#encoding: utf-8
|
2
2
|
|
3
|
+
require 'technical_graph/graph_color_library'
|
4
|
+
|
3
5
|
# Stores only data used for one layer
|
4
6
|
# Instances of this class are used elsewhere
|
5
7
|
# Stores also drawing parameters for one layer
|
@@ -9,6 +11,9 @@ class DataLayer
|
|
9
11
|
def initialize(d = [], options = { })
|
10
12
|
@data_params = options
|
11
13
|
|
14
|
+
@data_params[:color] ||= GraphColorLibrary.instance.get_color
|
15
|
+
@data_params[:label] ||= ''
|
16
|
+
|
12
17
|
# set data and append initial data
|
13
18
|
clear_data
|
14
19
|
append_data(d)
|
@@ -33,7 +38,7 @@ class DataLayer
|
|
33
38
|
|
34
39
|
# Color of
|
35
40
|
def color
|
36
|
-
return @data_params[:color]
|
41
|
+
return @data_params[:color]
|
37
42
|
end
|
38
43
|
|
39
44
|
def antialias
|
@@ -41,7 +46,7 @@ class DataLayer
|
|
41
46
|
end
|
42
47
|
|
43
48
|
def label
|
44
|
-
return @data_params[:label]
|
49
|
+
return @data_params[:label]
|
45
50
|
end
|
46
51
|
|
47
52
|
# Clear data
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
require 'singleton'
|
4
|
+
|
5
|
+
# Used for auto color grabber
|
6
|
+
|
7
|
+
class GraphColorLibrary
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
# http://www.imagemagick.org/script/color.php
|
11
|
+
BASIC_COLORS = [
|
12
|
+
'blue',
|
13
|
+
'red',
|
14
|
+
'green',
|
15
|
+
'purple'
|
16
|
+
]
|
17
|
+
|
18
|
+
ADDITIONAL_COLORS = [
|
19
|
+
'tomato',
|
20
|
+
'sienna1',
|
21
|
+
'chocolate2',
|
22
|
+
'DarkGoldenrod4',
|
23
|
+
'OliveDrab4',
|
24
|
+
'ForestGreen',
|
25
|
+
'turquoise',
|
26
|
+
'DarkCyan',
|
27
|
+
'CadetBlue4',
|
28
|
+
'DeepSkyBlue4',
|
29
|
+
'DodgerBlue2',
|
30
|
+
'CornflowerBlue',
|
31
|
+
'MidnightBlue',
|
32
|
+
'MediumPurple3',
|
33
|
+
'magenta4',
|
34
|
+
'orchid4',
|
35
|
+
'DeepPink3',
|
36
|
+
'PaleVioletRed4',
|
37
|
+
'firebrick3'
|
38
|
+
]
|
39
|
+
|
40
|
+
FAIL_COLOR = 'black'
|
41
|
+
|
42
|
+
def initialize
|
43
|
+
@colors = BASIC_COLORS + ADDITIONAL_COLORS.sort {rand}
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_color
|
47
|
+
color = @colors.shift
|
48
|
+
return FAIL_COLOR if color.nil?
|
49
|
+
return color
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestTechnicalAutocolor < 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
|
+
:label => 'first'
|
51
|
+
}
|
52
|
+
layer_params_b = {
|
53
|
+
:antialias => true,
|
54
|
+
:label => 'second'
|
55
|
+
}
|
56
|
+
layer_params_c = {
|
57
|
+
:antialias => true,
|
58
|
+
:label => 'third'
|
59
|
+
}
|
60
|
+
layer_params_d = {
|
61
|
+
:antialias => true,
|
62
|
+
:label => 'fourth'
|
63
|
+
}
|
64
|
+
layer_data_a = Array.new
|
65
|
+
layer_data_b = Array.new
|
66
|
+
layer_data_c = Array.new
|
67
|
+
layer_data_d = Array.new
|
68
|
+
(0..max).each do |i|
|
69
|
+
layer_data_a << { :x => -10.0 + i.to_f, :y => 10.0 * Math.cos(i.to_f * (4.0 * 3.14 / max.to_f)) }
|
70
|
+
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)) }
|
71
|
+
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)) }
|
72
|
+
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)) }
|
73
|
+
end
|
74
|
+
@tg.add_layer(layer_data_a, layer_params_a)
|
75
|
+
@tg.add_layer(layer_data_b, layer_params_b)
|
76
|
+
@tg.add_layer(layer_data_c, layer_params_c)
|
77
|
+
@tg.add_layer(layer_data_d, layer_params_d)
|
78
|
+
|
79
|
+
|
80
|
+
@tg.layers.last.data.size.should > 0
|
81
|
+
@tg.layers.size.should == 4
|
82
|
+
|
83
|
+
@tg.render
|
84
|
+
|
85
|
+
@tg.image_drawer.save_to_file('test_autocolor.png')
|
86
|
+
@tg.image_drawer.to_png.class.should == String
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
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:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 1
|
9
8
|
- 2
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Aleksander Kwiatkowski
|
@@ -123,9 +123,11 @@ files:
|
|
123
123
|
- lib/technical_graph.rb
|
124
124
|
- lib/technical_graph/data_layer.rb
|
125
125
|
- lib/technical_graph/graph_axis.rb
|
126
|
+
- lib/technical_graph/graph_color_library.rb
|
126
127
|
- lib/technical_graph/graph_data_processor.rb
|
127
128
|
- lib/technical_graph/graph_image_drawer.rb
|
128
129
|
- test/helper.rb
|
130
|
+
- test/test_technical_autocolor.rb
|
129
131
|
- test/test_technical_axis_enlarge.rb
|
130
132
|
- test/test_technical_graph.rb
|
131
133
|
- test/test_technical_graph_axis.rb
|