gruff 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +5 -5
  2. data/.editorconfig +14 -0
  3. data/.rubocop.yml +16 -0
  4. data/.rubocop_todo.yml +923 -0
  5. data/.travis.yml +21 -14
  6. data/{History.txt → CHANGELOG.md} +32 -25
  7. data/README.md +3 -2
  8. data/Rakefile +27 -18
  9. data/assets/bubble.png +0 -0
  10. data/assets/city_scene/background/0000.png +0 -0
  11. data/assets/city_scene/background/0600.png +0 -0
  12. data/assets/city_scene/background/2000.png +0 -0
  13. data/assets/city_scene/clouds/cloudy.png +0 -0
  14. data/assets/city_scene/clouds/partly_cloudy.png +0 -0
  15. data/assets/city_scene/clouds/stormy.png +0 -0
  16. data/assets/city_scene/grass/default.png +0 -0
  17. data/assets/city_scene/haze/true.png +0 -0
  18. data/assets/city_scene/number_sample/1.png +0 -0
  19. data/assets/city_scene/number_sample/2.png +0 -0
  20. data/assets/city_scene/number_sample/default.png +0 -0
  21. data/assets/city_scene/sky/0000.png +0 -0
  22. data/assets/city_scene/sky/0200.png +0 -0
  23. data/assets/city_scene/sky/0400.png +0 -0
  24. data/assets/city_scene/sky/0600.png +0 -0
  25. data/assets/city_scene/sky/0800.png +0 -0
  26. data/assets/city_scene/sky/1000.png +0 -0
  27. data/assets/city_scene/sky/1200.png +0 -0
  28. data/assets/city_scene/sky/1400.png +0 -0
  29. data/assets/city_scene/sky/1500.png +0 -0
  30. data/assets/city_scene/sky/1700.png +0 -0
  31. data/assets/city_scene/sky/2000.png +0 -0
  32. data/assets/pc306715.jpg +0 -0
  33. data/assets/plastik/blue.png +0 -0
  34. data/assets/plastik/green.png +0 -0
  35. data/assets/plastik/red.png +0 -0
  36. data/gruff.gemspec +12 -10
  37. data/lib/gruff.rb +2 -2
  38. data/lib/gruff/accumulator_bar.rb +2 -2
  39. data/lib/gruff/area.rb +1 -4
  40. data/lib/gruff/bar.rb +12 -13
  41. data/lib/gruff/bar_conversion.rb +11 -11
  42. data/lib/gruff/base.rb +36 -36
  43. data/lib/gruff/bezier.rb +1 -2
  44. data/lib/gruff/bullet.rb +7 -10
  45. data/lib/gruff/deprecated.rb +10 -11
  46. data/lib/gruff/dot.rb +3 -4
  47. data/lib/gruff/line.rb +13 -14
  48. data/lib/gruff/mini/bar.rb +3 -3
  49. data/lib/gruff/mini/legend.rb +7 -8
  50. data/lib/gruff/mini/pie.rb +6 -6
  51. data/lib/gruff/mini/side_bar.rb +7 -7
  52. data/lib/gruff/net.rb +2 -8
  53. data/lib/gruff/photo_bar.rb +9 -12
  54. data/lib/gruff/pie.rb +6 -6
  55. data/lib/gruff/scatter.rb +47 -51
  56. data/lib/gruff/scene.rb +17 -19
  57. data/lib/gruff/side_bar.rb +5 -8
  58. data/lib/gruff/side_stacked_bar.rb +24 -26
  59. data/lib/gruff/spider.rb +14 -15
  60. data/lib/gruff/stacked_area.rb +12 -16
  61. data/lib/gruff/stacked_bar.rb +50 -52
  62. data/lib/gruff/stacked_mixin.rb +2 -3
  63. data/lib/gruff/themes.rb +32 -33
  64. data/lib/gruff/version.rb +1 -1
  65. metadata +23 -67
  66. data/RELEASE.md +0 -30
  67. data/test/gruff_test_case.rb +0 -152
  68. data/test/image_compare.rb +0 -58
  69. data/test/test_accumulator_bar.rb +0 -51
  70. data/test/test_area.rb +0 -134
  71. data/test/test_bar.rb +0 -505
  72. data/test/test_base.rb +0 -33
  73. data/test/test_bezier.rb +0 -33
  74. data/test/test_bullet.rb +0 -26
  75. data/test/test_dot.rb +0 -263
  76. data/test/test_labels_for_null_data.rb +0 -27
  77. data/test/test_legend.rb +0 -68
  78. data/test/test_line.rb +0 -674
  79. data/test/test_mini_bar.rb +0 -33
  80. data/test/test_mini_pie.rb +0 -25
  81. data/test/test_mini_side_bar.rb +0 -36
  82. data/test/test_net.rb +0 -231
  83. data/test/test_photo.rb +0 -41
  84. data/test/test_pie.rb +0 -194
  85. data/test/test_scatter.rb +0 -270
  86. data/test/test_scene.rb +0 -100
  87. data/test/test_side_bar.rb +0 -56
  88. data/test/test_sidestacked_bar.rb +0 -105
  89. data/test/test_spider.rb +0 -226
  90. data/test/test_stacked_area.rb +0 -52
  91. data/test/test_stacked_bar.rb +0 -68
@@ -1,39 +1,38 @@
1
-
2
1
  ##
3
2
  # A mixin for methods that need to be deleted or have been
4
3
  # replaced by cleaner code.
5
4
 
6
5
  module Gruff
7
6
  module Deprecated
8
-
7
+
9
8
  def scale_measurements
10
9
  setup_graph_measurements
11
10
  end
12
-
11
+
13
12
  def total_height
14
13
  @rows + 10
15
14
  end
16
-
15
+
17
16
  def graph_top
18
17
  @graph_top * @scale
19
18
  end
20
-
19
+
21
20
  def graph_height
22
21
  @graph_height * @scale
23
22
  end
24
-
25
- def graph_left
26
- @graph_left * @scale
23
+
24
+ def graph_left
25
+ @graph_left * @scale
27
26
  end
28
-
27
+
29
28
  def graph_width
30
29
  @graph_width * @scale
31
30
  end
32
-
31
+
33
32
  # TODO Should be calculate_graph_height
34
33
  # def setup_graph_height
35
34
  # @graph_height = @graph_bottom - @graph_top
36
35
  # end
37
-
36
+
38
37
  end
39
38
  end
@@ -24,7 +24,7 @@ class Gruff::Dot < Gruff::Base
24
24
  @norm_data.each_with_index do |data_row, row_index|
25
25
  data_row[DATA_VALUES_INDEX].each_with_index do |data_point, point_index|
26
26
  x_pos = @graph_left + (data_point * @graph_width)
27
- y_pos = @graph_top + (@items_width * point_index) + padding + (@items_width.to_f/2.0).round
27
+ y_pos = @graph_top + (@items_width * point_index) + padding + (@items_width.to_f / 2.0).round
28
28
 
29
29
  if row_index == 0
30
30
  @d = @d.stroke(@marker_color)
@@ -38,17 +38,16 @@ class Gruff::Dot < Gruff::Base
38
38
 
39
39
  @d = @d.fill data_row[DATA_COLOR_INDEX]
40
40
  @d = @d.stroke('transparent')
41
- @d = @d.circle(x_pos, y_pos, x_pos + (@item_width.to_f/3.0).round, y_pos)
41
+ @d = @d.circle(x_pos, y_pos, x_pos + (@item_width.to_f / 3.0).round, y_pos)
42
42
 
43
43
  draw_label(y_pos, point_index)
44
44
  end
45
-
46
45
  end
47
46
 
48
47
  @d.draw(@base_image)
49
48
  end
50
49
 
51
- protected
50
+ protected
52
51
 
53
52
  # Instead of base class version, draws vertical background lines and label
54
53
  def draw_line_markers
@@ -37,7 +37,7 @@ class Gruff::Line < Gruff::Base
37
37
 
38
38
  # Get the value if somebody has defined it.
39
39
  def baseline_value
40
- if (@reference_lines.key?(:baseline))
40
+ if @reference_lines.key?(:baseline)
41
41
  @reference_lines[:baseline][:value]
42
42
  else
43
43
  nil
@@ -51,7 +51,7 @@ class Gruff::Line < Gruff::Base
51
51
  end
52
52
 
53
53
  def baseline_color
54
- if (@reference_lines.key?(:baseline))
54
+ if @reference_lines.key?(:baseline)
55
55
  @reference_lines[:baseline][:color]
56
56
  else
57
57
  nil
@@ -74,6 +74,7 @@ class Gruff::Line < Gruff::Base
74
74
  # The preferred way is to call hide_dots or hide_lines instead.
75
75
  def initialize(*args)
76
76
  raise ArgumentError, 'Wrong number of arguments' if args.length > 2
77
+
77
78
  if args.empty? || ((not Numeric === args.first) && (not String === args.first))
78
79
  super()
79
80
  else
@@ -127,11 +128,12 @@ class Gruff::Line < Gruff::Base
127
128
  # In this example the lables are drawn at x positions 2, 4, and 6:
128
129
  # g.labels = {0 => '2003', 2 => '2004', 4 => '2005', 6 => '2006'}
129
130
  # The 0 => '2003' label will be ignored since it is outside the chart range.
130
- def dataxy(name, x_data_points=[], y_data_points=[], color=nil)
131
+ def dataxy(name, x_data_points = [], y_data_points = [], color = nil)
131
132
  raise ArgumentError, 'x_data_points is nil!' if x_data_points.length == 0
132
133
 
133
134
  if x_data_points.all? { |p| p.is_a?(Array) && p.size == 2 }
134
- x_data_points, y_data_points = x_data_points.map { |p| p[0] }, x_data_points.map { |p| p[1] }
135
+ y_data_points = x_data_points.map { |p| p[1] }
136
+ x_data_points = x_data_points.map { |p| p[0] }
135
137
  end
136
138
 
137
139
  raise ArgumentError, 'x_data_points.length != y_data_points.length!' if x_data_points.length != y_data_points.length
@@ -157,7 +159,6 @@ class Gruff::Line < Gruff::Base
157
159
  @minimum_x_value = (x_data_point < @minimum_x_value) ?
158
160
  x_data_point : @minimum_x_value
159
161
  end
160
-
161
162
  end
162
163
 
163
164
  def draw_reference_line(reference_line, left, right, top, bottom)
@@ -193,7 +194,7 @@ class Gruff::Line < Gruff::Base
193
194
  draw_vertical_reference_line(curr_reference_line) if curr_reference_line.key?(:index)
194
195
  end
195
196
 
196
- if (@show_vertical_markers)
197
+ if @show_vertical_markers
197
198
  (0..@column_count).each do |column|
198
199
  x = @graph_left + @graph_width - column.to_f * @x_increment
199
200
 
@@ -260,7 +261,8 @@ class Gruff::Line < Gruff::Base
260
261
  @d = DotRenderers.renderer(@dot_style).render(@d, new_x, new_y, circle_radius)
261
262
  end
262
263
 
263
- prev_x, prev_y = new_x, new_y
264
+ prev_x = new_x
265
+ prev_y = new_y
264
266
  end
265
267
  end
266
268
 
@@ -268,13 +270,12 @@ class Gruff::Line < Gruff::Base
268
270
  end
269
271
 
270
272
  def setup_data
271
-
272
273
  # Deal with horizontal reference line values that exceed the existing minimum & maximum values.
273
274
  possible_maximums = [@maximum_value.to_f]
274
275
  possible_minimums = [@minimum_value.to_f]
275
276
 
276
277
  @reference_lines.each_value do |curr_reference_line|
277
- if (curr_reference_line.key?(:value))
278
+ if curr_reference_line.key?(:value)
278
279
  possible_maximums << curr_reference_line[:value].to_f
279
280
  possible_minimums << curr_reference_line[:value].to_f
280
281
  end
@@ -286,16 +287,14 @@ class Gruff::Line < Gruff::Base
286
287
  super
287
288
  end
288
289
 
289
- def normalize(force=false)
290
+ def normalize(force = false)
290
291
  super(force)
291
292
 
292
293
  @reference_lines.each_value do |curr_reference_line|
293
-
294
294
  # We only care about horizontal markers ... for normalization.
295
295
  # Vertical markers won't have a :value, they will have an :index
296
296
 
297
- curr_reference_line[:norm_value] = ((curr_reference_line[:value].to_f - @minimum_value) / @spread.to_f) if (curr_reference_line.key?(:value))
298
-
297
+ curr_reference_line[:norm_value] = ((curr_reference_line[:value].to_f - @minimum_value) / @spread.to_f) if curr_reference_line.key?(:value)
299
298
  end
300
299
 
301
300
  #normalize the x data if it is specified
@@ -309,7 +308,6 @@ class Gruff::Line < Gruff::Base
309
308
  @norm_data[index] << norm_x_data_points
310
309
  end
311
310
  end
312
-
313
311
  end
314
312
 
315
313
  def sort_norm_data
@@ -329,6 +327,7 @@ class Gruff::Line < Gruff::Base
329
327
  # more than one point, bail
330
328
  return false
331
329
  end
330
+
332
331
  # there is at least one data point
333
332
  one_point = true
334
333
  end
@@ -8,10 +8,10 @@ module Gruff
8
8
  class Bar < Gruff::Bar
9
9
 
10
10
  include Gruff::Mini::Legend
11
-
11
+
12
12
  def initialize_ivars
13
13
  super
14
-
14
+
15
15
  @hide_legend = true
16
16
  @hide_title = true
17
17
  @hide_line_numbers = true
@@ -32,6 +32,6 @@ module Gruff
32
32
  end
33
33
 
34
34
  end
35
-
35
+
36
36
  end
37
37
  end
@@ -16,7 +16,7 @@ module Gruff
16
16
  def expand_canvas_for_vertical_legend
17
17
  return if @hide_mini_legend
18
18
 
19
- @legend_labels = @data.collect {|item| item[Gruff::Base::DATA_LABEL_INDEX] }
19
+ @legend_labels = @data.collect { |item| item[Gruff::Base::DATA_LABEL_INDEX] }
20
20
 
21
21
  legend_height = scale_fontsize(
22
22
  @data.length * calculate_line_height +
@@ -41,7 +41,7 @@ module Gruff
41
41
 
42
42
  def calculate_legend_width
43
43
  width = @legend_labels.map { |label| calculate_width(@legend_font_size, label) }.max
44
- scale_fontsize(width + 40*1.7)
44
+ scale_fontsize(width + 40 * 1.7)
45
45
  end
46
46
 
47
47
  ##
@@ -70,7 +70,6 @@ module Gruff
70
70
  debug { @d.line 0.0, current_y_offset, @raw_columns, current_y_offset }
71
71
 
72
72
  @legend_labels.each_with_index do |legend_label, index|
73
-
74
73
  # Draw label
75
74
  @d.fill = @font_color
76
75
  @d.font = @font if @font
@@ -78,10 +77,10 @@ module Gruff
78
77
  @d.stroke = 'transparent'
79
78
  @d.font_weight = Magick::NormalWeight
80
79
  @d.gravity = Magick::WestGravity
81
- @d = @d.annotate_scaled( @base_image,
82
- @raw_columns, 1.0,
83
- current_x_offset + (legend_square_width * 1.7), current_y_offset,
84
- truncate_legend_label(legend_label), @scale)
80
+ @d = @d.annotate_scaled(@base_image,
81
+ @raw_columns, 1.0,
82
+ current_x_offset + (legend_square_width * 1.7), current_y_offset,
83
+ truncate_legend_label(legend_label), @scale)
85
84
 
86
85
  # Now draw box with color of this dataset
87
86
  @d = @d.stroke 'transparent'
@@ -104,7 +103,7 @@ module Gruff
104
103
  def truncate_legend_label(label)
105
104
  truncated_label = label.to_s
106
105
  while calculate_width(scale_fontsize(@legend_font_size), truncated_label) > (@columns - @legend_left_margin - @right_margin) && (truncated_label.length > 1)
107
- truncated_label = truncated_label[0..truncated_label.length-2]
106
+ truncated_label = truncated_label[0..truncated_label.length - 2]
108
107
  end
109
108
  truncated_label + (truncated_label.length < label.to_s.length ? "..." : '')
110
109
  end
@@ -11,26 +11,26 @@ module Gruff
11
11
 
12
12
  def initialize_ivars
13
13
  super
14
-
14
+
15
15
  @hide_legend = true
16
16
  @hide_title = true
17
17
  @hide_line_numbers = true
18
-
18
+
19
19
  @marker_font_size = 60.0
20
20
  @legend_font_size = 60.0
21
21
  end
22
22
 
23
23
  def draw
24
24
  expand_canvas_for_vertical_legend
25
-
25
+
26
26
  super
27
-
27
+
28
28
  draw_vertical_legend
29
-
29
+
30
30
  @d.draw(@base_image)
31
31
  end # def draw
32
32
 
33
33
  end # class Pie
34
-
34
+
35
35
  end
36
36
  end
@@ -8,7 +8,7 @@ module Gruff
8
8
  class SideBar < Gruff::SideBar
9
9
 
10
10
  include Gruff::Mini::Legend
11
-
11
+
12
12
  def initialize_ivars
13
13
  super
14
14
  @hide_legend = true
@@ -18,18 +18,18 @@ module Gruff
18
18
  @marker_font_size = 50.0
19
19
  @legend_font_size = 50.0
20
20
  end
21
-
21
+
22
22
  def draw
23
23
  expand_canvas_for_vertical_legend
24
-
24
+
25
25
  super
26
-
26
+
27
27
  draw_vertical_legend
28
-
28
+
29
29
  @d.draw(@base_image)
30
30
  end
31
-
31
+
32
32
  end
33
-
33
+
34
34
  end
35
35
  end
@@ -69,43 +69,37 @@ class Gruff::Net < Gruff::Base
69
69
 
70
70
  @d = @d.circle(start_x, start_y, start_x - circle_radius, start_y) unless @hide_dots
71
71
  end
72
-
73
72
  end
74
73
 
75
74
  @d.draw(@base_image)
76
75
  end
77
76
 
78
-
79
77
  # the lines connecting in the center, with the first line vertical
80
78
  def draw_line_markers
81
79
  return if @hide_line_markers
82
80
 
83
-
84
81
  # have to do this here (AGAIN)... see draw() in this class
85
82
  # because this funtion is called before the @radius, @center_x and @center_y are set
86
83
  @radius = @graph_height / 2.0
87
84
  @center_x = @graph_left + (@graph_width / 2.0)
88
85
  @center_y = @graph_top + (@graph_height / 2.0) - 10 # Move graph up a bit
89
86
 
90
-
91
87
  # Draw horizontal line markers and annotate with numbers
92
88
  @d = @d.stroke(@marker_color)
93
89
  @d = @d.stroke_width 1
94
90
 
95
-
96
- (0..@column_count-1).each do |index|
91
+ (0..@column_count - 1).each do |index|
97
92
  rad_pos = index * Math::PI * 2 / @column_count
98
93
 
99
94
  @d = @d.line(@center_x, @center_y, @center_x + Math::sin(rad_pos) * @radius, @center_y - Math::cos(rad_pos) * @radius)
100
95
 
101
-
102
96
  marker_label = labels[index] ? labels[index].to_s : '000'
103
97
 
104
98
  draw_label(@center_x, @center_y, rad_pos * 360 / (2 * Math::PI), @radius, marker_label)
105
99
  end
106
100
  end
107
101
 
108
- private
102
+ private
109
103
 
110
104
  def draw_label(center_x, center_y, angle, radius, amount)
111
105
  r_offset = 1.1
@@ -30,7 +30,7 @@ class Gruff::PhotoBar < Gruff::Base
30
30
  return # TODO Remove for further development
31
31
 
32
32
  init_photo_bar_graphics()
33
-
33
+
34
34
  #Draw#define_clip_path()
35
35
  #Draw#clip_path(pathname)
36
36
  #Draw#composite....with bar graph image OverCompositeOp
@@ -38,7 +38,7 @@ class Gruff::PhotoBar < Gruff::Base
38
38
  # See also
39
39
  #
40
40
  # Draw.pattern # define an image to tile as the filling of a draw object
41
- #
41
+ #
42
42
 
43
43
  # Setup spacing.
44
44
  #
@@ -47,7 +47,6 @@ class Gruff::PhotoBar < Gruff::Base
47
47
  @bar_width = @norm_data[0][DATA_COLOR_INDEX].columns
48
48
 
49
49
  @norm_data.each_with_index do |data_row, row_index|
50
-
51
50
  data_row[DATA_VALUES_INDEX].each_with_index do |data_point, point_index|
52
51
  data_point = 0 if data_point.nil?
53
52
  # Use incremented x and scaled y
@@ -55,27 +54,25 @@ class Gruff::PhotoBar < Gruff::Base
55
54
  left_y = @graph_top + (@graph_height - data_point * @graph_height) + 1
56
55
  right_x = left_x + @bar_width * spacing_factor
57
56
  right_y = @graph_top + @graph_height - 1
58
-
57
+
59
58
  bar_image_width = data_row[DATA_COLOR_INDEX].columns
60
59
  bar_image_height = right_y.to_f - left_y.to_f
61
-
60
+
62
61
  # Crop to scale for data
63
62
  bar_image = data_row[DATA_COLOR_INDEX].crop(0, 0, bar_image_width, bar_image_height)
64
-
63
+
65
64
  @d.gravity = NorthWestGravity
66
65
  @d = @d.composite(left_x, left_y, bar_image_width, bar_image_height, bar_image)
67
-
66
+
68
67
  # Calculate center based on bar_width and current row
69
68
  label_center = @graph_left + (@data.length * @bar_width * point_index) + (@data.length * @bar_width / 2.0)
70
69
  draw_label(label_center, point_index)
71
70
  end
72
-
73
71
  end
74
72
 
75
- @d.draw(@base_image)
73
+ @d.draw(@base_image)
76
74
  end
77
75
 
78
-
79
76
  # Return the chosen theme or the default
80
77
  def theme
81
78
  @theme || 'plastik'
@@ -85,16 +82,16 @@ protected
85
82
 
86
83
  # Sets up colors with a list of images that will be used.
87
84
  # Images should be 340px tall
88
- def init_photo_bar_graphics
85
+ def init_photo_bar_graphics
89
86
  color_list = Array.new
90
87
  theme_dir = File.dirname(__FILE__) + '/../../assets/' + theme
91
88
 
92
89
  Dir.open(theme_dir).each do |file|
93
90
  next unless /\.png$/.match(file)
91
+
94
92
  color_list << Image.read("#{theme_dir}/#{file}").first
95
93
  end
96
94
  @colors = color_list
97
95
  end
98
96
 
99
97
  end
100
-