technical_graph 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -0
- data/VERSION +1 -1
- data/lib/technical_graph/graph_axis.rb +47 -0
- data/lib/technical_graph/graph_data_processor.rb +7 -0
- data/lib/technical_graph/graph_image_drawer.rb +13 -0
- data/technical_graph.gemspec +3 -2
- data/test/test_technical_axis_enlarge.rb +68 -0
- data/test/test_technical_simple_graph.rb +1 -1
- metadata +5 -4
data/README.md
CHANGED
@@ -114,6 +114,12 @@ Font size:
|
|
114
114
|
* options[:axis_font_size] - size of font used in axis
|
115
115
|
* options[:axis_label_font_size] - size of font used in options[:x_axis_label] and options[:y_axis_label]
|
116
116
|
|
117
|
+
Sometime because of axis options and large amount of data, axis can be put densely on graph. Turning this option graph
|
118
|
+
size will be enlarged to maintain set distanced between axis.
|
119
|
+
|
120
|
+
* options[:axis_density_enlarge_image] - turn this options on
|
121
|
+
* options[:x_axis_min_distance] - minimum distance between X axis, default 30 pixels
|
122
|
+
* options[:y_axis_min_distance] - minimum distance between X axis, default 50 pixels
|
117
123
|
|
118
124
|
|
119
125
|
Layer options Hash
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -74,6 +74,53 @@ class GraphAxis
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
+
# Enlarge image to maintain proper axis density
|
78
|
+
def axis_distance_image_enlarge
|
79
|
+
if options[:axis_density_enlarge_image]
|
80
|
+
x_axis_distance_image_enlarge
|
81
|
+
y_axis_distance_image_enlarge
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Enlarge image to maintain proper axis density
|
86
|
+
def x_axis_distance_image_enlarge
|
87
|
+
a = parameter_axis
|
88
|
+
# must be at least 2 axis
|
89
|
+
return if a.size < 2
|
90
|
+
|
91
|
+
ax = a[0]
|
92
|
+
ax = image_drawer.calc_bitmap_y(ax).round
|
93
|
+
bx = a[1]
|
94
|
+
bx = image_drawer.calc_bitmap_y(bx).round
|
95
|
+
|
96
|
+
axis_distance = (bx - ax).abs
|
97
|
+
|
98
|
+
if axis_distance < options[:x_axis_min_distance]
|
99
|
+
# enlarging image
|
100
|
+
options[:old_width] = options[:width]
|
101
|
+
options[:width] *= (options[:x_axis_min_distance] / axis_distance).ceil
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# Enlarge image to maintain proper axis density
|
106
|
+
def y_axis_distance_image_enlarge
|
107
|
+
a = value_axis
|
108
|
+
# must be at least 2 axis
|
109
|
+
return if a.size < 2
|
110
|
+
|
111
|
+
ay = a[0]
|
112
|
+
ay = image_drawer.calc_bitmap_y(ay).round
|
113
|
+
by = a[1]
|
114
|
+
by = image_drawer.calc_bitmap_y(by).round
|
115
|
+
|
116
|
+
axis_distance = (by - ay).abs
|
117
|
+
|
118
|
+
if axis_distance < options[:y_axis_min_distance]
|
119
|
+
# enlarging image
|
120
|
+
options[:old_height] = options[:height]
|
121
|
+
options[:height] *= (options[:y_axis_min_distance] / axis_distance).ceil
|
122
|
+
end
|
123
|
+
end
|
77
124
|
|
78
125
|
# Render axis on image
|
79
126
|
def render_on_image(image)
|
@@ -43,6 +43,13 @@ class GraphDataProcessor
|
|
43
43
|
options[:x_axis_fixed_interval] = true if options[:x_axis_fixed_interval].nil?
|
44
44
|
options[:y_axis_fixed_interval] = true if options[:y_axis_fixed_interval].nil?
|
45
45
|
|
46
|
+
# when set enlarge image so axis are located in sensible distance between themselves
|
47
|
+
options[:axis_density_enlarge_image] = false if options[:x_axis_fixed_interval].nil?
|
48
|
+
# distance in pixels
|
49
|
+
options[:x_axis_min_distance] ||= 30
|
50
|
+
# distance in pixels
|
51
|
+
options[:y_axis_min_distance] ||= 50
|
52
|
+
|
46
53
|
# default truncate string used for rendering numbers
|
47
54
|
options[:truncate_string] ||= "%.2f"
|
48
55
|
|
@@ -33,6 +33,11 @@ class GraphImageDrawer
|
|
33
33
|
@technical_graph.data_processor
|
34
34
|
end
|
35
35
|
|
36
|
+
# Axis processing
|
37
|
+
def graph_axis
|
38
|
+
@technical_graph.axis
|
39
|
+
end
|
40
|
+
|
36
41
|
def truncate_string
|
37
42
|
options[:truncate_string]
|
38
43
|
end
|
@@ -103,8 +108,16 @@ class GraphImageDrawer
|
|
103
108
|
return (offset.to_f * height.to_f) / l.to_f
|
104
109
|
end
|
105
110
|
|
111
|
+
# Everything that must be done before creating image
|
112
|
+
def pre_image_create_calculations
|
113
|
+
# check axis density and enlarge if this option is on
|
114
|
+
graph_axis.axis_distance_image_enlarge
|
115
|
+
end
|
116
|
+
|
106
117
|
# Create background image
|
107
118
|
def crate_blank_graph_image
|
119
|
+
pre_image_create_calculations
|
120
|
+
|
108
121
|
@image = Magick::ImageList.new
|
109
122
|
@image.new_image(
|
110
123
|
width,
|
data/technical_graph.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{technical_graph}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Aleksander Kwiatkowski"]
|
12
|
-
s.date = %q{2011-09
|
12
|
+
s.date = %q{2011-10-09}
|
13
13
|
s.description = %q{Purpose of this gem is to create neat, simple, technical graphs. This is alternative to most new libraries which create small, candy graphs using JavaScript.}
|
14
14
|
s.email = %q{bobikx@poczta.fm}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -40,6 +40,7 @@ Gem::Specification.new do |s|
|
|
40
40
|
"samples/home_io_batt_voltage.png",
|
41
41
|
"technical_graph.gemspec",
|
42
42
|
"test/helper.rb",
|
43
|
+
"test/test_technical_axis_enlarge.rb",
|
43
44
|
"test/test_technical_graph.rb",
|
44
45
|
"test/test_technical_graph_axis.rb",
|
45
46
|
"test/test_technical_simple_graph.rb"
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestTechnicalAxisEnlarge < Test::Unit::TestCase
|
4
|
+
context 'initial options' do
|
5
|
+
should 'enlarge image' 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 => 8,
|
18
|
+
:axis_font_size => 8,
|
19
|
+
:axis_label_font_size => 20,
|
20
|
+
|
21
|
+
:x_axis_count => 50,
|
22
|
+
:y_axis_count => 50,
|
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 => 800,
|
34
|
+
:height => 600,
|
35
|
+
|
36
|
+
:axis_density_enlarge_image => true,
|
37
|
+
:x_axis_min_distance => 50,
|
38
|
+
:y_axis_min_distance => 50,
|
39
|
+
}
|
40
|
+
)
|
41
|
+
|
42
|
+
max = 50
|
43
|
+
|
44
|
+
# adding simple layer
|
45
|
+
layer_params = {
|
46
|
+
:antialias => false,
|
47
|
+
#:color => 'red'
|
48
|
+
:color => '#FFFF00'
|
49
|
+
}
|
50
|
+
layer_data = Array.new
|
51
|
+
(0..max).each do |i|
|
52
|
+
layer_data << { :x => -10.0 + i.to_f, :y => 10.0 * Math.cos(i.to_f * (4.0 * 3.14 / max.to_f)) }
|
53
|
+
end
|
54
|
+
@tg.add_layer(layer_data, layer_params)
|
55
|
+
# should be added
|
56
|
+
@tg.layers.last.data.size.should > 0
|
57
|
+
# checking ranger for layer
|
58
|
+
|
59
|
+
@tg.render
|
60
|
+
|
61
|
+
@tg.image_drawer.save_to_file('test_axis_enlarge.png')
|
62
|
+
@tg.image_drawer.save_to_file('test_axis_enlarge.svg')
|
63
|
+
@tg.image_drawer.to_png.class.should == String
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
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: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
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-09
|
18
|
+
date: 2011-10-09 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -151,6 +151,7 @@ files:
|
|
151
151
|
- samples/home_io_batt_voltage.png
|
152
152
|
- technical_graph.gemspec
|
153
153
|
- test/helper.rb
|
154
|
+
- test/test_technical_axis_enlarge.rb
|
154
155
|
- test/test_technical_graph.rb
|
155
156
|
- test/test_technical_graph_axis.rb
|
156
157
|
- test/test_technical_simple_graph.rb
|