gruff 0.6.0-java → 0.11.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +5 -5
  2. data/.editorconfig +14 -0
  3. data/.github/ISSUE_TEMPLATE.md +18 -0
  4. data/.gitignore +3 -0
  5. data/.rubocop.yml +109 -0
  6. data/.rubocop_todo.yml +112 -0
  7. data/.travis.yml +24 -15
  8. data/.yardopts +1 -0
  9. data/{History.txt → CHANGELOG.md} +72 -25
  10. data/Gemfile +3 -7
  11. data/README.md +57 -25
  12. data/Rakefile +21 -192
  13. data/assets/plastik/blue.png +0 -0
  14. data/assets/plastik/green.png +0 -0
  15. data/assets/plastik/red.png +0 -0
  16. data/docker/Dockerfile +14 -0
  17. data/docker/build.sh +4 -0
  18. data/docker/launch.sh +4 -0
  19. data/gruff.gemspec +21 -13
  20. data/init.rb +2 -0
  21. data/lib/gruff.rb +26 -2
  22. data/lib/gruff/accumulator_bar.rb +18 -8
  23. data/lib/gruff/area.rb +33 -19
  24. data/lib/gruff/bar.rb +76 -45
  25. data/lib/gruff/base.rb +435 -704
  26. data/lib/gruff/bezier.rb +32 -17
  27. data/lib/gruff/bullet.rb +62 -68
  28. data/lib/gruff/dot.rb +38 -82
  29. data/lib/gruff/helper/bar_conversion.rb +47 -0
  30. data/lib/gruff/helper/bar_value_label_mixin.rb +30 -0
  31. data/lib/gruff/helper/stacked_mixin.rb +23 -0
  32. data/lib/gruff/histogram.rb +60 -0
  33. data/lib/gruff/line.rb +134 -170
  34. data/lib/gruff/mini/bar.rb +17 -10
  35. data/lib/gruff/mini/legend.rb +24 -36
  36. data/lib/gruff/mini/pie.rb +18 -12
  37. data/lib/gruff/mini/side_bar.rb +26 -12
  38. data/lib/gruff/net.rb +68 -81
  39. data/lib/gruff/patch/rmagick.rb +33 -0
  40. data/lib/gruff/patch/string.rb +10 -0
  41. data/lib/gruff/photo_bar.rb +39 -42
  42. data/lib/gruff/pie.rb +180 -89
  43. data/lib/gruff/renderer/bezier.rb +21 -0
  44. data/lib/gruff/renderer/circle.rb +21 -0
  45. data/lib/gruff/renderer/dash_line.rb +22 -0
  46. data/lib/gruff/renderer/dot.rb +39 -0
  47. data/lib/gruff/renderer/ellipse.rb +21 -0
  48. data/lib/gruff/renderer/line.rb +42 -0
  49. data/lib/gruff/renderer/polygon.rb +23 -0
  50. data/lib/gruff/renderer/polyline.rb +21 -0
  51. data/lib/gruff/renderer/rectangle.rb +19 -0
  52. data/lib/gruff/renderer/renderer.rb +132 -0
  53. data/lib/gruff/renderer/text.rb +53 -0
  54. data/lib/gruff/scatter.rb +163 -182
  55. data/lib/gruff/scene.rb +31 -41
  56. data/lib/gruff/side_bar.rb +81 -65
  57. data/lib/gruff/side_stacked_bar.rb +78 -62
  58. data/lib/gruff/spider.rb +49 -57
  59. data/lib/gruff/stacked_area.rb +40 -32
  60. data/lib/gruff/stacked_bar.rb +86 -53
  61. data/lib/gruff/store/base_data.rb +38 -0
  62. data/lib/gruff/store/custom_data.rb +38 -0
  63. data/lib/gruff/store/store.rb +80 -0
  64. data/lib/gruff/store/xy_data.rb +59 -0
  65. data/lib/gruff/themes.rb +32 -33
  66. data/lib/gruff/version.rb +3 -1
  67. metadata +80 -102
  68. data/Manifest.txt +0 -81
  69. data/RELEASE.md +0 -30
  70. data/assets/bubble.png +0 -0
  71. data/assets/city_scene/background/0000.png +0 -0
  72. data/assets/city_scene/background/0600.png +0 -0
  73. data/assets/city_scene/background/2000.png +0 -0
  74. data/assets/city_scene/clouds/cloudy.png +0 -0
  75. data/assets/city_scene/clouds/partly_cloudy.png +0 -0
  76. data/assets/city_scene/clouds/stormy.png +0 -0
  77. data/assets/city_scene/grass/default.png +0 -0
  78. data/assets/city_scene/haze/true.png +0 -0
  79. data/assets/city_scene/number_sample/1.png +0 -0
  80. data/assets/city_scene/number_sample/2.png +0 -0
  81. data/assets/city_scene/number_sample/default.png +0 -0
  82. data/assets/city_scene/sky/0000.png +0 -0
  83. data/assets/city_scene/sky/0200.png +0 -0
  84. data/assets/city_scene/sky/0400.png +0 -0
  85. data/assets/city_scene/sky/0600.png +0 -0
  86. data/assets/city_scene/sky/0800.png +0 -0
  87. data/assets/city_scene/sky/1000.png +0 -0
  88. data/assets/city_scene/sky/1200.png +0 -0
  89. data/assets/city_scene/sky/1400.png +0 -0
  90. data/assets/city_scene/sky/1500.png +0 -0
  91. data/assets/city_scene/sky/1700.png +0 -0
  92. data/assets/city_scene/sky/2000.png +0 -0
  93. data/assets/pc306715.jpg +0 -0
  94. data/lib/gruff/bar_conversion.rb +0 -46
  95. data/lib/gruff/deprecated.rb +0 -39
  96. data/lib/gruff/stacked_mixin.rb +0 -23
  97. data/test/gruff_test_case.rb +0 -154
  98. data/test/image_compare.rb +0 -58
  99. data/test/test_accumulator_bar.rb +0 -51
  100. data/test/test_area.rb +0 -134
  101. data/test/test_bar.rb +0 -505
  102. data/test/test_base.rb +0 -8
  103. data/test/test_bezier.rb +0 -33
  104. data/test/test_bullet.rb +0 -26
  105. data/test/test_dot.rb +0 -263
  106. data/test/test_labels_for_null_data.rb +0 -27
  107. data/test/test_legend.rb +0 -68
  108. data/test/test_line.rb +0 -657
  109. data/test/test_mini_bar.rb +0 -33
  110. data/test/test_mini_pie.rb +0 -25
  111. data/test/test_mini_side_bar.rb +0 -36
  112. data/test/test_net.rb +0 -231
  113. data/test/test_photo.rb +0 -41
  114. data/test/test_pie.rb +0 -161
  115. data/test/test_scatter.rb +0 -233
  116. data/test/test_scene.rb +0 -100
  117. data/test/test_side_bar.rb +0 -56
  118. data/test/test_sidestacked_bar.rb +0 -105
  119. data/test/test_spider.rb +0 -226
  120. data/test/test_stacked_area.rb +0 -52
  121. data/test/test_stacked_bar.rb +0 -68
@@ -1,20 +1,39 @@
1
- require File.dirname(__FILE__) + '/base'
2
-
1
+ # frozen_string_literal: true
2
+
3
+ require 'gruff/base'
4
+
5
+ #
6
+ # Gruff::Bezier is a special line graph that have
7
+ # the bezier curve.
8
+ #
9
+ # Here's how to set up a Gruff::Bezier.
10
+ #
11
+ # dataset = [
12
+ # +0.00, +0.09, +0.19, +0.29, +0.38, +0.47, +0.56, +0.64, +0.71, +0.78,
13
+ # +0.84, +0.89, +0.93, +0.96, +0.98, +0.99, +0.99, +0.99, +0.97, +0.94,
14
+ # +0.90, +0.86, +0.80, +0.74, +0.67, +0.59, +0.51, +0.42, +0.33, +0.23,
15
+ # +0.14, +0.04, -0.06, -0.16, -0.26, -0.36, -0.45, -0.53, -0.62, -0.69,
16
+ # -0.76, -0.82, -0.88, -0.92, -0.96, -0.98, -1.00, -1.00, -1.00, -0.99,
17
+ # -0.96, -0.93, -0.89, -0.84, -0.78, -0.71, -0.64, -0.56, -0.47, -0.38,
18
+ # ]
19
+ # g = Gruff::Bezier.new
20
+ # g.data 'sin', dataset
21
+ # g.write('bezier.png')
22
+ #
3
23
  class Gruff::Bezier < Gruff::Base
4
24
  def draw
5
25
  super
6
26
 
7
- return unless @has_data
27
+ return unless data_given?
8
28
 
9
- @x_increment = @graph_width / (@column_count - 1).to_f
29
+ x_increment = @graph_width / (column_count - 1).to_f
10
30
 
11
- @norm_data.each do |data_row|
12
- poly_points = Array.new
13
- @d = @d.fill data_row[DATA_COLOR_INDEX]
31
+ store.norm_data.each do |data_row|
32
+ poly_points = []
14
33
 
15
34
  data_row[1].each_with_index do |data_point, index|
16
35
  # Use incremented x and scaled y
17
- new_x = @graph_left + (@x_increment * index)
36
+ new_x = @graph_left + (x_increment * index)
18
37
  new_y = @graph_top + (@graph_height - data_point * @graph_height)
19
38
 
20
39
  if index == 0 && RUBY_PLATFORM != 'java'
@@ -27,20 +46,16 @@ class Gruff::Bezier < Gruff::Base
27
46
 
28
47
  draw_label(new_x, index)
29
48
  end
30
-
31
- @d = @d.fill_opacity 0.0
32
- @d = @d.stroke data_row[DATA_COLOR_INDEX]
33
- @d = @d.stroke_width clip_value_if_greater_than(@columns / (@norm_data.first[1].size * 4), 5.0)
49
+
50
+ stroke_width = clip_value_if_greater_than(@columns / (store.norm_data.first[1].size * 4), 5.0)
34
51
 
35
52
  if RUBY_PLATFORM == 'java'
36
- @d = @d.polyline(*poly_points)
53
+ Gruff::Renderer::Polyline.new(color: data_row.color, width: stroke_width).render(poly_points)
37
54
  else
38
- @d = @d.bezier(*poly_points)
55
+ Gruff::Renderer::Bezier.new(color: data_row.color, width: stroke_width).render(poly_points)
39
56
  end
40
57
  end
41
58
 
42
- @d.draw(@base_image)
59
+ Gruff::Renderer.finish
43
60
  end
44
-
45
-
46
61
  end
@@ -1,52 +1,53 @@
1
- require File.dirname(__FILE__) + '/base'
1
+ # frozen_string_literal: true
2
+
3
+ require 'gruff/base'
2
4
  require 'gruff/themes'
3
5
 
6
+ #
7
+ # A bullet graph is a variation of a bar graph.
4
8
  # http://en.wikipedia.org/wiki/Bullet_graph
9
+ #
10
+ # Here's how to set up a Gruff::Bullet.
11
+ #
12
+ # g = Gruff::Bullet.new
13
+ # g.title = 'Monthly Revenue'
14
+ # g.data 75, 100, { target: 80, low: 50, high: 90 }
15
+ # g.write('bullet.png')
16
+ #
5
17
  class Gruff::Bullet < Gruff::Base
6
-
7
- def initialize(target_width="400x40")
8
- if not Numeric === target_width
9
- geometric_width, geometric_height = target_width.split('x')
10
- @columns = geometric_width.to_f
11
- @rows = geometric_height.to_f
18
+ def initialize(target_width = '400x40')
19
+ if target_width.is_a?(String)
20
+ @columns, @rows = target_width.split('x').map(&:to_f)
12
21
  else
13
22
  @columns = target_width.to_f
14
23
  @rows = target_width.to_f / 5.0
15
24
  end
25
+ @columns.freeze
26
+ @rows.freeze
16
27
 
28
+ initialize_graph_scale
17
29
  initialize_ivars
30
+ initialize_store
18
31
 
19
- reset_themes
20
32
  self.theme = Gruff::Themes::GREYSCALE
33
+ end
34
+
35
+ def initialize_ivars
36
+ super
37
+
21
38
  @title_font_size = 20
22
39
  end
40
+ private :initialize_ivars
23
41
 
24
- def data(value, maximum_value, options={})
42
+ def data(value, maximum_value, options = {})
25
43
  @value = value.to_f
26
- @maximum_value = maximum_value.to_f
44
+ self.maximum_value = maximum_value.to_f
27
45
  @options = options
28
- @options.map { |k, v| @options[k] = v.to_f if v === Numeric }
46
+ @options.map { |k, v| @options[k] = v.to_f if v.is_a?(Numeric) }
29
47
  end
30
48
 
31
- # def setup_drawing
32
- # # Maybe should be done in one of the following functions for more granularity.
33
- # unless @has_data
34
- # draw_no_data()
35
- # return
36
- # end
37
- #
38
- # normalize()
39
- # setup_graph_measurements()
40
- # sort_norm_data() if @sort # Sort norm_data with avg largest values set first (for display)
41
- #
42
- # draw_legend()
43
- # draw_line_markers()
44
- # draw_axis_labels()
45
- # draw_title
46
- # end
47
-
48
49
  def draw
49
- # TODO Left label
50
+ # TODO: Left label
50
51
  # TODO Bottom labels and markers
51
52
  # @graph_bottom
52
53
  # Calculations are off 800x???
@@ -55,57 +56,50 @@ class Gruff::Bullet < Gruff::Base
55
56
 
56
57
  draw_title
57
58
 
58
- @margin = 30.0
59
- @thickness = @raw_rows / 6.0
60
- @right_margin = @margin
61
- @graph_left = @title_width * 1.3 rescue @margin # HACK Need to calculate real width
62
- @graph_width = @raw_columns - @graph_left - @right_margin
63
- @graph_height = @thickness * 3.0
59
+ title_width = calculate_width(@title_font_size, @title)
60
+ margin = 30.0
61
+ thickness = @raw_rows / 6.0
62
+ right_margin = margin
63
+ graph_left = [title_width * 1.3, margin].max
64
+ graph_width = @raw_columns - graph_left - right_margin
65
+ graph_height = thickness * 3.0
64
66
 
65
67
  # Background
66
- @d = @d.fill @colors[0]
67
- @d = @d.rectangle(@graph_left, 0, @graph_left + @graph_width, @graph_height)
68
+ rect_renderer = Gruff::Renderer::Rectangle.new(color: @colors[0])
69
+ rect_renderer.render(graph_left, 0, graph_left + graph_width, graph_height)
68
70
 
69
71
  [:high, :low].each_with_index do |indicator, index|
70
- next unless @options.has_key?(indicator)
71
- @d = @d.fill @colors[index + 1]
72
- indicator_width_x = @graph_left + @graph_width * (@options[indicator] / @maximum_value)
73
- @d = @d.rectangle(@graph_left, 0, indicator_width_x, @graph_height)
72
+ next unless @options.key?(indicator)
73
+
74
+ indicator_width_x = graph_left + graph_width * (@options[indicator] / maximum_value)
75
+
76
+ rect_renderer = Gruff::Renderer::Rectangle.new(color: @colors[index + 1])
77
+ rect_renderer.render(graph_left, 0, indicator_width_x, graph_height)
74
78
  end
75
79
 
76
- if @options.has_key?(:target)
77
- @d = @d.fill @font_color
78
- target_x = @graph_left + @graph_width * (@options[:target] / @maximum_value)
79
- half_thickness = @thickness / 2.0
80
- @d = @d.rectangle(target_x, half_thickness, target_x + half_thickness, @thickness * 2 + half_thickness)
80
+ if @options.key?(:target)
81
+ target_x = graph_left + graph_width * (@options[:target] / maximum_value)
82
+ half_thickness = thickness / 2.0
83
+
84
+ rect_renderer = Gruff::Renderer::Rectangle.new(color: @font_color)
85
+ rect_renderer.render(target_x, half_thickness, target_x + half_thickness, thickness * 2 + half_thickness)
81
86
  end
82
87
 
83
88
  # Value
84
- @d = @d.fill @font_color
85
- @d = @d.rectangle(@graph_left, @thickness, @graph_left + @graph_width * (@value / @maximum_value), @thickness * 2)
89
+ rect_renderer = Gruff::Renderer::Rectangle.new(color: @font_color)
90
+ rect_renderer.render(graph_left, thickness, graph_left + graph_width * (@value / maximum_value), thickness * 2)
86
91
 
87
- @d.draw(@base_image)
92
+ Gruff::Renderer.finish
88
93
  end
89
94
 
95
+ private
96
+
90
97
  def draw_title
91
- return unless @title
92
-
93
- @font_height = calculate_caps_height(scale_fontsize(@title_font_size))
94
- @title_width = calculate_width(@title_font_size, @title)
95
-
96
- @d.fill = @font_color
97
- @d.font = @font if @font
98
- @d.stroke('transparent')
99
- @d.font_weight = NormalWeight
100
- @d.pointsize = scale_fontsize(@title_font_size)
101
- @d.gravity = NorthWestGravity
102
- @d = @d.annotate_scaled(*[
103
- @base_image,
104
- 1.0, 1.0,
105
- @font_height/2, @font_height/2,
106
- @title,
107
- @scale
108
- ])
109
- end
98
+ return if hide_title?
99
+
100
+ font_height = calculate_caps_height(scale_fontsize(@title_font_size))
110
101
 
102
+ text_renderer = Gruff::Renderer::Text.new(@title, font: @font, size: @title_font_size, color: @font_color)
103
+ text_renderer.add_to_render_queue(1.0, 1.0, font_height / 2, font_height / 2, Magick::NorthWestGravity)
104
+ end
111
105
  end
@@ -1,105 +1,71 @@
1
- require File.dirname(__FILE__) + '/base'
1
+ # frozen_string_literal: true
2
2
 
3
- ##
4
- # Graph with dots and labels along a vertical access
5
- # see: 'Creating More Effective Graphs' by Robbins
3
+ require 'gruff/base'
6
4
 
5
+ #
6
+ # Graph with dots and labels along a vertical access.
7
+ # see: 'Creating More Effective Graphs' by Robbins
8
+ #
9
+ # Here's how to set up a Gruff::Dot.
10
+ #
11
+ # g = Gruff::Dot.new
12
+ # g.title = 'Dot Graph'
13
+ # g.data :Art, [0, 5, 8, 15]
14
+ # g.data :Philosophy, [10, 3, 2, 8]
15
+ # g.data :Science, [2, 15, 8, 11]
16
+ # g.write('dot.png')
17
+ #
7
18
  class Gruff::Dot < Gruff::Base
8
-
9
19
  def draw
10
20
  @has_left_labels = true
11
21
  super
12
22
 
13
- return unless @has_data
23
+ return unless data_given?
14
24
 
15
25
  # Setup spacing.
16
26
  #
17
27
  spacing_factor = 1.0
18
28
 
19
- @items_width = @graph_height / @column_count.to_f
20
- @item_width = @items_width * spacing_factor / @norm_data.size
21
- @d = @d.stroke_opacity 0.0
22
- padding = (@items_width * (1 - spacing_factor)) / 2
29
+ items_width = @graph_height / column_count.to_f
30
+ item_width = items_width * spacing_factor / store.length
31
+ padding = (items_width * (1 - spacing_factor)) / 2
23
32
 
24
- @norm_data.each_with_index do |data_row, row_index|
25
- data_row[DATA_VALUES_INDEX].each_with_index do |data_point, point_index|
33
+ store.norm_data.each_with_index do |data_row, row_index|
34
+ data_row.points.each_with_index do |data_point, point_index|
26
35
  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
36
+ y_pos = @graph_top + (items_width * point_index) + padding + (items_width.to_f / 2.0).round
28
37
 
29
38
  if row_index == 0
30
- @d = @d.stroke(@marker_color)
31
- @d = @d.fill(@marker_color)
32
- @d = @d.stroke_width 1.0
33
- @d = @d.stroke_opacity 0.1
34
- @d = @d.fill_opacity 0.1
35
- @d = @d.line(@graph_left, y_pos, @graph_left + @graph_width, y_pos)
36
- @d = @d.fill_opacity 1
39
+ Gruff::Renderer::Line.new(color: @marker_color).render(@graph_left, y_pos, @graph_left + @graph_width, y_pos)
37
40
  end
38
41
 
39
- @d = @d.fill data_row[DATA_COLOR_INDEX]
40
- @d = @d.stroke('transparent')
41
- @d = @d.circle(x_pos, y_pos, x_pos + (@item_width.to_f/3.0).round, y_pos)
42
+ Gruff::Renderer::Circle.new(color: data_row.color).render(x_pos, y_pos, x_pos + (item_width.to_f / 3.0).round, y_pos)
42
43
 
43
44
  draw_label(y_pos, point_index)
44
45
  end
45
-
46
46
  end
47
47
 
48
- @d.draw(@base_image)
48
+ Gruff::Renderer.finish
49
49
  end
50
50
 
51
- protected
51
+ protected
52
52
 
53
53
  # Instead of base class version, draws vertical background lines and label
54
54
  def draw_line_markers
55
55
  return if @hide_line_markers
56
56
 
57
- @d = @d.stroke_antialias false
58
-
59
- # Draw horizontal line markers and annotate with numbers
60
- @d = @d.stroke(@marker_color)
61
- @d = @d.stroke_width 1
62
- if @y_axis_increment
63
- increment = @y_axis_increment
64
- number_of_lines = (@spread / @y_axis_increment).to_i
65
- else
66
- # Try to use a number of horizontal lines that will come out even.
67
- #
68
- # TODO Do the same for larger numbers...100, 75, 50, 25
69
- if @marker_count.nil?
70
- (3..7).each do |lines|
71
- if @spread % lines == 0.0
72
- @marker_count = lines
73
- break
74
- end
75
- end
76
- @marker_count ||= 5
77
- end
78
- # TODO Round maximum marker value to a round number like 100, 0.1, 0.5, etc.
79
- @increment = (@spread > 0 && @marker_count > 0) ? significant(@spread / @marker_count) : 1
80
-
81
- number_of_lines = @marker_count
82
- increment = @increment
83
- end
57
+ (0..@marker_count).each do |index|
58
+ marker_label = minimum_value + index * @increment
59
+ x = @graph_left + (marker_label - minimum_value) * @graph_width / @spread
84
60
 
85
- (0..number_of_lines).each do |index|
86
- marker_label = @minimum_value + index * increment
87
- x = @graph_left + (marker_label - @minimum_value) * @graph_width / @spread
88
- @d = @d.line(x, @graph_bottom, x, @graph_bottom + 0.5 * LABEL_MARGIN)
61
+ line_renderer = Gruff::Renderer::Line.new(color: @marker_color, shadow_color: @marker_shadow_color)
62
+ line_renderer.render(x, @graph_bottom, x, @graph_bottom + 5)
89
63
 
90
64
  unless @hide_line_numbers
91
- @d.fill = @font_color
92
- @d.font = @font if @font
93
- @d.stroke = 'transparent'
94
- @d.pointsize = scale_fontsize(@marker_font_size)
95
- @d.gravity = CenterGravity
96
- # TODO Center text over line
97
- @d = @d.annotate_scaled(@base_image,
98
- 0, 0, # Width of box to draw text in
99
- x, @graph_bottom + (LABEL_MARGIN * 2.0), # Coordinates of text
100
- label(marker_label, increment), @scale)
101
- end # unless
102
- @d = @d.stroke_antialias true
65
+ label = label(marker_label, @increment)
66
+ text_renderer = Gruff::Renderer::Text.new(label, font: @font, size: @marker_font_size, color: @font_color)
67
+ text_renderer.add_to_render_queue(0, 0, x, @graph_bottom + (LABEL_MARGIN * 1.5), Magick::CenterGravity)
68
+ end
103
69
  end
104
70
  end
105
71
 
@@ -107,19 +73,9 @@ class Gruff::Dot < Gruff::Base
107
73
  # Draw on the Y axis instead of the X
108
74
 
109
75
  def draw_label(y_offset, index)
110
- if !@labels[index].nil? && @labels_seen[index].nil?
111
- @d.fill = @font_color
112
- @d.font = @font if @font
113
- @d.stroke = 'transparent'
114
- @d.font_weight = NormalWeight
115
- @d.pointsize = scale_fontsize(@marker_font_size)
116
- @d.gravity = EastGravity
117
- @d = @d.annotate_scaled(@base_image,
118
- 1, 1,
119
- -@graph_left + LABEL_MARGIN * 2.0, y_offset,
120
- @labels[index], @scale)
121
- @labels_seen[index] = 1
76
+ draw_unique_label(index) do
77
+ text_renderer = Gruff::Renderer::Text.new(@labels[index], font: @font, size: @marker_font_size, color: @font_color)
78
+ text_renderer.add_to_render_queue(@graph_left - LABEL_MARGIN, 1.0, 0.0, y_offset, Magick::EastGravity)
122
79
  end
123
80
  end
124
-
125
81
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # Original Author: David Stokar
5
+ #
6
+ # This class perfoms the y coordinats conversion for the bar class.
7
+ #
8
+ # There are three cases:
9
+ #
10
+ # 1. Bars all go from zero in positive direction
11
+ # 2. Bars all go from zero to negative direction
12
+ # 3. Bars either go from zero to positive or from zero to negative
13
+ #
14
+ # @private
15
+ class Gruff::BarConversion
16
+ attr_writer :mode
17
+ attr_writer :zero
18
+ attr_writer :graph_top
19
+ attr_writer :graph_height
20
+ attr_writer :minimum_value
21
+ attr_writer :spread
22
+
23
+ def get_left_y_right_y_scaled(data_point)
24
+ result = []
25
+
26
+ case @mode
27
+ when 1
28
+ # minimum value >= 0 ( only positive values )
29
+ result[0] = @graph_top + @graph_height * (1 - data_point) + 1
30
+ result[1] = @graph_top + @graph_height - 1
31
+ when 2
32
+ # only negative values
33
+ result[0] = @graph_top + 1
34
+ result[1] = @graph_top + @graph_height * (1 - data_point) - 1
35
+ when 3
36
+ # positive and negative values
37
+ val = data_point - @minimum_value / @spread
38
+ result[0] = @graph_top + @graph_height * (1 - (val - @zero)) + 1
39
+ result[1] = @graph_top + @graph_height * (1 - @zero) - 1
40
+ else
41
+ result[0] = 0.0
42
+ result[1] = 0.0
43
+ end
44
+
45
+ result
46
+ end
47
+ end