gruff 0.14.0-java → 0.17.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +28 -12
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +20 -24
  5. data/CHANGELOG.md +52 -0
  6. data/README.md +10 -3
  7. data/gruff.gemspec +9 -10
  8. data/lib/gruff/accumulator_bar.rb +1 -1
  9. data/lib/gruff/area.rb +6 -4
  10. data/lib/gruff/bar.rb +53 -31
  11. data/lib/gruff/base.rb +292 -184
  12. data/lib/gruff/bezier.rb +4 -2
  13. data/lib/gruff/box_plot.rb +180 -0
  14. data/lib/gruff/bullet.rb +6 -6
  15. data/lib/gruff/candlestick.rb +120 -0
  16. data/lib/gruff/dot.rb +11 -12
  17. data/lib/gruff/font.rb +3 -0
  18. data/lib/gruff/helper/bar_conversion.rb +6 -10
  19. data/lib/gruff/helper/bar_mixin.rb +25 -0
  20. data/lib/gruff/helper/bar_value_label.rb +24 -40
  21. data/lib/gruff/helper/stacked_mixin.rb +19 -1
  22. data/lib/gruff/histogram.rb +9 -5
  23. data/lib/gruff/line.rb +49 -48
  24. data/lib/gruff/mini/legend.rb +11 -11
  25. data/lib/gruff/net.rb +23 -18
  26. data/lib/gruff/patch/rmagick.rb +0 -1
  27. data/lib/gruff/patch/string.rb +1 -0
  28. data/lib/gruff/pie.rb +26 -12
  29. data/lib/gruff/renderer/dash_line.rb +3 -2
  30. data/lib/gruff/renderer/dot.rb +28 -15
  31. data/lib/gruff/renderer/line.rb +1 -3
  32. data/lib/gruff/renderer/rectangle.rb +6 -2
  33. data/lib/gruff/renderer/renderer.rb +4 -8
  34. data/lib/gruff/renderer/text.rb +7 -1
  35. data/lib/gruff/scatter.rb +64 -56
  36. data/lib/gruff/side_bar.rb +64 -30
  37. data/lib/gruff/side_stacked_bar.rb +43 -54
  38. data/lib/gruff/spider.rb +52 -18
  39. data/lib/gruff/stacked_area.rb +18 -8
  40. data/lib/gruff/stacked_bar.rb +59 -29
  41. data/lib/gruff/store/xy_data.rb +2 -0
  42. data/lib/gruff/version.rb +1 -1
  43. data/lib/gruff.rb +67 -58
  44. metadata +17 -16
  45. data/.rubocop_todo.yml +0 -116
  46. data/lib/gruff/scene.rb +0 -200
  47. data/lib/gruff/store/custom_data.rb +0 -36
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'helper/stacked_mixin'
4
+
3
5
  #
4
6
  # Here's how to set up a Gruff::StackedBar.
5
7
  #
@@ -39,6 +41,16 @@ private
39
41
  @label_formatting = nil
40
42
  @show_labels_for_bar_values = false
41
43
  @hide_labels = false
44
+ @minimum_value = 0.0
45
+ end
46
+
47
+ def setup_drawing
48
+ # Labels will be centered over the left of the bar if
49
+ # there are more labels than columns. This is basically the same
50
+ # as where it would be for a line graph.
51
+ @center_labels_over_point = (@labels.keys.length > column_count)
52
+
53
+ super
42
54
  end
43
55
 
44
56
  def setup_data
@@ -46,47 +58,61 @@ private
46
58
  super
47
59
  end
48
60
 
61
+ def setup_graph_measurements
62
+ super
63
+ return if @hide_line_markers
64
+
65
+ if @show_labels_for_bar_values
66
+ if maximum_value >= 0
67
+ _, metrics = Gruff::BarValueLabel.metrics(maximum_value, @label_formatting, proc_text_metrics)
68
+ @graph_top += metrics.height
69
+ end
70
+
71
+ @graph_height = @graph_bottom - @graph_top
72
+ end
73
+ end
74
+
49
75
  # Draws a bar graph, but multiple sets are stacked on top of each other.
50
76
  def draw_graph
51
77
  # Setup spacing.
52
78
  #
53
79
  # Columns sit stacked.
54
- bar_width = @graph_width / column_count.to_f
80
+ bar_width = @graph_width / column_count
55
81
  padding = (bar_width * (1 - @bar_spacing)) / 2
56
82
 
57
- height = Array.new(column_count, 0)
58
- stack_bar_value_label = Gruff::BarValueLabel::StackedBar.new
83
+ # Setup the BarConversion Object
84
+ conversion = Gruff::BarConversion.new(
85
+ top: @graph_top, bottom: @graph_bottom,
86
+ minimum_value: minimum_value, maximum_value: maximum_value, spread: @spread
87
+ )
59
88
 
60
- store.norm_data.each_with_index do |data_row, row_index|
61
- data_row.points.each_with_index do |data_point, point_index|
62
- next if data_point == 0
89
+ normalized_stacked_bars.each_with_index do |stacked_bars, stacked_index|
90
+ total = 0
91
+ left_x = @graph_left + (bar_width * stacked_index) + padding
92
+ right_x = left_x + (bar_width * @bar_spacing)
63
93
 
64
- # Use incremented x and scaled y
65
- left_x = @graph_left + (bar_width * point_index) + padding
66
- left_y = @graph_top + (@graph_height -
67
- data_point * @graph_height -
68
- height[point_index]) + @segment_spacing
69
- right_x = left_x + bar_width * @bar_spacing
70
- right_y = @graph_top + @graph_height - height[point_index]
94
+ top_y = 0
95
+ stacked_bars.each do |bar|
96
+ next if bar.point == 0
71
97
 
72
- # update the total height of the current stacked bar
73
- height[point_index] += (data_point * @graph_height)
98
+ bottom_y, = conversion.get_top_bottom_scaled(total)
99
+ bottom_y -= @segment_spacing
100
+ top_y, = conversion.get_top_bottom_scaled(total + bar.point)
74
101
 
75
- rect_renderer = Gruff::Renderer::Rectangle.new(renderer, color: data_row.color)
76
- rect_renderer.render(left_x, left_y, right_x, right_y)
102
+ rect_renderer = Gruff::Renderer::Rectangle.new(renderer, color: bar.color)
103
+ rect_renderer.render(left_x, bottom_y, right_x, top_y)
77
104
 
78
- # Calculate center based on bar_width and current row
79
- label_center = left_x + bar_width * @bar_spacing / 2.0
80
- draw_label(label_center, point_index)
81
-
82
- bar_value_label = Gruff::BarValueLabel::Bar.new([left_x, left_y, right_x, right_y], store.data[row_index].points[point_index])
83
- stack_bar_value_label.add(bar_value_label, point_index)
105
+ total += bar.point
84
106
  end
85
- end
86
107
 
87
- if @show_labels_for_bar_values
88
- stack_bar_value_label.prepare_rendering(@label_formatting, bar_width) do |x, y, text|
89
- draw_value_label(x, y, text)
108
+ label_center = left_x + (bar_width * @bar_spacing / 2.0)
109
+ draw_label(label_center, stacked_index)
110
+
111
+ if @show_labels_for_bar_values
112
+ bar_value_label = Gruff::BarValueLabel::Bar.new([left_x, top_y, right_x, @graph_bottom], stacked_bars.sum(&:value))
113
+ bar_value_label.prepare_rendering(@label_formatting, proc_text_metrics) do |x, y, text, _text_width, text_height|
114
+ draw_value_label(bar_width * @bar_spacing, text_height, x, y, text)
115
+ end
90
116
  end
91
117
  end
92
118
  end
@@ -96,10 +122,14 @@ private
96
122
  end
97
123
 
98
124
  def hide_left_label_area?
99
- @hide_line_markers
125
+ @hide_line_markers && @y_axis_label.nil?
100
126
  end
101
127
 
102
128
  def hide_bottom_label_area?
103
- hide_labels?
129
+ hide_labels? && @x_axis_label.nil? && @legend_at_bottom == false
130
+ end
131
+
132
+ def proc_text_metrics
133
+ ->(text) { text_metrics(@marker_font, text) }
104
134
  end
105
135
  end
@@ -9,6 +9,8 @@ module Gruff
9
9
  super(label.to_s, Array(y_points), color, x_points)
10
10
  end
11
11
 
12
+ alias points y_points
13
+
12
14
  def x_points
13
15
  self[:x_points] || Array.new(y_points.length)
14
16
  end
data/lib/gruff/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gruff
4
- VERSION = '0.14.0'
4
+ VERSION = '0.17.0'
5
5
  end
data/lib/gruff.rb CHANGED
@@ -1,62 +1,71 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rmagick'
4
- require 'gruff/version'
5
-
6
- # Extra full path added to fix loading errors on some installations.
7
-
8
- %w[
9
- patch/rmagick
10
- patch/string
11
-
12
- font
13
- base
14
-
15
- helper/bar_conversion.rb
16
- helper/stacked_mixin
17
- helper/bar_value_label
18
-
19
- themes
20
- area
21
- bar
22
- bezier
23
- bullet
24
- dot
25
- histogram
26
- line
27
- net
28
- pie
29
- scatter
30
- spider
31
- side_bar
32
- stacked_area
33
- stacked_bar
34
- side_stacked_bar
35
- accumulator_bar
36
-
37
- scene
38
-
39
- renderer/renderer
40
- renderer/rectangle
41
- renderer/circle
42
- renderer/dash_line
43
- renderer/line
44
- renderer/polyline
45
- renderer/polygon
46
- renderer/bezier
47
- renderer/ellipse
48
- renderer/dot
49
- renderer/text
50
-
51
- store/store
52
- store/basic_data
53
- store/custom_data
54
- store/xy_data
55
-
56
- mini/legend
57
- mini/bar
58
- mini/pie
59
- mini/side_bar
60
- ].each do |filename|
61
- require "gruff/#{filename}"
4
+
5
+ require_relative 'gruff/patch/rmagick'
6
+ require_relative 'gruff/patch/string'
7
+ require_relative 'gruff/renderer/renderer'
8
+ require_relative 'gruff/store/store'
9
+ require_relative 'gruff/font'
10
+ require_relative 'gruff/base'
11
+ require_relative 'gruff/version'
12
+
13
+ ##
14
+ # = Gruff. Graphs.
15
+ #
16
+ module Gruff
17
+ # @private
18
+ def self.libpath(path)
19
+ File.join(__dir__, 'gruff', path)
20
+ end
21
+
22
+ autoload :BarConversion, Gruff.libpath('helper/bar_conversion')
23
+ autoload :BarValueLabel, Gruff.libpath('helper/bar_value_label')
24
+
25
+ autoload :AccumulatorBar, Gruff.libpath('accumulator_bar')
26
+ autoload :Area, Gruff.libpath('area')
27
+ autoload :Bar, Gruff.libpath('bar')
28
+ autoload :Bezier, Gruff.libpath('bezier')
29
+ autoload :BoxPlot, Gruff.libpath('box_plot')
30
+ autoload :Bullet, Gruff.libpath('bullet')
31
+ autoload :Candlestick, Gruff.libpath('candlestick')
32
+ autoload :Dot, Gruff.libpath('dot')
33
+ autoload :Histogram, Gruff.libpath('histogram')
34
+ autoload :Line, Gruff.libpath('line')
35
+ autoload :Net, Gruff.libpath('net')
36
+ autoload :Pie, Gruff.libpath('pie')
37
+ autoload :Scatter, Gruff.libpath('scatter')
38
+ autoload :SideBar, Gruff.libpath('side_bar')
39
+ autoload :SideStackedBar, Gruff.libpath('side_stacked_bar')
40
+ autoload :Spider, Gruff.libpath('spider')
41
+ autoload :StackedArea, Gruff.libpath('stacked_area')
42
+ autoload :StackedBar, Gruff.libpath('stacked_bar')
43
+
44
+ autoload :Layer, Gruff.libpath('scene')
45
+ autoload :Themes, Gruff.libpath('themes')
46
+
47
+ class Renderer
48
+ autoload :Bezier, Gruff.libpath('renderer/bezier')
49
+ autoload :Circle, Gruff.libpath('renderer/circle')
50
+ autoload :DashLine, Gruff.libpath('renderer/dash_line')
51
+ autoload :Dot, Gruff.libpath('renderer/dot')
52
+ autoload :Ellipse, Gruff.libpath('renderer/ellipse')
53
+ autoload :Line, Gruff.libpath('renderer/line')
54
+ autoload :Polygon, Gruff.libpath('renderer/polygon')
55
+ autoload :Polyline, Gruff.libpath('renderer/polyline')
56
+ autoload :Rectangle, Gruff.libpath('renderer/rectangle')
57
+ autoload :Text, Gruff.libpath('renderer/text')
58
+ end
59
+
60
+ class Store
61
+ autoload :BasicData, Gruff.libpath('store/basic_data')
62
+ autoload :XYData, Gruff.libpath('store/xy_data')
63
+ end
64
+
65
+ module Mini
66
+ autoload :Bar, Gruff.libpath('mini/bar')
67
+ autoload :Legend, Gruff.libpath('mini/legend')
68
+ autoload :Pie, Gruff.libpath('mini/pie')
69
+ autoload :SideBar, Gruff.libpath('mini/side_bar')
70
+ end
62
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gruff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.17.0
5
5
  platform: java
6
6
  authors:
7
7
  - Geoffrey Grosenbach
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-07-11 00:00:00.000000000 Z
12
+ date: 2022-06-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  requirement: !ruby/object:Gem::Requirement
@@ -18,8 +18,8 @@ dependencies:
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  name: rmagick4j
21
- type: :runtime
22
21
  prerelease: false
22
+ type: :runtime
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
@@ -32,8 +32,8 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  name: histogram
35
- type: :runtime
36
35
  prerelease: false
36
+ type: :runtime
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
@@ -46,8 +46,8 @@ dependencies:
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  name: rake
49
- type: :development
50
49
  prerelease: false
50
+ type: :development
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - ">="
@@ -60,8 +60,8 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  name: minitest-reporters
63
- type: :development
64
63
  prerelease: false
64
+ type: :development
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - ">="
@@ -74,8 +74,8 @@ dependencies:
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  name: simplecov
77
- type: :development
78
77
  prerelease: false
78
+ type: :development
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - ">="
@@ -86,15 +86,15 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.9.25
89
+ version: 0.9.28
90
90
  name: yard
91
- type: :development
92
91
  prerelease: false
92
+ type: :development
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: 0.9.25
97
+ version: 0.9.28
98
98
  description: Beautiful graphs for one or multiple datasets. Can be used on websites
99
99
  or in documents.
100
100
  email: boss@topfunky.com
@@ -107,7 +107,6 @@ files:
107
107
  - ".github/workflows/ci.yml"
108
108
  - ".gitignore"
109
109
  - ".rubocop.yml"
110
- - ".rubocop_todo.yml"
111
110
  - ".yardopts"
112
111
  - CHANGELOG.md
113
112
  - Gemfile
@@ -124,10 +123,13 @@ files:
124
123
  - lib/gruff/bar.rb
125
124
  - lib/gruff/base.rb
126
125
  - lib/gruff/bezier.rb
126
+ - lib/gruff/box_plot.rb
127
127
  - lib/gruff/bullet.rb
128
+ - lib/gruff/candlestick.rb
128
129
  - lib/gruff/dot.rb
129
130
  - lib/gruff/font.rb
130
131
  - lib/gruff/helper/bar_conversion.rb
132
+ - lib/gruff/helper/bar_mixin.rb
131
133
  - lib/gruff/helper/bar_value_label.rb
132
134
  - lib/gruff/helper/stacked_mixin.rb
133
135
  - lib/gruff/histogram.rb
@@ -152,14 +154,12 @@ files:
152
154
  - lib/gruff/renderer/renderer.rb
153
155
  - lib/gruff/renderer/text.rb
154
156
  - lib/gruff/scatter.rb
155
- - lib/gruff/scene.rb
156
157
  - lib/gruff/side_bar.rb
157
158
  - lib/gruff/side_stacked_bar.rb
158
159
  - lib/gruff/spider.rb
159
160
  - lib/gruff/stacked_area.rb
160
161
  - lib/gruff/stacked_bar.rb
161
162
  - lib/gruff/store/basic_data.rb
162
- - lib/gruff/store/custom_data.rb
163
163
  - lib/gruff/store/store.rb
164
164
  - lib/gruff/store/xy_data.rb
165
165
  - lib/gruff/themes.rb
@@ -170,7 +170,8 @@ files:
170
170
  homepage: https://github.com/topfunky/gruff
171
171
  licenses:
172
172
  - MIT
173
- metadata: {}
173
+ metadata:
174
+ rubygems_mfa_required: 'true'
174
175
  post_install_message:
175
176
  rdoc_options: []
176
177
  require_paths:
@@ -179,14 +180,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
179
180
  requirements:
180
181
  - - ">="
181
182
  - !ruby/object:Gem::Version
182
- version: 2.4.0
183
+ version: 2.5.0
183
184
  required_rubygems_version: !ruby/object:Gem::Requirement
184
185
  requirements:
185
186
  - - ">="
186
187
  - !ruby/object:Gem::Version
187
188
  version: '0'
188
189
  requirements: []
189
- rubygems_version: 3.0.6
190
+ rubygems_version: 3.2.29
190
191
  signing_key:
191
192
  specification_version: 4
192
193
  summary: Beautiful graphs for one or multiple datasets.
data/.rubocop_todo.yml DELETED
@@ -1,116 +0,0 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2021-07-11 06:52:14 UTC using RuboCop version 1.12.1.
4
- # The point is for the user to remove these configuration records
5
- # one by one as the offenses are removed from the code base.
6
- # Note that changes in the inspected code, or installation of new
7
- # versions of RuboCop, may require this file to be generated again.
8
-
9
- # Offense count: 13
10
- Lint/FloatComparison:
11
- Exclude:
12
- - 'Rakefile'
13
- - 'lib/gruff/base.rb'
14
- - 'lib/gruff/renderer/renderer.rb'
15
- - 'lib/gruff/scatter.rb'
16
-
17
- # Offense count: 1
18
- # Configuration parameters: CheckForMethodsWithNoSideEffects.
19
- Lint/Void:
20
- Exclude:
21
- - 'lib/gruff/patch/rmagick.rb'
22
-
23
- # Offense count: 57
24
- # Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
25
- Metrics/AbcSize:
26
- Max: 66
27
-
28
- # Offense count: 3
29
- # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
30
- # IgnoredMethods: refine
31
- Metrics/BlockLength:
32
- Max: 32
33
-
34
- # Offense count: 14
35
- # Configuration parameters: CountComments, CountAsOne.
36
- Metrics/ClassLength:
37
- Max: 683
38
-
39
- # Offense count: 8
40
- # Configuration parameters: IgnoredMethods.
41
- Metrics/CyclomaticComplexity:
42
- Max: 17
43
-
44
- # Offense count: 134
45
- # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
46
- Metrics/MethodLength:
47
- Max: 81
48
-
49
- # Offense count: 3
50
- # Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
51
- Metrics/ParameterLists:
52
- Max: 7
53
-
54
- # Offense count: 6
55
- # Configuration parameters: IgnoredMethods.
56
- Metrics/PerceivedComplexity:
57
- Max: 19
58
-
59
- # Offense count: 1
60
- # Configuration parameters: EnforcedStyleForLeadingUnderscores.
61
- # SupportedStylesForLeadingUnderscores: disallowed, required, optional
62
- Naming/MemoizedInstanceVariableName:
63
- Exclude:
64
- - 'lib/gruff/scene.rb'
65
-
66
- # Offense count: 6
67
- # Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers.
68
- # SupportedStyles: snake_case, normalcase, non_integer
69
- # AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339
70
- Naming/VariableNumber:
71
- Exclude:
72
- - 'test/test_bar.rb'
73
- - 'test/test_bezier.rb'
74
- - 'test/test_line.rb'
75
-
76
- # Offense count: 2
77
- # Cop supports --auto-correct.
78
- Performance/StringReplacement:
79
- Exclude:
80
- - 'lib/gruff/scene.rb'
81
-
82
- # Offense count: 1
83
- Rake/Desc:
84
- Exclude:
85
- - 'Rakefile'
86
-
87
- # Offense count: 1
88
- Security/Eval:
89
- Exclude:
90
- - 'test/gruff_test_case.rb'
91
-
92
- # Offense count: 1
93
- Style/CombinableLoops:
94
- Exclude:
95
- - 'test/test_line.rb'
96
-
97
- # Offense count: 2
98
- Style/DocumentDynamicEvalDefinition:
99
- Exclude:
100
- - 'test/gruff_test_case.rb'
101
-
102
- # Offense count: 97
103
- # Configuration parameters: RequireForNonPublicMethods.
104
- Style/DocumentationMethod:
105
- Enabled: false
106
-
107
- # Offense count: 1
108
- Style/MissingRespondToMissing:
109
- Exclude:
110
- - 'lib/gruff/scene.rb'
111
-
112
- # Offense count: 2
113
- # Cop supports --auto-correct.
114
- Style/StringConcatenation:
115
- Exclude:
116
- - 'test/gruff_test_case.rb'