technical_graph 0.5.1 → 0.6.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.
@@ -10,10 +10,10 @@ class GraphColorLibrary
10
10
  # rock solid colors
11
11
  # http://www.imagemagick.org/script/color.php
12
12
  BASIC_COLORS = [
13
- 'blue',
14
- 'red',
15
- 'green',
16
- 'purple'
13
+ '#0000FF', #'blue',
14
+ '#FF0000', #'red',
15
+ '#00FF00', #'green',
16
+ '#FF00FF', #'purple'
17
17
  ]
18
18
 
19
19
  # other random picked up, SVG need #RGB and I'm too lazy :]
@@ -39,7 +39,7 @@ class GraphColorLibrary
39
39
  #'firebrick3'
40
40
  ]
41
41
 
42
- FAIL_COLOR = 'black'
42
+ FAIL_COLOR = '#000000' #'black'
43
43
 
44
44
  def initialize
45
45
  reset
@@ -49,10 +49,12 @@ class GraphDataProcessor
49
49
 
50
50
  # when set enlarge image so axis are located in sensible distance between themselves
51
51
  options[:axis_density_enlarge_image] = false if options[:axis_density_enlarge_image].nil?
52
+ options[:x_axis_density_enlarge_image] = false if options[:x_axis_density_enlarge_image].nil?
53
+ options[:y_axis_density_enlarge_image] = false if options[:y_axis_density_enlarge_image].nil?
52
54
  # distance in pixels
53
55
  options[:x_axis_min_distance] ||= 30
54
56
  # distance in pixels
55
- options[:y_axis_min_distance] ||= 50
57
+ options[:y_axis_min_distance] ||= 30
56
58
 
57
59
  # default truncate string used for rendering numbers
58
60
  options[:truncate_string] ||= "%.2f"
@@ -17,26 +17,26 @@ class GraphImageDrawer
17
17
 
18
18
  # Which type of drawing class use?
19
19
  def drawing_class
20
- if options[:drawer_class] == :rmagick and rmagick_installed?
21
- require 'technical_graph/graph_image_drawer_rmagick'
22
- return GraphImageDrawerRmagick
23
- end
24
-
25
20
  if options[:drawer_class] == :rasem
26
21
  require 'technical_graph/graph_image_drawer_rasem'
27
22
  return GraphImageDrawerRasem
28
23
  end
29
24
 
25
+ if options[:drawer_class] == :chunky_png
26
+ require 'technical_graph/graph_image_drawer_chunky'
27
+ return GraphImageDrawerChunky
28
+ end
29
+
30
+ if options[:drawer_class] == :rmagick and rmagick_installed?
31
+ require 'technical_graph/graph_image_drawer_rmagick'
32
+ return GraphImageDrawerRmagick
33
+ end
34
+
30
35
  # default
31
36
  require 'technical_graph/graph_image_drawer_rasem'
32
37
  return GraphImageDrawerRasem
33
38
  end
34
39
 
35
- # Check if rmagick is installed
36
- def rmagick_installed?
37
- return Gem.source_index.find_name('rmagick').size > 0
38
- end
39
-
40
40
  # Best output image format, used for testing
41
41
  def best_output_format
42
42
  @technical_graph.best_output_format
@@ -81,6 +81,9 @@ class GraphImageDrawer
81
81
  DEFAULT_WIDTH = 1600
82
82
  DEFAULT_HEIGHT = 1200
83
83
 
84
+ @@default_width = DEFAULT_WIDTH
85
+ @@default_height = DEFAULT_HEIGHT
86
+
84
87
  def initialize(technical_graph)
85
88
  @technical_graph = technical_graph
86
89
 
@@ -90,8 +93,8 @@ class GraphImageDrawer
90
93
  #options[:drawer_class] ||= :rmagick
91
94
  options[:drawer_class] ||= :rasem
92
95
 
93
- options[:width] ||= DEFAULT_WIDTH
94
- options[:height] ||= DEFAULT_HEIGHT
96
+ options[:width] ||= @@default_width
97
+ options[:height] ||= @@default_height
95
98
 
96
99
  options[:axis_value_and_param_labels] = true if options[:axis_value_and_param_labels].nil?
97
100
  options[:axis_zero_labels] = true if options[:axis_zero_labels].nil?
@@ -143,6 +146,26 @@ class GraphImageDrawer
143
146
  options[:height] = h.to_i if h.to_i > 0
144
147
  end
145
148
 
149
+ # Get default graph width
150
+ def self.width
151
+ @@default_width
152
+ end
153
+
154
+ # Get default graph height
155
+ def self.height
156
+ @@default_height
157
+ end
158
+
159
+ # Set default graph width
160
+ def self.width=(w)
161
+ @@default_width = w.to_i if w.to_i > 0
162
+ end
163
+
164
+ # Set default graph height
165
+ def self.height=(h)
166
+ @@default_height = h.to_i if h.to_i > 0
167
+ end
168
+
146
169
  def antialias
147
170
  options[:antialias] == true
148
171
  end
@@ -0,0 +1,161 @@
1
+ #encoding: utf-8
2
+
3
+ require 'technical_graph/graph_image_drawer_module'
4
+ require 'rubygems'
5
+ require 'chunky_png'
6
+ require 'oily_png' if gem_available? 'oily_png'
7
+
8
+ class GraphImageDrawerChunky
9
+ include GraphImageDrawerModule
10
+
11
+ # Initialize blank image
12
+ def create_blank_image
13
+ @image = ChunkyPNG::Image.new(width, height, ChunkyPNG::Color::WHITE)
14
+ end
15
+
16
+ # Draw both array axis
17
+ def axis(x_array, y_array, _options = { :color => 'black', :width => 1 }, render_labels = false, x_labels = [], y_labels = [])
18
+ # for single axis
19
+ x_array = [x_array] if not x_array.kind_of? Array
20
+ y_array = [y_array] if not y_array.kind_of? Array
21
+
22
+ x_array.each_with_index do |x, i|
23
+ @image.line(x, 0, x, height, ChunkyPNG::Color.from_hex(_options[:color]))
24
+
25
+ # labels
26
+ # chunky_png probably can't write text
27
+
28
+ #label = x_labels[i]
29
+ #if render_labels and not label.nil?
30
+ # label = "#{truncate_string % label}"
31
+ # plot_axis_text.text(x + 15, height - 15, label)
32
+ #end
33
+ end
34
+
35
+ y_array.each_with_index do |y, i|
36
+ @image.line(0, y, width, y, ChunkyPNG::Color.from_hex(_options[:color]))
37
+
38
+ # labels
39
+ #label = y_labels[i]
40
+ #if render_labels and not label.nil?
41
+ # label = "#{truncate_string % label}"
42
+ # plot_axis_text.text(15, y + 15, label)
43
+ #end
44
+ end
45
+
46
+ end
47
+
48
+ # Label for parameters and values
49
+ def axis_labels(parameter_label, value_label, _options = { :color => 'black', :width => 1, :size => 20 })
50
+ # chunky_png probably can't write text
51
+
52
+ #if options[:x_axis_label].to_s.size > 0
53
+ # plot = axis_labels_draw_object
54
+ # plot.stroke(_options[:color])
55
+ # plot.stroke_width(_options[:width])
56
+ #
57
+ # plot.text(
58
+ # (width / 2).to_i,
59
+ # height - 40,
60
+ # options[:x_axis_label].to_s
61
+ # )
62
+ # plot.draw(@image)
63
+ #end
64
+ #
65
+ #
66
+ #if options[:y_axis_label].to_s.size > 0
67
+ # plot = axis_labels_draw_object
68
+ # plot.stroke(_options[:color])
69
+ # plot.stroke_width(_options[:width])
70
+ # plot = plot.rotate(90)
71
+ #
72
+ # plot.text(
73
+ # (height / 2).to_i,
74
+ # -40,
75
+ # options[:y_axis_label].to_s
76
+ # )
77
+ # plot.draw(@image)
78
+ #end
79
+ end
80
+
81
+ def render_data_layer(l, coords)
82
+ # chunky_png probably can't write text
83
+
84
+ ## value labels
85
+ #if l.value_labels
86
+ # plot = layer_no_stroke(layer_value_labels_draw_object(l))
87
+ # coords.each do |c|
88
+ # string_label = "#{truncate_string % c[:dy]}"
89
+ # plot.text(
90
+ # c[:ax] + 5, c[:ay],
91
+ # string_label
92
+ # )
93
+ # end
94
+ # plot.draw(@image)
95
+ #end
96
+
97
+ # lines and dots
98
+ coords.each do |c|
99
+ # additional circle
100
+ #plot.circle(c[:ax], c[:ay], c[:ax] + 2, c[:ay])
101
+ #plot.circle(c[:bx], c[:by], c[:bx] + 2, c[:by])
102
+
103
+ # line
104
+ @image.line(c[:ax], c[:ay], c[:bx], c[:by], ChunkyPNG::Color.from_hex(l.color))
105
+ end
106
+ end
107
+
108
+
109
+ def legend(legend_data)
110
+ # chunky_png probably can't write text
111
+
112
+ #legend_text_offset = (options[:legend_font_size] / 2.0).round - 4
113
+ #
114
+ #legend_data.each do |l|
115
+ # plot = axis_draw_object
116
+ # plot_text = layer_no_stroke(plot)
117
+ #
118
+ # plot.fill(l[:color])
119
+ # plot.stroke(l[:color])
120
+ # plot_text.fill(l[:color])
121
+ # plot_text.pointsize(options[:legend_font_size])
122
+ #
123
+ # plot.circle(l[:x], l[:y], l[:x] + 2, l[:y])
124
+ # plot_text.text(l[:x] + 5, l[:y] + legend_text_offset, l[:label])
125
+ #
126
+ # plot.draw(@image)
127
+ # plot_text.draw(@image)
128
+ #end
129
+ end
130
+
131
+ def close
132
+ # only for compatibility
133
+ @closed = true
134
+ end
135
+
136
+ def closed?
137
+ @closed
138
+ end
139
+
140
+ # Save output to file
141
+ def save(file)
142
+ t = Time.now
143
+
144
+ @image.save(file)
145
+
146
+ logger.debug "saving image"
147
+ logger.debug " TIME COST #{Time.now - t}"
148
+ end
149
+
150
+ # Export image
151
+ def to_format(format)
152
+ t = Time.now
153
+ blob = @image.to_blob
154
+
155
+ logger.debug "exporting image as string"
156
+ logger.debug " TIME COST #{Time.now - t}"
157
+
158
+ return blob
159
+ end
160
+
161
+ end
@@ -125,7 +125,9 @@ class GraphImageDrawerRmagick
125
125
  if options[:x_axis_label].to_s.size > 0
126
126
  plot = axis_labels_draw_object
127
127
  plot.stroke(_options[:color])
128
- plot.stroke_width(_options[:width])
128
+ plot.stroke_width(0.0)
129
+ plot.fill_opacity(1.0)
130
+ plot.stroke_opacity(0.0)
129
131
 
130
132
  plot.text(
131
133
  (width / 2).to_i,
@@ -139,7 +141,9 @@ class GraphImageDrawerRmagick
139
141
  if options[:y_axis_label].to_s.size > 0
140
142
  plot = axis_labels_draw_object
141
143
  plot.stroke(_options[:color])
142
- plot.stroke_width(_options[:width])
144
+ plot.stroke_width(0.0)
145
+ plot.fill_opacity(1.0)
146
+ plot.stroke_opacity(0.0)
143
147
  plot = plot.rotate(90)
144
148
 
145
149
  plot.text(
metadata CHANGED
@@ -1,133 +1,135 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: technical_graph
3
- version: !ruby/object:Gem::Version
4
- hash: 9
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 5
9
- - 1
10
- version: 0.5.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Aleksander Kwiatkowski
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-12-11 00:00:00 +01:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-05-26 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rasem
16
+ requirement: &23351560 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
22
  type: :runtime
23
- requirement: &id001 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ version_requirements: *23351560
25
+ - !ruby/object:Gem::Dependency
26
+ name: chunky_png
27
+ requirement: &23350860 !ruby/object:Gem::Requirement
24
28
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
32
- name: rasem
33
- version_requirements: *id001
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
34
  prerelease: false
35
- - !ruby/object:Gem::Dependency
36
- type: :development
37
- requirement: &id002 !ruby/object:Gem::Requirement
35
+ version_requirements: *23350860
36
+ - !ruby/object:Gem::Dependency
37
+ name: rmagick
38
+ requirement: &23350140 !ruby/object:Gem::Requirement
38
39
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
46
- name: rdoc
47
- version_requirements: *id002
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
48
45
  prerelease: false
49
- - !ruby/object:Gem::Dependency
50
- type: :development
51
- requirement: &id003 !ruby/object:Gem::Requirement
46
+ version_requirements: *23350140
47
+ - !ruby/object:Gem::Dependency
48
+ name: oily_png
49
+ requirement: &23349380 !ruby/object:Gem::Requirement
52
50
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
60
- name: shoulda
61
- version_requirements: *id003
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *23349380
58
+ - !ruby/object:Gem::Dependency
59
+ name: rdoc
60
+ requirement: &23348320 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
62
67
  prerelease: false
63
- - !ruby/object:Gem::Dependency
68
+ version_requirements: *23348320
69
+ - !ruby/object:Gem::Dependency
70
+ name: shoulda
71
+ requirement: &23347480 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
64
77
  type: :development
65
- requirement: &id004 !ruby/object:Gem::Requirement
78
+ prerelease: false
79
+ version_requirements: *23347480
80
+ - !ruby/object:Gem::Dependency
81
+ name: bundler
82
+ requirement: &23346800 !ruby/object:Gem::Requirement
66
83
  none: false
67
- requirements:
84
+ requirements:
68
85
  - - ~>
69
- - !ruby/object:Gem::Version
70
- hash: 23
71
- segments:
72
- - 1
73
- - 0
74
- - 0
86
+ - !ruby/object:Gem::Version
75
87
  version: 1.0.0
76
- name: bundler
77
- version_requirements: *id004
78
- prerelease: false
79
- - !ruby/object:Gem::Dependency
80
88
  type: :development
81
- requirement: &id005 !ruby/object:Gem::Requirement
82
- none: false
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- hash: 3
87
- segments:
88
- - 0
89
- version: "0"
90
- name: rspec
91
- version_requirements: *id005
92
89
  prerelease: false
93
- - !ruby/object:Gem::Dependency
94
- type: :development
95
- requirement: &id006 !ruby/object:Gem::Requirement
90
+ version_requirements: *23346800
91
+ - !ruby/object:Gem::Dependency
92
+ name: rspec
93
+ requirement: &23346180 !ruby/object:Gem::Requirement
96
94
  none: false
97
- requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- hash: 3
101
- segments:
102
- - 0
103
- version: "0"
104
- name: jeweler
105
- version_requirements: *id006
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
106
100
  prerelease: false
107
- - !ruby/object:Gem::Dependency
101
+ version_requirements: *23346180
102
+ - !ruby/object:Gem::Dependency
103
+ name: jeweler
104
+ requirement: &23320780 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
108
110
  type: :development
109
- requirement: &id007 !ruby/object:Gem::Requirement
111
+ prerelease: false
112
+ version_requirements: *23320780
113
+ - !ruby/object:Gem::Dependency
114
+ name: simplecov
115
+ requirement: &23320140 !ruby/object:Gem::Requirement
110
116
  none: false
111
- requirements:
112
- - - ">="
113
- - !ruby/object:Gem::Version
114
- hash: 3
115
- segments:
116
- - 0
117
- version: "0"
118
- name: rcov
119
- version_requirements: *id007
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :development
120
122
  prerelease: false
121
- description: 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.
123
+ version_requirements: *23320140
124
+ description: Purpose of this gem is to create neat, simple, technical graphs. This
125
+ is alternative to most new libraries which create small, candy graphs using JavaScript.
122
126
  email: bobikx@poczta.fm
123
127
  executables: []
124
-
125
128
  extensions: []
126
-
127
- extra_rdoc_files:
129
+ extra_rdoc_files:
128
130
  - LICENSE.txt
129
131
  - README.md
130
- files:
132
+ files:
131
133
  - DOCUMENTATION.md
132
134
  - DOCUMENTATION.textile
133
135
  - Gemfile
@@ -143,59 +145,41 @@ files:
143
145
  - lib/technical_graph/data_layer_processor_noise_removal.rb
144
146
  - lib/technical_graph/data_layer_processor_simple_smoother.rb
145
147
  - lib/technical_graph/data_point.rb
148
+ - lib/technical_graph/gem.rb
146
149
  - lib/technical_graph/graph_axis.rb
147
150
  - lib/technical_graph/graph_color_library.rb
148
151
  - lib/technical_graph/graph_data_processor.rb
149
152
  - lib/technical_graph/graph_image_drawer.rb
153
+ - lib/technical_graph/graph_image_drawer_chunky.rb
150
154
  - lib/technical_graph/graph_image_drawer_module.rb
151
155
  - lib/technical_graph/graph_image_drawer_rasem.rb
152
156
  - lib/technical_graph/graph_image_drawer_rmagick.rb
153
- - test/helper.rb
154
- - test/test_technical_autocolor.rb
155
- - test/test_technical_axis_enlarge.rb
156
- - test/test_technical_fix1.rb
157
- - test/test_technical_graph.rb
158
- - test/test_technical_graph_axis.rb
159
- - test/test_technical_multilayer.rb
160
- - test/test_technical_noise_removal.rb
161
- - test/test_technical_rasem.rb
162
- - test/test_technical_readme.rb
163
- - test/test_technical_simple_graph.rb
164
- - test/test_technical_smoother.rb
165
- - test/test_technical_smoother_adv.rb
166
- has_rdoc: true
167
157
  homepage: http://github.com/akwiatkowski/technical_graph
168
- licenses:
158
+ licenses:
169
159
  - LGPLv3
170
160
  post_install_message:
171
161
  rdoc_options: []
172
-
173
- require_paths:
162
+ require_paths:
174
163
  - lib
175
- required_ruby_version: !ruby/object:Gem::Requirement
164
+ required_ruby_version: !ruby/object:Gem::Requirement
176
165
  none: false
177
- requirements:
178
- - - ">="
179
- - !ruby/object:Gem::Version
180
- hash: 3
181
- segments:
166
+ requirements:
167
+ - - ! '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ segments:
182
171
  - 0
183
- version: "0"
184
- required_rubygems_version: !ruby/object:Gem::Requirement
172
+ hash: 1155677963396469989
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
185
174
  none: false
186
- requirements:
187
- - - ">="
188
- - !ruby/object:Gem::Version
189
- hash: 3
190
- segments:
191
- - 0
192
- version: "0"
175
+ requirements:
176
+ - - ! '>='
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
193
179
  requirements: []
194
-
195
180
  rubyforge_project:
196
- rubygems_version: 1.6.2
181
+ rubygems_version: 1.8.15
197
182
  signing_key:
198
183
  specification_version: 3
199
184
  summary: Create simple and neat graphs
200
185
  test_files: []
201
-