gruff 0.13.0-java → 0.16.0-java

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46eb3259410a2c7b797d4482f37db956ee9f7b69ab00770d9980522666e58f38
4
- data.tar.gz: 3ddd8e3ecf26ecf8315173e1c6afc18b37cb6d0d9d487b3ff24a3a4623184e05
3
+ metadata.gz: 03a1c8455536dad68e5d325a51416807d32595aee6e4be75ef214c1b00e0df06
4
+ data.tar.gz: fa90b50b714c8464f6b82260f3ec9598edb57cf4b03ffcb8b451083e9bd1a307
5
5
  SHA512:
6
- metadata.gz: 4792f0f6dc06df61238e6312988bb0ac41994cca4b30feffbda7253fb51d26c7cbbecb8152760a7eef1881e089b83a1976a333e9f1f80e8a1f5377f0155dfe3c
7
- data.tar.gz: 24f43e7dd7f304fe2a3e44afe56d1f235ba205495de69f7b25fba74280b730619f60af3d51ee854b89ad00a73e9509a3052c514dd4adce56e00bff16c4233a1e
6
+ metadata.gz: 180bb66623c99daf3b89febea4059ed0d1f655b5fdee1da046e78174d0ea2efdf26e3fbc1de8bc18765cf9ab5cbe8bc52cb22fd01deeb25c377210340506bcfb
7
+ data.tar.gz: 05e9d6c86ee5ccee8bafc37fe1843f041f2a91f82aa7bbfb77c11fd05c9d64b2192d4b56dfaff0bc3f5d5db925e13ba057179843e0265873d2e1c7659582235d
@@ -0,0 +1,79 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ lint:
11
+ runs-on: ubuntu-20.04
12
+ timeout-minutes: 20
13
+ name: Lint
14
+ steps:
15
+ - uses: actions/checkout@v3
16
+ with:
17
+ ref: ${{ github.event.pull_request.head.sha }}
18
+ - name: Set up Ruby 2.5
19
+ uses: ruby/setup-ruby@master
20
+ with:
21
+ ruby-version: '2.5'
22
+ bundler-cache: true
23
+ - name: Install dependencies
24
+ run: bundle install --path=vendor/bundle --jobs 4 --retry 3
25
+ - name: RuboCop Problem Matchers
26
+ uses: r7kamura/rubocop-problem-matchers-action@v1.1.0
27
+ - name: Run tests
28
+ run: bundle exec rubocop
29
+
30
+ test-ruby:
31
+ runs-on: ubuntu-20.04
32
+ timeout-minutes: 20
33
+ strategy:
34
+ matrix:
35
+ ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1']
36
+ imagemagick-version:
37
+ - { full: 7.1.0-31, major-minor: '7.0' }
38
+ name: Ruby ${{ matrix.ruby-version }}
39
+ steps:
40
+ - uses: actions/checkout@v3
41
+ - name: Cache ImageMagick
42
+ uses: actions/cache@v3
43
+ with:
44
+ path: ./build-ImageMagick
45
+ key: v1-linux-imagemagick-${{ matrix.imagemagick-version.full }}
46
+ restore-keys: |
47
+ v1-linux-imagemagick-${{ matrix.imagemagick-version.full }}
48
+ - name: Install ImageMagick ${{ matrix.imagemagick-version.full }}
49
+ run: |
50
+ export IMAGEMAGICK_VERSION=${{ matrix.imagemagick-version.full }}
51
+ ./before_install_linux.sh
52
+ - name: Set up Ruby
53
+ uses: ruby/setup-ruby@master
54
+ with:
55
+ ruby-version: ${{ matrix.ruby-version }}
56
+ bundler-cache: false
57
+ - name: Install dependencies
58
+ run: bundle install --path=vendor/bundle --jobs 4 --retry 3
59
+ - name: Run tests
60
+ run: bundle exec rake
61
+
62
+ test-jruby:
63
+ runs-on: ubuntu-20.04
64
+ timeout-minutes: 20
65
+ strategy:
66
+ matrix:
67
+ ruby-version: ['9.2.20.1', '9.3.4.0']
68
+ name: JRuby ${{ matrix.ruby-version }}
69
+ steps:
70
+ - uses: actions/checkout@v3
71
+ - name: Set up Ruby
72
+ uses: ruby/setup-ruby@master
73
+ with:
74
+ ruby-version: jruby-${{ matrix.ruby-version }}
75
+ bundler-cache: true
76
+ - name: Install dependencies
77
+ run: bundle install --path=vendor/bundle --jobs 4 --retry 3
78
+ - name: Run tests
79
+ run: bundle exec rake
data/.rubocop.yml CHANGED
@@ -1,13 +1,17 @@
1
- inherit_from: .rubocop_todo.yml
2
- require: rubocop-performance
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rake
3
4
 
4
5
  AllCops:
5
6
  EnabledByDefault: true
6
- TargetRubyVersion: 2.4
7
+ TargetRubyVersion: 2.5
7
8
  Exclude:
8
9
  - 'vendor/bundle/**/*'
9
10
  - 'rails_generators/gruff/**/*'
10
11
 
12
+ Metrics:
13
+ Enabled: false
14
+
11
15
  Gemspec/OrderedDependencies:
12
16
  Enabled: false
13
17
 
@@ -17,15 +21,9 @@ Gemspec/RequiredRubyVersion:
17
21
  Layout/AccessModifierIndentation:
18
22
  EnforcedStyle: outdent
19
23
 
20
- Layout/ClassStructure:
21
- Enabled: false
22
-
23
24
  Layout/FirstMethodArgumentLineBreak:
24
25
  Enabled: false
25
26
 
26
- Layout/LeadingCommentSpace:
27
- Enabled: false
28
-
29
27
  Layout/LineLength:
30
28
  Max: 150
31
29
 
@@ -35,22 +33,34 @@ Layout/MultilineMethodArgumentLineBreaks:
35
33
  Layout/MultilineAssignmentLayout:
36
34
  EnforcedStyle: same_line
37
35
 
38
- Lint/AssignmentInCondition:
36
+ Layout/RedundantLineBreak:
37
+ Enabled: false
38
+
39
+ Layout/SingleLineBlockChain:
39
40
  Enabled: false
40
41
 
41
42
  Lint/ConstantResolution:
42
43
  Enabled: false
43
44
 
45
+ Lint/FloatComparison:
46
+ Enabled: false
47
+
44
48
  Lint/NumberConversion:
45
49
  Enabled: false
46
50
 
47
- Style/AccessorGrouping:
51
+ Naming/MemoizedInstanceVariableName:
48
52
  Enabled: false
49
53
 
50
- Style/ClassAndModuleChildren:
54
+ Naming/MethodParameterName:
55
+ Enabled: false
56
+
57
+ Naming/VariableNumber:
58
+ Enabled: false
59
+
60
+ Style/AccessorGrouping:
51
61
  Enabled: false
52
62
 
53
- Style/ConditionalAssignment:
63
+ Style/ClassAndModuleChildren:
54
64
  Enabled: false
55
65
 
56
66
  Style/ConstantVisibility:
@@ -62,15 +72,15 @@ Style/Copyright:
62
72
  Style/Documentation:
63
73
  Enabled: true
64
74
 
65
- Style/Encoding:
75
+ Style/DocumentationMethod:
76
+ Enabled: false
77
+
78
+ Style/DocumentDynamicEvalDefinition:
66
79
  Enabled: false
67
80
 
68
81
  Style/FormatString:
69
82
  EnforcedStyle: sprintf
70
83
 
71
- Style/FormatStringToken:
72
- Enabled: false
73
-
74
84
  Style/GuardClause:
75
85
  Enabled: false
76
86
 
@@ -92,15 +102,9 @@ Style/MethodCallWithArgsParentheses:
92
102
  Style/MissingElse:
93
103
  Enabled: false
94
104
 
95
- Style/MutableConstant:
96
- Enabled: false
97
-
98
105
  Style/Next:
99
106
  Enabled: false
100
107
 
101
- Style/NumericLiterals:
102
- Enabled: false
103
-
104
108
  Style/NumericPredicate:
105
109
  Enabled: false
106
110
 
@@ -113,17 +117,11 @@ Style/RedundantBegin:
113
117
  Style/SingleLineBlockParams:
114
118
  Enabled: false
115
119
 
116
- Style/SpecialGlobalVars:
117
- Enabled: false
118
-
119
120
  Style/StructInheritance:
120
121
  Enabled: false
121
122
 
122
- Style/SymbolArray:
123
- Enabled: false
124
-
125
- Style/TernaryParentheses:
123
+ Performance/ChainArrayAllocation:
126
124
  Enabled: false
127
125
 
128
- Performance/ChainArrayAllocation:
126
+ Performance/StringReplacement:
129
127
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,48 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.16.0
4
+ - Add Candlestick (#575)
5
+ - Add BoxPlot (#574)
6
+ - Raise exception if less data set was given in Gruff::Spider (#573)
7
+ - Adjust default label offset value in Gruff::Pie
8
+ - Remove has_left_labels from attribute (#571)
9
+ - Remove center_labels_over_point from attribute (#570)
10
+ - Adjust legend label / box position
11
+ - Fix right margin when truncate the label
12
+ - Adjust axis label position
13
+ - Adjust left label margin
14
+ - Fix axis label position with hide_line_markers
15
+ - Fix margin of value label in Bar/StackedBar (#568)
16
+ - Fix label position in Gruff::Spider (#567)
17
+ - Fix axis label position with legend_at_bottom
18
+ - Fix axis label position with hide_line_markers
19
+ - Refactor: Remove instance variable usage
20
+ - Remove Gruff::Scene (#566)
21
+ - Fix exception with zero value in StackBar (#565)
22
+ - Fix segment spacing in SideStackedBar (#564)
23
+ - Fix margin of value label in SideBar/SideStackedBar (#563)
24
+ - Raise exception if negative values were given in stacked graph (#562)
25
+ - Fix centering in value label position (#561)
26
+ - Fix duck typing support in Gruff::Histogram (#560)
27
+ - Fix start drawing position to top in Pie and enabled sort option by default (#559)
28
+
29
+ ## 0.15.0
30
+ - Fix SideStackedBar which bars overlap on the coordinate axes if data contains 0 (#558)
31
+ - Lazy loading library to reduce memory usage (#556)
32
+ - Drop Ruby 2.4 support (#554)
33
+ - Fix sort drawing in Gruff::Line (#553)
34
+ - Fix color value handling in Line#dataxy method (#552)
35
+
36
+ ## 0.14.0
37
+ - Update rails template (#547)
38
+ - Remove singleton in order to support multi-thread processing (#546)
39
+ - Fix bug in Gruff::Scatter that X coordinate value is wrong if set value in x_axis_increment (#534)
40
+ - Add marker_x_count attribute in Gruff::Line (#532)
41
+ - Add label_formatting attribute in Gruff::Pie (#531)
42
+ - Removed the ability to inject custom PieSlice classes from the outside (#530)
43
+ - Remove Gruff::PhotoBar (#513)
44
+ - Deprecate last_series_goes_on_bottom attribute in Gruff::StackedArea (#512)
45
+
3
46
  ## 0.13.0
4
47
  - Allow to customize label value with lambda (#510)
5
48
  - Rename enable_vertical_line_markers attribute to show_vertical_markers (#509)
data/README.md CHANGED
@@ -126,6 +126,13 @@ In progress!
126
126
 
127
127
  ![Histogram chart](https://raw.github.com/topfunky/gruff/master/test/expected/histogram.png)
128
128
 
129
+ ### Box plot
130
+
131
+ ![Box plot](https://raw.github.com/topfunky/gruff/master/test/expected/box_plot.png)
132
+
133
+ ### Candlestick
134
+
135
+ ![Candlestick](https://raw.github.com/topfunky/gruff/master/test/expected/candlestick.png)
129
136
 
130
137
  ## Documentation
131
138
 
@@ -133,23 +140,22 @@ http://www.rubydoc.info/github/topfunky/gruff/frames
133
140
 
134
141
  ## Supported Ruby Versions
135
142
 
136
- We aim to support all Ruby implementations supporting Ruby language level 1.9.3
137
- or later. Currently we are running CI for MRI, JRuby, and Rubinius.
143
+ - Ruby 2.5 or later
144
+ - JRuby 9.2.x or later
138
145
 
139
146
  ## Development
140
147
  1. Build docker image
141
148
  ```sh
142
- $ ./docker/build.sh
149
+ $ ./docker-build.sh
143
150
  ```
144
151
 
145
152
  2. Launch docker image
146
153
  ```sh
147
- $ ./docker/launch.sh
154
+ $ ./docker-launch.sh
148
155
  ```
149
156
 
150
157
  3. Run tests
151
158
  ```sh
152
- $ bundle install
153
159
  $ bundle exec rake
154
160
  ```
155
161
 
data/gruff.gemspec CHANGED
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  # frozen_string_literal: true
3
2
 
4
3
  lib = File.expand_path('lib')
@@ -10,12 +9,9 @@ Gem::Specification.new do |s|
10
9
  s.name = 'gruff'
11
10
  s.version = Gruff::VERSION
12
11
  s.authors = ['Geoffrey Grosenbach', 'Uwe Kubosch']
13
- s.date = Date.today.to_s
14
12
  s.description = 'Beautiful graphs for one or multiple datasets. Can be used on websites or in documents.'
15
13
  s.email = 'boss@topfunky.com'
16
- s.files = `git ls-files`.split.reject do |f|
17
- f =~ /^test|^docker|^Rakefile/
18
- end
14
+ s.files = `git ls-files`.split.grep_v(/^test|^docker|^before_install_linux.sh|^Rakefile/i)
19
15
  s.homepage = 'https://github.com/topfunky/gruff'
20
16
  s.require_paths = %w[lib]
21
17
  s.summary = 'Beautiful graphs for one or multiple datasets.'
@@ -28,16 +24,18 @@ Gem::Specification.new do |s|
28
24
  s.platform = 'java'
29
25
  s.add_dependency 'rmagick4j'
30
26
  else
31
- s.add_dependency 'rmagick'
32
- s.add_development_dependency 'rubocop', '~> 1.12.1'
33
- s.add_development_dependency 'rubocop-performance', '~> 1.10.2'
27
+ s.add_dependency 'rmagick', '>= 4.2'
28
+ s.add_development_dependency 'rubocop', '~> 1.27.0'
29
+ s.add_development_dependency 'rubocop-performance', '~> 1.13.3'
30
+ s.add_development_dependency 'rubocop-rake', '~> 0.6.0'
34
31
  end
35
32
  s.add_dependency 'histogram'
36
- s.required_ruby_version = '>= 2.4.0'
33
+ s.required_ruby_version = '>= 2.5.0'
37
34
 
38
35
  s.add_development_dependency 'rake'
39
- s.add_development_dependency 'parallel'
40
36
  s.add_development_dependency 'minitest-reporters'
41
37
  s.add_development_dependency 'simplecov'
42
38
  s.add_development_dependency 'yard', '~> 0.9.25'
39
+
40
+ s.metadata['rubygems_mfa_required'] = 'true'
43
41
  end
@@ -14,10 +14,12 @@
14
14
  # g.write('accumulator_bar.png')
15
15
  #
16
16
  class Gruff::AccumulatorBar < Gruff::StackedBar
17
- def draw
17
+ private
18
+
19
+ def setup_data
18
20
  raise(Gruff::IncorrectNumberOfDatasetsException) unless store.length == 1
19
21
 
20
- accum_array = store.data.first.points[0..-2].reduce([0]) { |a, v| a << a.last + v }
22
+ accum_array = store.data.first.points[0..-2].reduce([0]) { |a, v| a << (a.last + v) }
21
23
  data 'Accumulator', accum_array
22
24
  set_colors
23
25
  store.reverse!
data/lib/gruff/area.rb CHANGED
@@ -20,20 +20,17 @@ class Gruff::Area < Gruff::Base
20
20
  # Specifies the stroke width in line around area graph. Default is +2.0+.
21
21
  attr_writer :stroke_width
22
22
 
23
- def initialize_ivars
23
+ private
24
+
25
+ def initialize_attributes
24
26
  super
25
27
  @sorted_drawing = true
26
28
  @fill_opacity = 0.85
27
29
  @stroke_width = 2.0
28
30
  end
29
- private :initialize_ivars
30
-
31
- def draw
32
- super
33
-
34
- return unless data_given?
35
31
 
36
- x_increment = @graph_width / (column_count - 1).to_f
32
+ def draw_graph
33
+ x_increment = @graph_width / (column_count - 1)
37
34
 
38
35
  store.norm_data.each do |data_row|
39
36
  poly_points = []
@@ -41,7 +38,7 @@ class Gruff::Area < Gruff::Base
41
38
  data_row.points.each_with_index do |data_point, index|
42
39
  # Use incremented x and scaled y
43
40
  new_x = @graph_left + (x_increment * index)
44
- new_y = @graph_top + (@graph_height - data_point * @graph_height)
41
+ new_y = @graph_top + (@graph_height - (data_point * @graph_height))
45
42
 
46
43
  poly_points << new_x
47
44
  poly_points << new_y
@@ -51,11 +48,11 @@ class Gruff::Area < Gruff::Base
51
48
 
52
49
  # Add closing points, draw polygon
53
50
  poly_points << @graph_right
54
- poly_points << @graph_bottom - 1
51
+ poly_points << (@graph_bottom - 1)
55
52
  poly_points << @graph_left
56
- poly_points << @graph_bottom - 1
53
+ poly_points << (@graph_bottom - 1)
57
54
 
58
- Gruff::Renderer::Polygon.new(color: data_row.color, width: @stroke_width, opacity: @fill_opacity).render(poly_points)
55
+ Gruff::Renderer::Polygon.new(renderer, color: data_row.color, width: @stroke_width, opacity: @fill_opacity).render(poly_points)
59
56
  end
60
57
  end
61
58
  end
data/lib/gruff/bar.rb CHANGED
@@ -33,7 +33,25 @@ class Gruff::Bar < Gruff::Base
33
33
  # Prevent drawing of column labels below a bar graph. Default is +false+.
34
34
  attr_writer :hide_labels
35
35
 
36
- def initialize_ivars
36
+ # Value to avoid completely overwriting the coordinate axis
37
+ AXIS_MARGIN = 0.5
38
+ private_constant :AXIS_MARGIN
39
+
40
+ # Can be used to adjust the spaces between the bars.
41
+ # Accepts values between 0.00 and 1.00 where 0.00 means no spacing at all
42
+ # and 1 means that each bars' width is nearly 0 (so each bar is a simple
43
+ # line with no x dimension).
44
+ #
45
+ # Default value is +0.9+.
46
+ def spacing_factor=(space_percent)
47
+ raise ArgumentError, 'spacing_factor must be between 0.00 and 1.00' unless (space_percent >= 0) && (space_percent <= 1)
48
+
49
+ @spacing_factor = (1 - space_percent)
50
+ end
51
+
52
+ private
53
+
54
+ def initialize_attributes
37
55
  super
38
56
  @spacing_factor = 0.9
39
57
  @group_spacing = 10
@@ -41,57 +59,52 @@ class Gruff::Bar < Gruff::Base
41
59
  @show_labels_for_bar_values = false
42
60
  @hide_labels = false
43
61
  end
44
- private :initialize_ivars
45
62
 
46
- def draw
63
+ def setup_drawing
47
64
  # Labels will be centered over the left of the bar if
48
65
  # there are more labels than columns. This is basically the same
49
66
  # as where it would be for a line graph.
50
67
  @center_labels_over_point = (@labels.keys.length > column_count)
51
68
 
52
69
  super
53
- return unless data_given?
54
-
55
- draw_bars
56
- end
57
-
58
- # Can be used to adjust the spaces between the bars.
59
- # Accepts values between 0.00 and 1.00 where 0.00 means no spacing at all
60
- # and 1 means that each bars' width is nearly 0 (so each bar is a simple
61
- # line with no x dimension).
62
- #
63
- # Default value is +0.9+.
64
- def spacing_factor=(space_percent)
65
- raise ArgumentError, 'spacing_factor must be between 0.00 and 1.00' unless (space_percent >= 0) && (space_percent <= 1)
66
-
67
- @spacing_factor = (1 - space_percent)
68
70
  end
69
71
 
70
- protected
71
-
72
72
  def hide_labels?
73
73
  @hide_labels
74
74
  end
75
75
 
76
76
  def hide_left_label_area?
77
- @hide_line_markers
77
+ @hide_line_markers && @y_axis_label.nil?
78
78
  end
79
79
 
80
80
  def hide_bottom_label_area?
81
- hide_labels?
81
+ hide_labels? && @x_axis_label.nil? && @legend_at_bottom == false
82
82
  end
83
83
 
84
- # Value to avoid completely overwriting the coordinate axis
85
- AXIS_MARGIN = 0.5
84
+ def setup_graph_measurements
85
+ super
86
+ return if @hide_line_markers
87
+
88
+ if @show_labels_for_bar_values
89
+ proc_text_metrics = ->(text) { text_metrics(@marker_font, text) }
90
+
91
+ if maximum_value >= 0
92
+ _, metrics = Gruff::BarValueLabel.metrics(maximum_value, @label_formatting, proc_text_metrics)
93
+ @graph_top += metrics.height
94
+ end
86
95
 
87
- def draw_bars
96
+ @graph_height = @graph_bottom - @graph_top
97
+ end
98
+ end
99
+
100
+ def draw_graph
88
101
  # Setup spacing.
89
102
  #
90
103
  # Columns sit side-by-side.
91
104
  @bar_spacing ||= @spacing_factor # space between the bars
92
105
 
93
- bar_width = (@graph_width - calculate_spacing) / (column_count * store.length).to_f
94
- padding = (bar_width * (1 - @bar_spacing)) / 2
106
+ bar_width = (@graph_width - calculate_spacing) / (column_count * store.length)
107
+ padding = (bar_width * (1 - @bar_spacing)) / 2.0
95
108
 
96
109
  # Setup the BarConversion Object
97
110
  conversion = Gruff::BarConversion.new(
@@ -99,6 +112,8 @@ protected
99
112
  minimum_value: minimum_value, maximum_value: maximum_value, spread: @spread
100
113
  )
101
114
 
115
+ proc_text_metrics = ->(text) { text_metrics(@marker_font, text) }
116
+
102
117
  # iterate over all normalised data
103
118
  store.norm_data.each_with_index do |data_row, row_index|
104
119
  data_row.points.each_with_index do |data_point, point_index|
@@ -107,12 +122,12 @@ protected
107
122
  # Use incremented x and scaled y
108
123
  # x
109
124
  left_x = @graph_left + (bar_width * (row_index + point_index + ((store.length - 1) * point_index))) + padding + group_spacing
110
- right_x = left_x + bar_width * @bar_spacing
125
+ right_x = left_x + (bar_width * @bar_spacing)
111
126
  # y
112
127
  left_y, right_y = conversion.get_top_bottom_scaled(data_point)
113
128
 
114
129
  # create new bar
115
- rect_renderer = Gruff::Renderer::Rectangle.new(color: data_row.color)
130
+ rect_renderer = Gruff::Renderer::Rectangle.new(renderer, color: data_row.color)
116
131
  rect_renderer.render(left_x, left_y - AXIS_MARGIN, right_x, right_y - AXIS_MARGIN)
117
132
 
118
133
  # Calculate center based on bar_width and current row
@@ -122,8 +137,8 @@ protected
122
137
  draw_label(label_center, point_index)
123
138
  if @show_labels_for_bar_values
124
139
  bar_value_label = Gruff::BarValueLabel::Bar.new([left_x, left_y, right_x, right_y], store.data[row_index].points[point_index])
125
- bar_value_label.prepare_rendering(@label_formatting, bar_width) do |x, y, text|
126
- draw_value_label(x, y, text, true)
140
+ bar_value_label.prepare_rendering(@label_formatting, proc_text_metrics) do |x, y, text, _text_width, text_height|
141
+ draw_value_label(bar_width * @bar_spacing, text_height, x, y, text)
127
142
  end
128
143
  end
129
144
  end