gruff 0.11.0-java → 0.12.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/gruff.gemspec +7 -3
  4. data/lib/gruff.rb +8 -3
  5. data/lib/gruff/accumulator_bar.rb +0 -2
  6. data/lib/gruff/area.rb +0 -4
  7. data/lib/gruff/bar.rb +18 -5
  8. data/lib/gruff/base.rb +78 -41
  9. data/lib/gruff/bezier.rb +0 -4
  10. data/lib/gruff/bullet.rb +2 -9
  11. data/lib/gruff/dot.rb +1 -5
  12. data/lib/gruff/helper/bar_conversion.rb +1 -1
  13. data/lib/gruff/helper/bar_value_label_mixin.rb +3 -0
  14. data/lib/gruff/histogram.rb +0 -1
  15. data/lib/gruff/line.rb +5 -11
  16. data/lib/gruff/mini/bar.rb +1 -1
  17. data/lib/gruff/mini/legend.rb +9 -4
  18. data/lib/gruff/mini/pie.rb +1 -2
  19. data/lib/gruff/mini/side_bar.rb +1 -2
  20. data/lib/gruff/net.rb +5 -6
  21. data/lib/gruff/patch/rmagick.rb +22 -24
  22. data/lib/gruff/patch/string.rb +7 -4
  23. data/lib/gruff/photo_bar.rb +0 -4
  24. data/lib/gruff/pie.rb +1 -5
  25. data/lib/gruff/renderer/bezier.rb +4 -3
  26. data/lib/gruff/renderer/circle.rb +4 -3
  27. data/lib/gruff/renderer/dash_line.rb +4 -3
  28. data/lib/gruff/renderer/dot.rb +4 -3
  29. data/lib/gruff/renderer/ellipse.rb +4 -3
  30. data/lib/gruff/renderer/line.rb +5 -4
  31. data/lib/gruff/renderer/polygon.rb +5 -4
  32. data/lib/gruff/renderer/polyline.rb +4 -3
  33. data/lib/gruff/renderer/rectangle.rb +3 -2
  34. data/lib/gruff/renderer/renderer.rb +31 -43
  35. data/lib/gruff/renderer/text.rb +10 -6
  36. data/lib/gruff/scatter.rb +1 -5
  37. data/lib/gruff/scene.rb +0 -1
  38. data/lib/gruff/side_bar.rb +22 -6
  39. data/lib/gruff/side_stacked_bar.rb +19 -6
  40. data/lib/gruff/spider.rb +2 -6
  41. data/lib/gruff/stacked_area.rb +0 -5
  42. data/lib/gruff/stacked_bar.rb +17 -5
  43. data/lib/gruff/store/{base_data.rb → basic_data.rb} +5 -7
  44. data/lib/gruff/store/custom_data.rb +4 -6
  45. data/lib/gruff/store/store.rb +5 -4
  46. data/lib/gruff/store/xy_data.rb +6 -7
  47. data/lib/gruff/version.rb +1 -1
  48. metadata +18 -15
  49. data/.editorconfig +0 -14
  50. data/.github/ISSUE_TEMPLATE.md +0 -18
  51. data/.gitignore +0 -10
  52. data/.rubocop.yml +0 -109
  53. data/.rubocop_todo.yml +0 -112
  54. data/.travis.yml +0 -26
  55. data/.yardopts +0 -1
  56. data/Rakefile +0 -47
  57. data/docker/Dockerfile +0 -14
  58. data/docker/build.sh +0 -4
  59. data/docker/launch.sh +0 -4
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'gruff/base'
4
-
5
3
  #
6
4
  # Graph with dots and labels along a vertical access.
7
5
  # see: 'Creating More Effective Graphs' by Robbins
@@ -44,8 +42,6 @@ class Gruff::Dot < Gruff::Base
44
42
  draw_label(y_pos, point_index)
45
43
  end
46
44
  end
47
-
48
- Gruff::Renderer.finish
49
45
  end
50
46
 
51
47
  protected
@@ -54,7 +50,7 @@ protected
54
50
  def draw_line_markers
55
51
  return if @hide_line_markers
56
52
 
57
- (0..@marker_count).each do |index|
53
+ (0..marker_count).each do |index|
58
54
  marker_label = minimum_value + index * @increment
59
55
  x = @graph_left + (marker_label - minimum_value) * @graph_width / @spread
60
56
 
@@ -3,7 +3,7 @@
3
3
  ##
4
4
  # Original Author: David Stokar
5
5
  #
6
- # This class perfoms the y coordinats conversion for the bar class.
6
+ # This class performs the y coordinates conversion for the bar class.
7
7
  #
8
8
  # There are three cases:
9
9
  #
@@ -2,6 +2,9 @@
2
2
 
3
3
  # @private
4
4
  module Gruff::Base::BarValueLabelMixin
5
+ using String::GruffCommify
6
+
7
+ # @private
5
8
  class BarValueLabel
6
9
  attr_accessor :coordinates, :values
7
10
 
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'histogram'
4
- require 'gruff/base'
5
4
 
6
5
  #
7
6
  # Here's how to set up a Gruff::Histogram.
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'gruff/base'
4
-
5
3
  #
6
4
  # Here's how to make a Gruff::Line.
7
5
  #
@@ -30,7 +28,7 @@ class Gruff::Line < Gruff::Base
30
28
  # default is +'circle'+, other options include square.
31
29
  attr_writer :dot_style
32
30
 
33
- # Hide parts of the graph to fit more datapoints, or for a different appearance.
31
+ # Hide parts of the graph to fit more data points, or for a different appearance.
34
32
  attr_writer :hide_dots, :hide_lines
35
33
 
36
34
  # accessors for support of xy data.
@@ -134,7 +132,7 @@ class Gruff::Line < Gruff::Base
134
132
  # g.data("Capples", [1, 1, 2, 2, 3, 3])
135
133
  #
136
134
  # # labels will be drawn at the x locations of the keys passed in.
137
- # In this example the lables are drawn at x positions 2, 4, and 6:
135
+ # In this example the labels are drawn at x positions 2, 4, and 6:
138
136
  # g.labels = {0 => '2003', 2 => '2004', 4 => '2005', 6 => '2006'}
139
137
  # # The 0 => '2003' label will be ignored since it is outside the chart range.
140
138
  def dataxy(name, x_data_points = [], y_data_points = [], color = nil)
@@ -155,11 +153,9 @@ class Gruff::Line < Gruff::Base
155
153
  end
156
154
 
157
155
  def draw_reference_line(reference_line, left, right, top, bottom)
158
- config = {
159
- color: reference_line[:color] || @reference_line_default_color,
160
- width: reference_line[:width] || @reference_line_default_width
161
- }
162
- Gruff::Renderer::DashLine.new(config).render(left, top, right, bottom)
156
+ color = reference_line[:color] || @reference_line_default_color
157
+ width = reference_line[:width] || @reference_line_default_width
158
+ Gruff::Renderer::DashLine.new(color: color, width: width).render(left, top, right, bottom)
163
159
  end
164
160
 
165
161
  def draw_horizontal_reference_line(reference_line)
@@ -237,8 +233,6 @@ class Gruff::Line < Gruff::Base
237
233
  prev_y = new_y
238
234
  end
239
235
  end
240
-
241
- Gruff::Renderer.finish
242
236
  end
243
237
 
244
238
  private
@@ -14,6 +14,7 @@
14
14
  #
15
15
  module Gruff
16
16
  module Mini
17
+ # A class for drawing a small bar graph.
17
18
  class Bar < Gruff::Bar
18
19
  include Gruff::Mini::Legend
19
20
 
@@ -37,7 +38,6 @@ module Gruff
37
38
  super
38
39
 
39
40
  draw_vertical_legend
40
- Gruff::Renderer.finish
41
41
  end
42
42
  end
43
43
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Gruff
4
4
  module Mini
5
+ # A module to handle the small legend.
5
6
  module Legend
6
7
  attr_accessor :hide_mini_legend, :legend_position
7
8
 
@@ -25,7 +26,7 @@ module Gruff
25
26
  @original_columns = @raw_columns
26
27
 
27
28
  case @legend_position
28
- when :right then
29
+ when :right
29
30
  @rows = [@rows, legend_height].max
30
31
  @columns += calculate_legend_width + @left_margin
31
32
  else
@@ -55,7 +56,7 @@ module Gruff
55
56
  legend_top_margin = 40.0
56
57
 
57
58
  case @legend_position
58
- when :right then
59
+ when :right
59
60
  current_x_offset = @original_columns + @left_margin
60
61
  current_y_offset = @top_margin + legend_top_margin
61
62
  else
@@ -67,7 +68,8 @@ module Gruff
67
68
  # Draw label
68
69
  label = truncate_legend_label(legend_label)
69
70
  text_renderer = Gruff::Renderer::Text.new(label, font: @font, size: @legend_font_size, color: @font_color)
70
- text_renderer.add_to_render_queue(@raw_columns, 1.0, current_x_offset + (legend_square_width * 1.7), current_y_offset, Magick::WestGravity)
71
+ x_offset = current_x_offset + (legend_square_width * 1.7)
72
+ text_renderer.add_to_render_queue(@raw_columns, 1.0, x_offset, current_y_offset, Magick::WestGravity)
71
73
 
72
74
  # Now draw box with color of this dataset
73
75
  rect_renderer = Gruff::Renderer::Rectangle.new(color: store.data[index].color)
@@ -87,7 +89,10 @@ module Gruff
87
89
 
88
90
  def truncate_legend_label(label)
89
91
  truncated_label = label.to_s
90
- while calculate_width(scale_fontsize(@legend_font_size), truncated_label) > (@columns - @legend_left_margin - @right_margin) && (truncated_label.length > 1)
92
+
93
+ font_size = scale_fontsize(@legend_font_size)
94
+ max_width = @columns - @legend_left_margin - @right_margin
95
+ while calculate_width(font_size, truncated_label) > max_width && truncated_label.length > 1
91
96
  truncated_label = truncated_label[0..truncated_label.length - 2]
92
97
  end
93
98
  truncated_label + (truncated_label.length < label.to_s.length ? '...' : '')
@@ -13,6 +13,7 @@
13
13
  #
14
14
  module Gruff
15
15
  module Mini
16
+ # A class for drawing a small pie graph.
16
17
  class Pie < Gruff::Pie
17
18
  include Gruff::Mini::Legend
18
19
 
@@ -34,8 +35,6 @@ module Gruff
34
35
  super
35
36
 
36
37
  draw_vertical_legend
37
-
38
- Gruff::Renderer.finish
39
38
  end
40
39
  end
41
40
  end
@@ -21,6 +21,7 @@
21
21
  #
22
22
  module Gruff
23
23
  module Mini
24
+ # A class for drawing a small side bar graph.
24
25
  class SideBar < Gruff::SideBar
25
26
  include Gruff::Mini::Legend
26
27
 
@@ -41,8 +42,6 @@ module Gruff
41
42
  super
42
43
 
43
44
  draw_vertical_legend
44
-
45
- Gruff::Renderer.finish
46
45
  end
47
46
  end
48
47
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'gruff/base'
4
-
5
3
  # See also the Spider graph.
6
4
  #
7
5
  # Here's how to make a Gruff::Net.
@@ -25,7 +23,7 @@ require 'gruff/base'
25
23
  # g.write("net.png")
26
24
  #
27
25
  class Gruff::Net < Gruff::Base
28
- # Hide parts of the graph to fit more datapoints, or for a different appearance.
26
+ # Hide parts of the graph to fit more data points, or for a different appearance.
29
27
  attr_writer :hide_dots
30
28
 
31
29
  # Dimensions of lines and dots; calculated based on dataset size if left unspecified.
@@ -66,11 +64,12 @@ class Gruff::Net < Gruff::Base
66
64
 
67
65
  Gruff::Renderer::Line.new(color: data_row.color, width: @stroke_width).render(start_x, start_y, end_x, end_y)
68
66
 
69
- Gruff::Renderer::Circle.new(color: data_row.color, width: @stroke_width).render(start_x, start_y, start_x - @circle_radius, start_y) unless @hide_dots
67
+ unless @hide_dots
68
+ circle_renderer = Gruff::Renderer::Circle.new(color: data_row.color, width: @stroke_width)
69
+ circle_renderer.render(start_x, start_y, start_x - @circle_radius, start_y)
70
+ end
70
71
  end
71
72
  end
72
-
73
- Gruff::Renderer.finish
74
73
  end
75
74
 
76
75
  private
@@ -1,33 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # @private
3
4
  module Magick
4
- class Draw
5
- # Additional method to scale annotation text since Draw.scale doesn't.
6
- def annotate_scaled(img, width, height, x, y, text, scale)
7
- scaled_width = (width * scale) >= 1 ? (width * scale) : 1
8
- scaled_height = (height * scale) >= 1 ? (height * scale) : 1
5
+ # @private
6
+ module GruffAnnotate
7
+ refine Draw do
8
+ # Additional method to scale annotation text since Draw.scale doesn't.
9
+ def annotate_scaled(img, width, height, x, y, text, scale)
10
+ scaled_width = (width * scale) >= 1 ? (width * scale) : 1
11
+ scaled_height = (height * scale) >= 1 ? (height * scale) : 1
9
12
 
10
- annotate(img,
11
- scaled_width, scaled_height,
12
- x * scale, y * scale,
13
- text.gsub('%', '%%'))
14
- end
15
-
16
- remove_method :stroke_opacity
17
- def stroke_opacity(_opacity)
18
- raise '#stroke_opacity method has different behavior between RMagick and RMagick4J. Should not use this method.'
19
- end
13
+ annotate(img,
14
+ scaled_width, scaled_height,
15
+ x * scale, y * scale,
16
+ text.gsub('%', '%%'))
17
+ end
20
18
 
21
- if defined? JRUBY_VERSION
22
- # FIXME(uwe): We should NOT need to implement this method.
23
- # Remove this method as soon as RMagick4J Issue #16 is fixed.
24
- # https://github.com/Serabe/RMagick4J/issues/16
25
- def fill=(fill)
26
- fill = { white: '#FFFFFF' }[fill.to_sym] || fill
27
- @draw.fill = Magick4J.ColorDatabase.query_default(fill)
28
- self
19
+ if defined? JRUBY_VERSION
20
+ # FIXME(uwe): We should NOT need to implement this method.
21
+ # Remove this method as soon as RMagick4J Issue #16 is fixed.
22
+ # https://github.com/Serabe/RMagick4J/issues/16
23
+ def fill=(fill)
24
+ fill = { white: '#FFFFFF' }[fill.to_sym] || fill
25
+ @draw.fill = Magick4J.ColorDatabase.query_default(fill)
26
+ self
27
+ end
29
28
  end
30
- # EMXIF
31
29
  end
32
30
  end
33
31
  end
@@ -1,10 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class String
3
+ # @private
4
+ module String::GruffCommify
4
5
  THOUSAND_SEPARATOR = ','
5
6
 
6
- #Taken from http://codesnippets.joyent.com/posts/show/330
7
- def commify(delimiter = THOUSAND_SEPARATOR)
8
- gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}")
7
+ refine String do
8
+ #Taken from http://codesnippets.joyent.com/posts/show/330
9
+ def commify(delimiter = THOUSAND_SEPARATOR)
10
+ gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}")
11
+ end
9
12
  end
10
13
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'gruff/base'
4
-
5
3
  # EXPERIMENTAL!
6
4
  #
7
5
  # Doesn't work yet.
@@ -70,8 +68,6 @@ class Gruff::PhotoBar < Gruff::Base
70
68
  draw_label(label_center, point_index)
71
69
  end
72
70
  end
73
-
74
- Gruff::Renderer.finish
75
71
  end
76
72
 
77
73
  # Return the chosen theme or the default
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'gruff/base'
4
-
5
3
  #
6
4
  # Here's how to make a Gruff::Pie.
7
5
  #
@@ -69,8 +67,6 @@ class Gruff::Pie < Gruff::Base
69
67
  update_chart_degrees_with slice.degrees
70
68
  end
71
69
  end
72
-
73
- Gruff::Renderer.finish
74
70
  end
75
71
 
76
72
  private
@@ -81,7 +77,7 @@ private
81
77
 
82
78
  slices.sort_by(&:value) if @sort
83
79
 
84
- total = slices.map(&:value).inject(:+).to_f
80
+ total = slices.map(&:value).sum.to_f
85
81
  slices.each { |slice| slice.total = total }
86
82
  end
87
83
  end
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gruff
4
+ # @private
4
5
  class Renderer::Bezier
5
- def initialize(args = {})
6
- @color = args[:color]
7
- @width = args[:width] || 1.0
6
+ def initialize(color:, width: 1.0)
7
+ @color = color
8
+ @width = width
8
9
  end
9
10
 
10
11
  def render(points)
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gruff
4
+ # @private
4
5
  class Renderer::Circle
5
- def initialize(args = {})
6
- @color = args[:color]
7
- @width = args[:width] || 1.0
6
+ def initialize(color:, width: 1.0)
7
+ @color = color
8
+ @width = width
8
9
  end
9
10
 
10
11
  def render(origin_x, origin_y, perim_x, perim_y)
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gruff
4
+ # @private
4
5
  class Renderer::DashLine
5
- def initialize(args = {})
6
- @color = args[:color]
7
- @width = args[:width]
6
+ def initialize(color:, width:)
7
+ @color = color
8
+ @width = width
8
9
  end
9
10
 
10
11
  def render(start_x, start_y, end_x, end_y)
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gruff
4
+ # @private
4
5
  class Renderer::Dot
5
- def initialize(style, config)
6
+ def initialize(style, color:, width: 1.0)
6
7
  @style = style
7
- @color = config[:color]
8
- @width = config[:width] || 1.0
8
+ @color = color
9
+ @width = width
9
10
  end
10
11
 
11
12
  def render(new_x, new_y, circle_radius)
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gruff
4
+ # @private
4
5
  class Renderer::Ellipse
5
- def initialize(args = {})
6
- @color = args[:color]
7
- @width = args[:width] || 1.0
6
+ def initialize(color:, width: 1.0)
7
+ @color = color
8
+ @width = width
8
9
  end
9
10
 
10
11
  def render(origin_x, origin_y, width, height, arc_start, arc_end)
@@ -1,13 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gruff
4
+ # @private
4
5
  class Renderer::Line
5
6
  EPSILON = 0.001
6
7
 
7
- def initialize(args = {})
8
- @color = args[:color]
9
- @shadow_color = args[:shadow_color]
10
- @width = args[:width]
8
+ def initialize(color:, width: nil, shadow_color: nil)
9
+ @color = color
10
+ @width = width
11
+ @shadow_color = shadow_color
11
12
  end
12
13
 
13
14
  def render(start_x, start_y, end_x, end_y)