gruff 0.12.2 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +66 -0
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +34 -27
  5. data/CHANGELOG.md +29 -0
  6. data/README.md +15 -7
  7. data/assets/fonts/LICENSE.txt +202 -0
  8. data/assets/fonts/Roboto-Bold.ttf +0 -0
  9. data/assets/fonts/Roboto-Regular.ttf +0 -0
  10. data/gruff.gemspec +9 -10
  11. data/lib/gruff/accumulator_bar.rb +3 -1
  12. data/lib/gruff/area.rb +5 -8
  13. data/lib/gruff/bar.rb +32 -49
  14. data/lib/gruff/base.rb +199 -115
  15. data/lib/gruff/bezier.rb +4 -6
  16. data/lib/gruff/bullet.rb +12 -11
  17. data/lib/gruff/dot.rb +13 -14
  18. data/lib/gruff/font.rb +39 -0
  19. data/lib/gruff/helper/bar_conversion.rb +27 -12
  20. data/lib/gruff/helper/bar_value_label.rb +71 -0
  21. data/lib/gruff/helper/stacked_mixin.rb +1 -2
  22. data/lib/gruff/histogram.rb +9 -7
  23. data/lib/gruff/line.rb +57 -50
  24. data/lib/gruff/mini/bar.rb +9 -6
  25. data/lib/gruff/mini/legend.rb +12 -8
  26. data/lib/gruff/mini/pie.rb +9 -6
  27. data/lib/gruff/mini/side_bar.rb +9 -6
  28. data/lib/gruff/net.rb +9 -15
  29. data/lib/gruff/patch/rmagick.rb +0 -1
  30. data/lib/gruff/patch/string.rb +1 -1
  31. data/lib/gruff/pie.rb +23 -65
  32. data/lib/gruff/renderer/bezier.rb +8 -9
  33. data/lib/gruff/renderer/circle.rb +8 -9
  34. data/lib/gruff/renderer/dash_line.rb +9 -10
  35. data/lib/gruff/renderer/dot.rb +13 -14
  36. data/lib/gruff/renderer/ellipse.rb +8 -9
  37. data/lib/gruff/renderer/line.rb +8 -9
  38. data/lib/gruff/renderer/polygon.rb +9 -10
  39. data/lib/gruff/renderer/polyline.rb +8 -9
  40. data/lib/gruff/renderer/rectangle.rb +7 -8
  41. data/lib/gruff/renderer/renderer.rb +25 -40
  42. data/lib/gruff/renderer/text.rb +21 -29
  43. data/lib/gruff/scatter.rb +55 -75
  44. data/lib/gruff/scene.rb +28 -18
  45. data/lib/gruff/side_bar.rb +35 -54
  46. data/lib/gruff/side_stacked_bar.rb +14 -17
  47. data/lib/gruff/spider.rb +11 -20
  48. data/lib/gruff/stacked_area.rb +10 -11
  49. data/lib/gruff/stacked_bar.rb +14 -15
  50. data/lib/gruff/store/store.rb +6 -10
  51. data/lib/gruff/store/xy_data.rb +2 -0
  52. data/lib/gruff/themes.rb +6 -6
  53. data/lib/gruff/version.rb +1 -1
  54. data/lib/gruff.rb +68 -55
  55. data/rails_generators/gruff/templates/controller.rb +1 -1
  56. metadata +34 -20
  57. data/.rubocop_todo.yml +0 -190
  58. data/.travis.yml +0 -23
  59. data/assets/plastik/blue.png +0 -0
  60. data/assets/plastik/green.png +0 -0
  61. data/assets/plastik/red.png +0 -0
  62. data/lib/gruff/helper/bar_value_label_mixin.rb +0 -33
  63. data/lib/gruff/photo_bar.rb +0 -93
data/.rubocop_todo.yml DELETED
@@ -1,190 +0,0 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2021-03-07 06:12:58 UTC using RuboCop version 1.11.0.
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: 1
10
- # Cop supports --auto-correct.
11
- # Configuration parameters: Include.
12
- # Include: **/*.gemspec
13
- Gemspec/DateAssignment:
14
- Exclude:
15
- - 'gruff.gemspec'
16
-
17
- # Offense count: 1
18
- # Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches.
19
- Lint/DuplicateBranch:
20
- Exclude:
21
- - 'test/gruff_test_case.rb'
22
-
23
- # Offense count: 1
24
- Lint/DuplicateMethods:
25
- Exclude:
26
- - 'lib/gruff/photo_bar.rb'
27
-
28
- # Offense count: 13
29
- Lint/FloatComparison:
30
- Exclude:
31
- - 'Rakefile'
32
- - 'lib/gruff/base.rb'
33
- - 'lib/gruff/renderer/renderer.rb'
34
- - 'lib/gruff/scatter.rb'
35
-
36
- # Offense count: 1
37
- Lint/UnreachableCode:
38
- Exclude:
39
- - 'lib/gruff/photo_bar.rb'
40
-
41
- # Offense count: 1
42
- Lint/UselessAssignment:
43
- Exclude:
44
- - 'lib/gruff/photo_bar.rb'
45
-
46
- # Offense count: 1
47
- # Configuration parameters: CheckForMethodsWithNoSideEffects.
48
- Lint/Void:
49
- Exclude:
50
- - 'lib/gruff/patch/rmagick.rb'
51
-
52
- # Offense count: 54
53
- # Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
54
- Metrics/AbcSize:
55
- Max: 82
56
-
57
- # Offense count: 1
58
- # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
59
- # IgnoredMethods: refine
60
- Metrics/BlockLength:
61
- Max: 29
62
-
63
- # Offense count: 13
64
- # Configuration parameters: CountComments, CountAsOne.
65
- Metrics/ClassLength:
66
- Max: 637
67
-
68
- # Offense count: 9
69
- # Configuration parameters: IgnoredMethods.
70
- Metrics/CyclomaticComplexity:
71
- Max: 21
72
-
73
- # Offense count: 121
74
- # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
75
- Metrics/MethodLength:
76
- Max: 81
77
-
78
- # Offense count: 3
79
- # Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
80
- Metrics/ParameterLists:
81
- Max: 7
82
-
83
- # Offense count: 8
84
- # Configuration parameters: IgnoredMethods.
85
- Metrics/PerceivedComplexity:
86
- Max: 22
87
-
88
- # Offense count: 1
89
- # Configuration parameters: EnforcedStyleForLeadingUnderscores.
90
- # SupportedStylesForLeadingUnderscores: disallowed, required, optional
91
- Naming/MemoizedInstanceVariableName:
92
- Exclude:
93
- - 'lib/gruff/scene.rb'
94
-
95
- # Offense count: 9
96
- # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
97
- # AllowedNames: at, by, db, id, in, io, ip, of, on, os, pp, to
98
- Naming/MethodParameterName:
99
- Exclude:
100
- - 'lib/gruff/base.rb'
101
- - 'lib/gruff/patch/rmagick.rb'
102
- - 'lib/gruff/pie.rb'
103
- - 'lib/gruff/renderer/text.rb'
104
-
105
- # Offense count: 6
106
- # Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers.
107
- # SupportedStyles: snake_case, normalcase, non_integer
108
- # AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339
109
- Naming/VariableNumber:
110
- Exclude:
111
- - 'test/test_bar.rb'
112
- - 'test/test_bezier.rb'
113
- - 'test/test_line.rb'
114
-
115
- # Offense count: 1
116
- # Configuration parameters: MinSize.
117
- Performance/CollectionLiteralInLoop:
118
- Exclude:
119
- - 'test/test_legend.rb'
120
-
121
- # Offense count: 1
122
- # Cop supports --auto-correct.
123
- Performance/RedundantMatch:
124
- Exclude:
125
- - 'lib/gruff/photo_bar.rb'
126
-
127
- # Offense count: 1
128
- # Cop supports --auto-correct.
129
- Performance/RegexpMatch:
130
- Exclude:
131
- - 'lib/gruff/photo_bar.rb'
132
-
133
- # Offense count: 2
134
- # Cop supports --auto-correct.
135
- Performance/StringReplacement:
136
- Exclude:
137
- - 'lib/gruff/scene.rb'
138
-
139
- # Offense count: 2
140
- Security/Eval:
141
- Exclude:
142
- - 'test/gruff_test_case.rb'
143
-
144
- # Offense count: 1
145
- Style/CombinableLoops:
146
- Exclude:
147
- - 'test/test_line.rb'
148
-
149
- # Offense count: 3
150
- Style/DocumentDynamicEvalDefinition:
151
- Exclude:
152
- - 'test/gruff_test_case.rb'
153
-
154
- # Offense count: 132
155
- # Configuration parameters: RequireForNonPublicMethods.
156
- Style/DocumentationMethod:
157
- Enabled: false
158
-
159
- # Offense count: 3
160
- # Cop supports --auto-correct.
161
- Style/EvalWithLocation:
162
- Exclude:
163
- - 'test/gruff_test_case.rb'
164
-
165
- # Offense count: 1
166
- Style/MissingRespondToMissing:
167
- Exclude:
168
- - 'lib/gruff/scene.rb'
169
-
170
- # Offense count: 1
171
- # Configuration parameters: AllowedMethods.
172
- # AllowedMethods: respond_to_missing?
173
- Style/OptionalBooleanParameter:
174
- Exclude:
175
- - 'lib/gruff/base.rb'
176
-
177
- # Offense count: 3
178
- # Cop supports --auto-correct.
179
- Style/StringConcatenation:
180
- Exclude:
181
- - 'lib/gruff/photo_bar.rb'
182
- - 'test/gruff_test_case.rb'
183
-
184
- # Offense count: 2
185
- # Configuration parameters: EnforcedStyle.
186
- # SupportedStyles: forbid_mixed_logical_operators, forbid_logical_operators
187
- Style/UnlessLogicalOperators:
188
- Exclude:
189
- - 'lib/gruff/bar.rb'
190
- - 'lib/gruff/scatter.rb'
data/.travis.yml DELETED
@@ -1,23 +0,0 @@
1
- language: ruby
2
- dist: bionic
3
- cache: bundler
4
-
5
- rvm:
6
- - 2.4
7
- - 2.5
8
- - 2.6
9
- - 2.7
10
- - 3.0
11
- - jruby-9.2.14.0
12
-
13
- jobs:
14
- include:
15
- - name: 'Lint'
16
- rvm: 2.4
17
- script: bundle exec rubocop
18
-
19
- addons:
20
- apt:
21
- packages:
22
- - gsfonts
23
- - ghostscript
Binary file
Binary file
Binary file
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # @private
4
- module Gruff::Base::BarValueLabelMixin
5
- using String::GruffCommify
6
-
7
- # @private
8
- class BarValueLabel
9
- attr_accessor :coordinates, :values
10
-
11
- def initialize(size, bar_width)
12
- @coordinates = Array.new(size)
13
- @values = Hash.new(0)
14
- @bar_width = bar_width
15
- end
16
-
17
- def prepare_rendering(format)
18
- @coordinates.each_with_index do |(left_x, left_y, right_x, _right_y), index|
19
- value = @values[index]
20
- val = (format || '%.2f') % value
21
- y = value >= 0 ? left_y - 30 : left_y + 12
22
- yield left_x + (right_x - left_x) / 2, y, val.commify
23
- end
24
- end
25
-
26
- def prepare_sidebar_rendering(format)
27
- @coordinates.each_with_index do |(_left_x, _left_y, right_x, right_y), index|
28
- val = (format || '%.2f') % @values[index]
29
- yield right_x + 40, right_y - @bar_width / 2, val.commify
30
- end
31
- end
32
- end
33
- end
@@ -1,93 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # EXPERIMENTAL!
4
- #
5
- # Doesn't work yet.
6
- #
7
- class Gruff::PhotoBar < Gruff::Base
8
- # TODO
9
- #
10
- # define base and cap in yml
11
- # allow for image directory to be located elsewhere
12
- # more exact measurements for bar heights (go all the way to the bottom of the graph)
13
- # option to tile images instead of use a single image
14
- # drop base label a few px lower so photo bar graphs can have a base dropping over the lower marker line
15
- #
16
-
17
- # The name of a pre-packaged photo-based theme.
18
- attr_reader :theme
19
-
20
- # def initialize(target_width=800)
21
- # super
22
- # init_photo_bar_graphics()
23
- # end
24
-
25
- def draw
26
- super
27
- return unless data_given?
28
-
29
- return # TODO: Remove for further development
30
-
31
- init_photo_bar_graphics
32
-
33
- #Draw#define_clip_path()
34
- #Draw#clip_path(pathname)
35
- #Draw#composite....with bar graph image OverCompositeOp
36
- #
37
- # See also
38
- #
39
- # Draw.pattern # define an image to tile as the filling of a draw object
40
- #
41
-
42
- # Setup spacing.
43
- #
44
- # Columns sit side-by-side.
45
- spacing_factor = 0.9
46
- bar_width = store.norm_data[0].color.columns
47
-
48
- store.norm_data.each_with_index do |data_row, row_index|
49
- data_row.points.each_with_index do |data_point, point_index|
50
- data_point = 0 if data_point.nil?
51
- # Use incremented x and scaled y
52
- left_x = @graph_left + (bar_width * (row_index + point_index + ((store.length - 1) * point_index)))
53
- left_y = @graph_top + (@graph_height - data_point * @graph_height) + 1
54
- right_x = left_x + bar_width * spacing_factor
55
- right_y = @graph_top + @graph_height - 1
56
-
57
- bar_image_width = data_row.color.columns
58
- bar_image_height = right_y.to_f - left_y.to_f
59
-
60
- # Crop to scale for data
61
- bar_image = data_row.color.crop(0, 0, bar_image_width, bar_image_height)
62
-
63
- @d.gravity = Magick::NorthWestGravity
64
- @d.composite(left_x, left_y, bar_image_width, bar_image_height, bar_image)
65
-
66
- # Calculate center based on bar_width and current row
67
- label_center = @graph_left + (store.length * bar_width * point_index) + (store.length * bar_width / 2.0)
68
- draw_label(label_center, point_index)
69
- end
70
- end
71
- end
72
-
73
- # Return the chosen theme or the default
74
- def theme
75
- @theme || 'plastik'
76
- end
77
-
78
- protected
79
-
80
- # Sets up colors with a list of images that will be used.
81
- # Images should be 340px tall
82
- def init_photo_bar_graphics
83
- color_list = []
84
- theme_dir = File.dirname(__FILE__) + '/../../assets/' + theme
85
-
86
- Dir.open(theme_dir).each do |file|
87
- next unless /\.png$/.match(file)
88
-
89
- color_list << Magick::Image.read("#{theme_dir}/#{file}").first
90
- end
91
- @colors = color_list
92
- end
93
- end