gruff 0.13.0-java → 0.16.0-java

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.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +79 -0
  3. data/.rubocop.yml +29 -31
  4. data/CHANGELOG.md +43 -0
  5. data/README.md +11 -5
  6. data/gruff.gemspec +8 -10
  7. data/lib/gruff/accumulator_bar.rb +4 -2
  8. data/lib/gruff/area.rb +9 -12
  9. data/lib/gruff/bar.rb +46 -31
  10. data/lib/gruff/base.rb +236 -207
  11. data/lib/gruff/bezier.rb +6 -8
  12. data/lib/gruff/box_plot.rb +174 -0
  13. data/lib/gruff/bullet.rb +17 -16
  14. data/lib/gruff/candlestick.rb +112 -0
  15. data/lib/gruff/dot.rb +14 -14
  16. data/lib/gruff/font.rb +42 -0
  17. data/lib/gruff/helper/bar_conversion.rb +5 -5
  18. data/lib/gruff/helper/bar_value_label.rb +26 -20
  19. data/lib/gruff/helper/stacked_mixin.rb +4 -3
  20. data/lib/gruff/histogram.rb +9 -7
  21. data/lib/gruff/line.rb +96 -83
  22. data/lib/gruff/mini/bar.rb +9 -6
  23. data/lib/gruff/mini/legend.rb +16 -12
  24. data/lib/gruff/mini/pie.rb +9 -6
  25. data/lib/gruff/mini/side_bar.rb +9 -6
  26. data/lib/gruff/net.rb +16 -22
  27. data/lib/gruff/patch/rmagick.rb +0 -1
  28. data/lib/gruff/patch/string.rb +2 -1
  29. data/lib/gruff/pie.rb +42 -75
  30. data/lib/gruff/renderer/bezier.rb +8 -9
  31. data/lib/gruff/renderer/circle.rb +8 -9
  32. data/lib/gruff/renderer/dash_line.rb +10 -10
  33. data/lib/gruff/renderer/dot.rb +15 -14
  34. data/lib/gruff/renderer/ellipse.rb +8 -9
  35. data/lib/gruff/renderer/line.rb +8 -11
  36. data/lib/gruff/renderer/polygon.rb +9 -10
  37. data/lib/gruff/renderer/polyline.rb +8 -9
  38. data/lib/gruff/renderer/rectangle.rb +11 -8
  39. data/lib/gruff/renderer/renderer.rb +25 -40
  40. data/lib/gruff/renderer/text.rb +21 -37
  41. data/lib/gruff/scatter.rb +86 -85
  42. data/lib/gruff/side_bar.rb +50 -37
  43. data/lib/gruff/side_stacked_bar.rb +26 -35
  44. data/lib/gruff/spider.rb +52 -28
  45. data/lib/gruff/stacked_area.rb +20 -16
  46. data/lib/gruff/stacked_bar.rb +44 -22
  47. data/lib/gruff/store/store.rb +6 -10
  48. data/lib/gruff/store/xy_data.rb +2 -0
  49. data/lib/gruff/themes.rb +6 -6
  50. data/lib/gruff/version.rb +1 -1
  51. data/lib/gruff.rb +70 -57
  52. data/rails_generators/gruff/templates/controller.rb +1 -1
  53. metadata +15 -32
  54. data/.rubocop_todo.yml +0 -182
  55. data/.travis.yml +0 -23
  56. data/assets/plastik/blue.png +0 -0
  57. data/assets/plastik/green.png +0 -0
  58. data/assets/plastik/red.png +0 -0
  59. data/lib/gruff/photo_bar.rb +0 -93
  60. data/lib/gruff/scene.rb +0 -198
  61. data/lib/gruff/store/custom_data.rb +0 -36
data/lib/gruff/line.rb CHANGED
@@ -37,29 +37,8 @@ class Gruff::Line < Gruff::Base
37
37
  # accessors for support of xy data.
38
38
  attr_writer :maximum_x_value
39
39
 
40
- # Get the value if somebody has defined it.
41
- def baseline_value
42
- if @reference_lines.key?(:baseline)
43
- @reference_lines[:baseline][:value]
44
- end
45
- end
46
-
47
- # Set a value for a baseline reference line..
48
- def baseline_value=(new_value)
49
- @reference_lines[:baseline] ||= {}
50
- @reference_lines[:baseline][:value] = new_value
51
- end
52
-
53
- def baseline_color
54
- if @reference_lines.key?(:baseline)
55
- @reference_lines[:baseline][:color]
56
- end
57
- end
58
-
59
- def baseline_color=(new_value)
60
- @reference_lines[:baseline] ||= {}
61
- @reference_lines[:baseline][:color] = new_value
62
- end
40
+ # The number of vertical lines shown.
41
+ attr_writer :marker_x_count
63
42
 
64
43
  # Call with target pixel width of graph (+800+, +400+, +300+), and/or +false+ to omit lines (points only).
65
44
  #
@@ -78,28 +57,29 @@ class Gruff::Line < Gruff::Base
78
57
  end
79
58
  end
80
59
 
81
- def initialize_store
82
- @store = Gruff::Store.new(Gruff::Store::XYData)
60
+ # Get the value if somebody has defined it.
61
+ def baseline_value
62
+ if @reference_lines.key?(:baseline)
63
+ @reference_lines[:baseline][:value]
64
+ end
83
65
  end
84
- private :initialize_store
85
66
 
86
- def initialize_ivars
87
- super
88
- @reference_lines = {}
89
- @reference_line_default_color = 'red'
90
- @reference_line_default_width = 5
91
-
92
- @hide_dots = @hide_lines = false
93
- @maximum_x_value = nil
94
- @minimum_x_value = nil
67
+ # Set a value for a baseline reference line..
68
+ def baseline_value=(new_value)
69
+ @reference_lines[:baseline] ||= {}
70
+ @reference_lines[:baseline][:value] = new_value
71
+ end
95
72
 
96
- @line_width = nil
97
- @dot_radius = nil
98
- @dot_style = 'circle'
73
+ def baseline_color
74
+ if @reference_lines.key?(:baseline)
75
+ @reference_lines[:baseline][:color]
76
+ end
77
+ end
99
78
 
100
- @show_vertical_markers = false
79
+ def baseline_color=(new_value)
80
+ @reference_lines[:baseline] ||= {}
81
+ @reference_lines[:baseline][:color] = new_value
101
82
  end
102
- private :initialize_ivars
103
83
 
104
84
  # This method allows one to plot a dataset with both X and Y data.
105
85
  #
@@ -138,12 +118,14 @@ class Gruff::Line < Gruff::Base
138
118
  def dataxy(name, x_data_points = [], y_data_points = [], color = nil)
139
119
  # make sure it's an array
140
120
  x_data_points = Array(x_data_points)
141
- y_data_points = Array(y_data_points)
142
121
 
143
122
  raise ArgumentError, 'x_data_points is nil!' if x_data_points.empty?
144
123
 
145
124
  if x_data_points.all? { |p| p.is_a?(Array) && p.size == 2 }
125
+ color = y_data_points if y_data_points.is_a?(String)
146
126
  x_data_points, y_data_points = x_data_points.transpose
127
+ else
128
+ y_data_points = Array(y_data_points)
147
129
  end
148
130
 
149
131
  raise ArgumentError, 'x_data_points.length != y_data_points.length!' if x_data_points.length != y_data_points.length
@@ -152,14 +134,38 @@ class Gruff::Line < Gruff::Base
152
134
  store.add(name, y_data_points, color, x_data_points)
153
135
  end
154
136
 
137
+ private
138
+
139
+ def initialize_store
140
+ @store = Gruff::Store.new(Gruff::Store::XYData)
141
+ end
142
+
143
+ def initialize_attributes
144
+ super
145
+ @reference_lines = {}
146
+ @reference_line_default_color = 'red'
147
+ @reference_line_default_width = 5
148
+
149
+ @hide_dots = @hide_lines = false
150
+ @maximum_x_value = nil
151
+ @minimum_x_value = nil
152
+ @marker_x_count = nil
153
+
154
+ @line_width = nil
155
+ @dot_radius = nil
156
+ @dot_style = 'circle'
157
+
158
+ @show_vertical_markers = false
159
+ end
160
+
155
161
  def draw_reference_line(reference_line, left, right, top, bottom)
156
162
  color = reference_line[:color] || @reference_line_default_color
157
163
  width = reference_line[:width] || @reference_line_default_width
158
- Gruff::Renderer::DashLine.new(color: color, width: width).render(left, top, right, bottom)
164
+ Gruff::Renderer::DashLine.new(renderer, color: color, width: width).render(left, top, right, bottom)
159
165
  end
160
166
 
161
167
  def draw_horizontal_reference_line(reference_line)
162
- level = @graph_top + (@graph_height - reference_line[:norm_value] * @graph_height)
168
+ level = @graph_top + (@graph_height - (reference_line[:norm_value] * @graph_height))
163
169
  draw_reference_line(reference_line, @graph_left, @graph_left + @graph_width, level, level)
164
170
  end
165
171
 
@@ -168,65 +174,49 @@ class Gruff::Line < Gruff::Base
168
174
  draw_reference_line(reference_line, index, index, @graph_top, @graph_top + @graph_height)
169
175
  end
170
176
 
171
- def draw
172
- super
173
-
174
- return unless data_given?
175
-
177
+ def draw_graph
176
178
  # Check to see if more than one datapoint was given. NaN can result otherwise.
177
- @x_increment = (column_count > 1) ? (@graph_width / (column_count - 1).to_f) : @graph_width
179
+ @x_increment = column_count > 1 ? @graph_width / (column_count - 1) : @graph_width
178
180
 
179
181
  @reference_lines.each_value do |curr_reference_line|
180
182
  draw_horizontal_reference_line(curr_reference_line) if curr_reference_line.key?(:norm_value)
181
183
  draw_vertical_reference_line(curr_reference_line) if curr_reference_line.key?(:index)
182
184
  end
183
185
 
184
- if @show_vertical_markers
185
- (0..column_count).each do |column|
186
- x = @graph_left + @graph_width - column.to_f * @x_increment
187
-
188
- Gruff::Renderer::Line.new(color: @marker_color).render(x, @graph_bottom, x, @graph_top)
189
- #If the user specified a marker shadow color, draw a shadow just below it
190
- if @marker_shadow_color
191
- Gruff::Renderer::Line.new(color: @marker_shadow_color).render(x + 1, @graph_bottom, x + 1, @graph_top)
192
- end
193
- end
194
- end
195
-
196
186
  store.norm_data.each do |data_row|
197
187
  prev_x = prev_y = nil
198
188
 
199
189
  one_point = contains_one_point_only?(data_row)
200
190
 
201
191
  data_row.coordinates.each_with_index do |(x_data, y_data), index|
202
- if x_data.nil?
203
- #use the old method: equally spaced points along the x-axis
204
- new_x = @graph_left + (@x_increment * index)
205
- draw_label(new_x, index)
206
- else
207
- new_x = get_x_coord(x_data, @graph_width, @graph_left)
208
- @labels.each do |label_pos, _|
209
- draw_label(@graph_left + ((label_pos - @minimum_x_value) * @graph_width) / (@maximum_x_value - @minimum_x_value), label_pos)
192
+ new_x = begin
193
+ if x_data.nil?
194
+ # use the old method: equally spaced points along the x-axis
195
+ @graph_left + (@x_increment * index)
196
+ else
197
+ get_x_coord(x_data, @graph_width, @graph_left)
210
198
  end
211
199
  end
200
+ draw_label_for_x_data(x_data, new_x, index)
201
+
212
202
  unless y_data # we can't draw a line for a null data point, we can still label the axis though
213
203
  prev_x = prev_y = nil
214
204
  next
215
205
  end
216
206
 
217
- new_y = @graph_top + (@graph_height - y_data * @graph_height)
207
+ new_y = @graph_top + (@graph_height - (y_data * @graph_height))
218
208
 
219
209
  # Reset each time to avoid thin-line errors
220
210
  stroke_width = @line_width || clip_value_if_greater_than(@columns / (store.norm_data.first.y_points.size * 4), 5.0)
221
211
  circle_radius = @dot_radius || clip_value_if_greater_than(@columns / (store.norm_data.first.y_points.size * 2.5), 5.0)
222
212
 
223
213
  if !@hide_lines && prev_x && prev_y
224
- Gruff::Renderer::Line.new(color: data_row.color, width: stroke_width)
214
+ Gruff::Renderer::Line.new(renderer, color: data_row.color, width: stroke_width)
225
215
  .render(prev_x, prev_y, new_x, new_y)
226
216
  end
227
217
 
228
218
  if one_point || !@hide_dots
229
- Gruff::Renderer::Dot.new(@dot_style, color: data_row.color, width: stroke_width).render(new_x, new_y, circle_radius)
219
+ Gruff::Renderer::Dot.new(renderer, @dot_style, color: data_row.color, width: stroke_width).render(new_x, new_y, circle_radius)
230
220
  end
231
221
 
232
222
  prev_x = new_x
@@ -235,16 +225,14 @@ class Gruff::Line < Gruff::Base
235
225
  end
236
226
  end
237
227
 
238
- private
239
-
240
228
  def setup_data
241
229
  # Update the global min/max values for the x data
242
- @maximum_x_value ||= store.max_x
243
- @minimum_x_value ||= store.min_x
230
+ @maximum_x_value = (@maximum_x_value || store.max_x).to_f
231
+ @minimum_x_value = (@minimum_x_value || store.min_x).to_f
244
232
 
245
233
  # Deal with horizontal reference line values that exceed the existing minimum & maximum values.
246
- possible_maximums = [maximum_value.to_f]
247
- possible_minimums = [minimum_value.to_f]
234
+ possible_maximums = [maximum_value]
235
+ possible_minimums = [minimum_value]
248
236
 
249
237
  @reference_lines.each_value do |curr_reference_line|
250
238
  if curr_reference_line.key?(:value)
@@ -259,26 +247,51 @@ private
259
247
  super
260
248
  end
261
249
 
250
+ def setup_drawing
251
+ @marker_x_count ||= column_count - 1
252
+ super
253
+ end
254
+
262
255
  def normalize
263
256
  return unless data_given?
264
257
 
265
- spread_x = @maximum_x_value.to_f - @minimum_x_value.to_f
258
+ spread_x = @maximum_x_value - @minimum_x_value
266
259
  store.normalize(minimum_x: @minimum_x_value, spread_x: spread_x, minimum_y: minimum_value, spread_y: @spread)
267
260
 
268
261
  @reference_lines.each_value do |curr_reference_line|
269
262
  # We only care about horizontal markers ... for normalization.
270
263
  # Vertical markers won't have a :value, they will have an :index
271
264
 
272
- curr_reference_line[:norm_value] = ((curr_reference_line[:value].to_f - minimum_value) / @spread.to_f) if curr_reference_line.key?(:value)
265
+ curr_reference_line[:norm_value] = ((curr_reference_line[:value].to_f - minimum_value) / @spread) if curr_reference_line.key?(:value)
266
+ end
267
+ end
268
+
269
+ def draw_line_markers
270
+ # do all of the stuff for the horizontal lines on the y-axis
271
+ super
272
+ return if @hide_line_markers
273
+ return unless @show_vertical_markers
274
+
275
+ (0..@marker_x_count).each do |index|
276
+ x = @graph_left + @graph_width - (index * @graph_width / @marker_x_count)
277
+
278
+ Gruff::Renderer::Line.new(renderer, color: @marker_color).render(x, @graph_bottom, x, @graph_top)
279
+ Gruff::Renderer::Line.new(renderer, color: @marker_shadow_color).render(x + 1, @graph_bottom, x + 1, @graph_top) if @marker_shadow_color
273
280
  end
274
281
  end
275
282
 
276
- def sort_norm_data
277
- super unless store.data.any?(&:x_points)
283
+ def draw_label_for_x_data(x_data, new_x, index)
284
+ if x_data.nil?
285
+ draw_label(new_x, index)
286
+ else
287
+ @labels.each do |label_pos, _|
288
+ draw_label(@graph_left + (((label_pos - @minimum_x_value) * @graph_width) / (@maximum_x_value - @minimum_x_value)), label_pos)
289
+ end
290
+ end
278
291
  end
279
292
 
280
293
  def get_x_coord(x_data_point, width, offset)
281
- x_data_point * width + offset
294
+ (x_data_point * width) + offset
282
295
  end
283
296
 
284
297
  def contains_one_point_only?(data_row)
@@ -16,27 +16,30 @@ module Gruff
16
16
  module Mini
17
17
  # A class for drawing a small bar graph.
18
18
  class Bar < Gruff::Bar
19
+ private
20
+
19
21
  include Gruff::Mini::Legend
20
22
 
21
- def initialize_ivars
23
+ def initialize_attributes
22
24
  super
23
25
 
24
26
  @hide_legend = true
25
27
  @hide_title = true
26
28
  @hide_line_numbers = true
27
29
 
28
- @marker_font_size = 50.0
29
- @legend_font_size = 60.0
30
+ @marker_font.size = 50.0
31
+ @legend_font.size = 60.0
30
32
 
31
33
  @minimum_value = 0.0
32
34
  end
33
- private :initialize_ivars
34
35
 
35
- def draw
36
+ def setup_data
36
37
  expand_canvas_for_vertical_legend
37
-
38
38
  super
39
+ end
39
40
 
41
+ def draw_graph
42
+ super
40
43
  draw_vertical_legend
41
44
  end
42
45
  end
@@ -3,6 +3,7 @@
3
3
  module Gruff
4
4
  module Mini
5
5
  # A module to handle the small legend.
6
+ # @private
6
7
  module Legend
7
8
  attr_accessor :hide_mini_legend, :legend_position
8
9
 
@@ -20,7 +21,7 @@ module Gruff
20
21
 
21
22
  @legend_labels = store.data.map(&:label)
22
23
 
23
- legend_height = scale_fontsize(store.length * calculate_line_height + @top_margin + @bottom_margin)
24
+ legend_height = scale_fontsize((store.length * calculate_line_height) + @top_margin + @bottom_margin)
24
25
 
25
26
  @original_rows = @raw_rows
26
27
  @original_columns = @raw_columns
@@ -30,19 +31,21 @@ module Gruff
30
31
  @rows = [@rows, legend_height].max
31
32
  @columns += calculate_legend_width + @left_margin
32
33
  else
33
- @rows += store.length * calculate_caps_height(scale_fontsize(@legend_font_size)) * 1.7
34
+ font = @legend_font.dup
35
+ font.size = scale_fontsize(font.size)
36
+ @rows += store.length * calculate_caps_height(font) * 1.7
34
37
  end
35
38
 
36
- Gruff::Renderer.setup(@columns, @rows, @font, @scale, @theme_options)
39
+ @renderer = Gruff::Renderer.new(@columns, @rows, @scale, @theme_options)
37
40
  end
38
41
 
39
42
  def calculate_line_height
40
- calculate_caps_height(@legend_font_size) * 1.7
43
+ calculate_caps_height(@legend_font) * 1.7
41
44
  end
42
45
 
43
46
  def calculate_legend_width
44
- width = @legend_labels.map { |label| calculate_width(@legend_font_size, label) }.max
45
- scale_fontsize(width + 40 * 1.7)
47
+ width = @legend_labels.map { |label| calculate_width(@legend_font, label) }.max
48
+ scale_fontsize(width + (40 * 1.7))
46
49
  end
47
50
 
48
51
  ##
@@ -67,16 +70,16 @@ module Gruff
67
70
  @legend_labels.each_with_index do |legend_label, index|
68
71
  # Draw label
69
72
  label = truncate_legend_label(legend_label)
70
- text_renderer = Gruff::Renderer::Text.new(label, font: @font, size: @legend_font_size, color: @font_color)
73
+ text_renderer = Gruff::Renderer::Text.new(renderer, label, font: @legend_font)
71
74
  x_offset = current_x_offset + (legend_square_width * 1.7)
72
75
  text_renderer.add_to_render_queue(@raw_columns, 1.0, x_offset, current_y_offset, Magick::WestGravity)
73
76
 
74
77
  # Now draw box with color of this dataset
75
- rect_renderer = Gruff::Renderer::Rectangle.new(color: store.data[index].color)
78
+ rect_renderer = Gruff::Renderer::Rectangle.new(renderer, color: store.data[index].color)
76
79
  rect_renderer.render(current_x_offset,
77
- current_y_offset - legend_square_width / 2.0,
80
+ current_y_offset - (legend_square_width / 2.0),
78
81
  current_x_offset + legend_square_width,
79
- current_y_offset + legend_square_width / 2.0)
82
+ current_y_offset + (legend_square_width / 2.0))
80
83
 
81
84
  current_y_offset += calculate_line_height
82
85
  end
@@ -90,9 +93,10 @@ module Gruff
90
93
  def truncate_legend_label(label)
91
94
  truncated_label = label.to_s
92
95
 
93
- font_size = scale_fontsize(@legend_font_size)
96
+ font = @legend_font.dup
97
+ font.size = scale_fontsize(font.size)
94
98
  max_width = @columns - @legend_left_margin - @right_margin
95
- while calculate_width(font_size, truncated_label) > max_width && truncated_label.length > 1
99
+ while calculate_width(font, truncated_label) > max_width && truncated_label.length > 1
96
100
  truncated_label = truncated_label[0..truncated_label.length - 2]
97
101
  end
98
102
  truncated_label + (truncated_label.length < label.to_s.length ? '...' : '')
@@ -15,25 +15,28 @@ module Gruff
15
15
  module Mini
16
16
  # A class for drawing a small pie graph.
17
17
  class Pie < Gruff::Pie
18
+ private
19
+
18
20
  include Gruff::Mini::Legend
19
21
 
20
- def initialize_ivars
22
+ def initialize_attributes
21
23
  super
22
24
 
23
25
  @hide_legend = true
24
26
  @hide_title = true
25
27
  @hide_line_numbers = true
26
28
 
27
- @marker_font_size = 60.0
28
- @legend_font_size = 60.0
29
+ @marker_font.size = 60.0
30
+ @legend_font.size = 60.0
29
31
  end
30
- private :initialize_ivars
31
32
 
32
- def draw
33
+ def setup_data
33
34
  expand_canvas_for_vertical_legend
34
-
35
35
  super
36
+ end
36
37
 
38
+ def draw_graph
39
+ super
37
40
  draw_vertical_legend
38
41
  end
39
42
  end
@@ -23,24 +23,27 @@ module Gruff
23
23
  module Mini
24
24
  # A class for drawing a small side bar graph.
25
25
  class SideBar < Gruff::SideBar
26
+ private
27
+
26
28
  include Gruff::Mini::Legend
27
29
 
28
- def initialize_ivars
30
+ def initialize_attributes
29
31
  super
30
32
  @hide_legend = true
31
33
  @hide_title = true
32
34
  @hide_line_numbers = true
33
35
 
34
- @marker_font_size = 50.0
35
- @legend_font_size = 50.0
36
+ @marker_font.size = 50.0
37
+ @legend_font.size = 50.0
36
38
  end
37
- private :initialize_ivars
38
39
 
39
- def draw
40
+ def setup_data
40
41
  expand_canvas_for_vertical_legend
41
-
42
42
  super
43
+ end
43
44
 
45
+ def draw_graph
46
+ super
44
47
  draw_vertical_legend
45
48
  end
46
49
  end
data/lib/gruff/net.rb CHANGED
@@ -30,7 +30,9 @@ class Gruff::Net < Gruff::Base
30
30
  attr_writer :line_width
31
31
  attr_writer :dot_radius
32
32
 
33
- def initialize_ivars
33
+ private
34
+
35
+ def initialize_attributes
34
36
  super
35
37
 
36
38
  @hide_dots = false
@@ -38,42 +40,36 @@ class Gruff::Net < Gruff::Base
38
40
  @dot_radius = nil
39
41
  @hide_line_numbers = true
40
42
  @sorted_drawing = true
43
+ @marker_font.bold = true
41
44
  end
42
- private :initialize_ivars
43
-
44
- def draw
45
- super
46
-
47
- return unless data_given?
48
45
 
46
+ def draw_graph
49
47
  store.norm_data.each do |data_row|
50
48
  data_row.points.each_with_index do |data_point, index|
51
49
  next if data_point.nil?
52
50
 
53
51
  rad_pos = index * Math::PI * 2 / column_count
54
52
  point_distance = data_point * @radius
55
- start_x = @center_x + Math.sin(rad_pos) * point_distance
56
- start_y = @center_y - Math.cos(rad_pos) * point_distance
53
+ start_x = @center_x + (Math.sin(rad_pos) * point_distance)
54
+ start_y = @center_y - (Math.cos(rad_pos) * point_distance)
57
55
 
58
56
  next_index = index + 1 < data_row.points.length ? index + 1 : 0
59
57
 
60
58
  next_rad_pos = next_index * Math::PI * 2 / column_count
61
59
  next_point_distance = data_row.points[next_index] * @radius
62
- end_x = @center_x + Math.sin(next_rad_pos) * next_point_distance
63
- end_y = @center_y - Math.cos(next_rad_pos) * next_point_distance
60
+ end_x = @center_x + (Math.sin(next_rad_pos) * next_point_distance)
61
+ end_y = @center_y - (Math.cos(next_rad_pos) * next_point_distance)
64
62
 
65
- Gruff::Renderer::Line.new(color: data_row.color, width: @stroke_width).render(start_x, start_y, end_x, end_y)
63
+ Gruff::Renderer::Line.new(renderer, color: data_row.color, width: @stroke_width).render(start_x, start_y, end_x, end_y)
66
64
 
67
65
  unless @hide_dots
68
- circle_renderer = Gruff::Renderer::Circle.new(color: data_row.color, width: @stroke_width)
66
+ circle_renderer = Gruff::Renderer::Circle.new(renderer, color: data_row.color, width: @stroke_width)
69
67
  circle_renderer.render(start_x, start_y, start_x - @circle_radius, start_y)
70
68
  end
71
69
  end
72
70
  end
73
71
  end
74
72
 
75
- private
76
-
77
73
  def setup_drawing
78
74
  super
79
75
 
@@ -92,8 +88,8 @@ private
92
88
  (0..column_count - 1).each do |index|
93
89
  rad_pos = index * Math::PI * 2 / column_count
94
90
 
95
- Gruff::Renderer::Line.new(color: @marker_color)
96
- .render(@center_x, @center_y, @center_x + Math.sin(rad_pos) * @radius, @center_y - Math.cos(rad_pos) * @radius)
91
+ Gruff::Renderer::Line.new(renderer, color: @marker_color)
92
+ .render(@center_x, @center_y, @center_x + (Math.sin(rad_pos) * @radius), @center_y - (Math.cos(rad_pos) * @radius))
97
93
 
98
94
  marker_label = @labels[index] ? @labels[index].to_s : '000'
99
95
  draw_label(@center_x, @center_y, rad_pos * 360 / (2 * Math::PI), @radius + @circle_radius, marker_label)
@@ -103,11 +99,9 @@ private
103
99
  def draw_label(center_x, center_y, angle, radius, amount)
104
100
  x_offset = center_x # + 15 # The label points need to be tweaked slightly
105
101
  y_offset = center_y # + 0 # This one doesn't though
106
- x = x_offset + (radius + LABEL_MARGIN) * Math.sin(deg2rad(angle))
107
- y = y_offset - (radius + LABEL_MARGIN) * Math.cos(deg2rad(angle))
102
+ x = x_offset + ((radius + LABEL_MARGIN) * Math.sin(deg2rad(angle)))
103
+ y = y_offset - ((radius + LABEL_MARGIN) * Math.cos(deg2rad(angle)))
108
104
 
109
- # Draw label
110
- text_renderer = Gruff::Renderer::Text.new(amount, font: @font, size: 20, color: @marker_color, weight: Magick::BoldWeight)
111
- text_renderer.add_to_render_queue(0, 0, x, y, Magick::CenterGravity)
105
+ draw_label_at(1.0, 1.0, x, y, amount, Magick::CenterGravity)
112
106
  end
113
107
  end
@@ -23,7 +23,6 @@ module Magick
23
23
  def fill=(fill)
24
24
  fill = { white: '#FFFFFF' }[fill.to_sym] || fill
25
25
  @draw.fill = Magick4J.ColorDatabase.query_default(fill)
26
- self
27
26
  end
28
27
  end
29
28
  end
@@ -3,9 +3,10 @@
3
3
  # @private
4
4
  module String::GruffCommify
5
5
  THOUSAND_SEPARATOR = ','
6
+ private_constant :THOUSAND_SEPARATOR
6
7
 
7
8
  refine String do
8
- #Taken from http://codesnippets.joyent.com/posts/show/330
9
+ # Taken from http://codesnippets.joyent.com/posts/show/330
9
10
  def commify(delimiter = THOUSAND_SEPARATOR)
10
11
  gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}")
11
12
  end