gruff 0.26.0-java → 0.27.0-java

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 (100) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/report.yml +1 -1
  3. data/.github/workflows/ci.yml +37 -0
  4. data/.rubocop.yml +3 -0
  5. data/CHANGELOG.md +18 -1
  6. data/Gemfile +5 -0
  7. data/README.md +7 -1
  8. data/gruff.gemspec +1 -1
  9. data/lib/gruff/accumulator_bar.rb +3 -1
  10. data/lib/gruff/area.rb +5 -2
  11. data/lib/gruff/bar.rb +18 -9
  12. data/lib/gruff/base.rb +193 -68
  13. data/lib/gruff/bezier.rb +6 -3
  14. data/lib/gruff/box.rb +40 -16
  15. data/lib/gruff/bubble.rb +9 -2
  16. data/lib/gruff/bullet.rb +8 -1
  17. data/lib/gruff/candlestick.rb +30 -8
  18. data/lib/gruff/dot.rb +13 -3
  19. data/lib/gruff/font.rb +12 -4
  20. data/lib/gruff/helper/bar_conversion.rb +12 -1
  21. data/lib/gruff/helper/bar_mixin.rb +19 -1
  22. data/lib/gruff/helper/bar_value_label.rb +22 -4
  23. data/lib/gruff/helper/stacked_mixin.rb +21 -1
  24. data/lib/gruff/histogram.rb +14 -5
  25. data/lib/gruff/line.rb +31 -12
  26. data/lib/gruff/mini/bar.rb +2 -2
  27. data/lib/gruff/mini/legend.rb +10 -1
  28. data/lib/gruff/mini/pie.rb +2 -2
  29. data/lib/gruff/mini/side_bar.rb +2 -2
  30. data/lib/gruff/net.rb +12 -7
  31. data/lib/gruff/patch/rmagick.rb +2 -0
  32. data/lib/gruff/patch/string.rb +1 -1
  33. data/lib/gruff/pie.rb +46 -11
  34. data/lib/gruff/renderer/bezier.rb +7 -0
  35. data/lib/gruff/renderer/circle.rb +11 -0
  36. data/lib/gruff/renderer/dash_line.rb +11 -0
  37. data/lib/gruff/renderer/dot.rb +11 -0
  38. data/lib/gruff/renderer/ellipse.rb +12 -0
  39. data/lib/gruff/renderer/line.rb +10 -0
  40. data/lib/gruff/renderer/polygon.rb +6 -0
  41. data/lib/gruff/renderer/polyline.rb +8 -0
  42. data/lib/gruff/renderer/rectangle.rb +11 -0
  43. data/lib/gruff/renderer/renderer.rb +16 -5
  44. data/lib/gruff/renderer/text.rb +19 -2
  45. data/lib/gruff/scatter.rb +16 -8
  46. data/lib/gruff/side_bar.rb +19 -10
  47. data/lib/gruff/side_stacked_bar.rb +15 -11
  48. data/lib/gruff/spider.rb +9 -2
  49. data/lib/gruff/stacked_area.rb +6 -1
  50. data/lib/gruff/stacked_bar.rb +16 -10
  51. data/lib/gruff/store/basic_data.rb +36 -2
  52. data/lib/gruff/store/store.rb +16 -3
  53. data/lib/gruff/store/xy_data.rb +32 -2
  54. data/lib/gruff/store/xy_pointsizes_data.rb +36 -3
  55. data/lib/gruff/themes.rb +2 -0
  56. data/lib/gruff/version.rb +3 -1
  57. data/lib/gruff.rb +3 -1
  58. data/sig/generated/gruff/accumulator_bar.rbs +19 -0
  59. data/sig/generated/gruff/area.rbs +27 -0
  60. data/sig/generated/gruff/bar.rbs +74 -0
  61. data/sig/generated/gruff/base.rbs +672 -0
  62. data/sig/generated/gruff/bezier.rbs +24 -0
  63. data/sig/generated/gruff/box.rbs +88 -0
  64. data/sig/generated/gruff/bubble.rbs +69 -0
  65. data/sig/generated/gruff/bullet.rbs +30 -0
  66. data/sig/generated/gruff/candlestick.rbs +79 -0
  67. data/sig/generated/gruff/dot.rbs +44 -0
  68. data/sig/generated/gruff/font.rbs +35 -0
  69. data/sig/generated/gruff/helper/bar_conversion.rbs +27 -0
  70. data/sig/generated/gruff/helper/bar_mixin.rbs +22 -0
  71. data/sig/generated/gruff/helper/bar_value_label.rbs +41 -0
  72. data/sig/generated/gruff/helper/stacked_mixin.rbs +27 -0
  73. data/sig/generated/gruff/histogram.rbs +42 -0
  74. data/sig/generated/gruff/line.rbs +165 -0
  75. data/sig/generated/gruff/net.rbs +52 -0
  76. data/sig/generated/gruff/pie.rbs +131 -0
  77. data/sig/generated/gruff/renderer/bezier.rbs +15 -0
  78. data/sig/generated/gruff/renderer/circle.rbs +19 -0
  79. data/sig/generated/gruff/renderer/dash_line.rbs +19 -0
  80. data/sig/generated/gruff/renderer/dot.rbs +27 -0
  81. data/sig/generated/gruff/renderer/ellipse.rbs +20 -0
  82. data/sig/generated/gruff/renderer/line.rbs +24 -0
  83. data/sig/generated/gruff/renderer/polyline.rbs +16 -0
  84. data/sig/generated/gruff/renderer/rectangle.rbs +19 -0
  85. data/sig/generated/gruff/renderer/renderer.rbs +43 -0
  86. data/sig/generated/gruff/renderer/text.rbs +38 -0
  87. data/sig/generated/gruff/scatter.rbs +112 -0
  88. data/sig/generated/gruff/side_bar.rbs +78 -0
  89. data/sig/generated/gruff/side_stacked_bar.rbs +52 -0
  90. data/sig/generated/gruff/spider.rbs +50 -0
  91. data/sig/generated/gruff/stacked_area.rbs +25 -0
  92. data/sig/generated/gruff/stacked_bar.rbs +56 -0
  93. data/sig/generated/gruff/store/basic_data.rbs +48 -0
  94. data/sig/generated/gruff/store/store.rbs +53 -0
  95. data/sig/generated/gruff/store/xy_data.rbs +58 -0
  96. data/sig/generated/gruff/store/xy_pointsizes_data.rbs +61 -0
  97. data/sig/generated/gruff/themes.rbs +24 -0
  98. data/sig/generated/gruff/version.rbs +5 -0
  99. data/sig/generated/gruff.rbs +20 -0
  100. metadata +51 -6
data/lib/gruff/base.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rbs_inline: enabled
4
+
3
5
  require 'bigdecimal'
4
6
 
5
7
  ##
@@ -21,105 +23,106 @@ module Gruff
21
23
  # A common base class inherited from class of drawing a graph.
22
24
  class Base
23
25
  # Space around text elements. Mostly used for vertical spacing.
24
- LEGEND_MARGIN = TITLE_MARGIN = 20.0
26
+ LEGEND_MARGIN = 20.0
27
+ TITLE_MARGIN = 20.0
25
28
  LABEL_MARGIN = 15.0
26
29
  DEFAULT_MARGIN = 20.0
27
30
 
28
31
  DEFAULT_TARGET_WIDTH = 800.0
29
32
 
30
33
  # Blank space between graph and labels. Default is +15+.
31
- attr_writer :label_margin
34
+ attr_writer :label_margin #: Float | Integer
32
35
 
33
36
  # Blank space above the graph. Default is +20+.
34
- attr_writer :top_margin
37
+ attr_writer :top_margin #: Float | Integer
35
38
 
36
39
  # Blank space below the graph. Default is +20+.
37
- attr_writer :bottom_margin
40
+ attr_writer :bottom_margin #: Float | Integer
38
41
 
39
42
  # Blank space to the right of the graph. Default is +20+.
40
- attr_writer :right_margin
43
+ attr_writer :right_margin #: Float | Integer
41
44
 
42
45
  # Blank space to the left of the graph. Default is +20+.
43
- attr_writer :left_margin
46
+ attr_writer :left_margin #: Float | Integer
44
47
 
45
48
  # Blank space below the title. Default is +20+.
46
- attr_writer :title_margin
49
+ attr_writer :title_margin #: Float | Integer
47
50
 
48
51
  # Blank space below the legend. Default is +20+.
49
- attr_writer :legend_margin
52
+ attr_writer :legend_margin #: Float | Integer
50
53
 
51
54
  # Truncates labels if longer than max specified.
52
- attr_writer :label_max_size
55
+ attr_writer :label_max_size #: Float | Integer
53
56
 
54
57
  # How truncated labels visually appear if they exceed {#label_max_size=}.
55
58
  #
56
59
  # - +:absolute+ - does not show trailing dots to indicate truncation. This is the default.
57
60
  # - +:trailing_dots+ - shows trailing dots to indicate truncation (note that {#label_max_size=}
58
61
  # must be greater than 3).
59
- attr_writer :label_truncation_style
62
+ attr_writer :label_truncation_style #: (:absolute | :trailing_dots)
60
63
 
61
64
  # Set a label for the bottom of the graph.
62
- attr_writer :x_axis_label
65
+ attr_writer :x_axis_label #: String
63
66
 
64
67
  # Set a label for the left side of the graph.
65
- attr_writer :y_axis_label
68
+ attr_writer :y_axis_label #: String
66
69
 
67
70
  # Allow passing lambda to format labels for x axis.
68
- attr_writer :x_axis_label_format
71
+ attr_writer :x_axis_label_format #: Proc
69
72
 
70
73
  # Allow passing lambda to format labels for y axis.
71
- attr_writer :y_axis_label_format
74
+ attr_writer :y_axis_label_format #: Proc
72
75
 
73
76
  # Set increment of the vertical marking lines.
74
- attr_writer :x_axis_increment
77
+ attr_writer :x_axis_increment #: Float | Integer
75
78
 
76
79
  # Set increment of the horizontal marking lines.
77
- attr_writer :y_axis_increment
80
+ attr_writer :y_axis_increment #: Float | Integer
78
81
 
79
82
  # Get or set the list of colors that will be used to draw the bars or lines.
80
- attr_accessor :colors
83
+ attr_accessor :colors #: [String]
81
84
 
82
85
  # Prevent drawing of line markers. Default is +false+.
83
- attr_writer :hide_line_markers
86
+ attr_writer :hide_line_markers #: bool
84
87
 
85
88
  # Prevent drawing of the legend. Default is +false+.
86
- attr_writer :hide_legend
89
+ attr_writer :hide_legend #: bool
87
90
 
88
91
  # Prevent drawing of the title. Default is +false+.
89
- attr_writer :hide_title
92
+ attr_writer :hide_title #: bool
90
93
 
91
94
  # Prevent drawing of line numbers. Default is +false+.
92
- attr_writer :hide_line_numbers
95
+ attr_writer :hide_line_numbers #: bool
93
96
 
94
97
  # Set a message shown when there is no data. Fits up to 20 characters. Defaults
95
98
  # to +"No Data."+.
96
- attr_writer :no_data_message
99
+ attr_writer :no_data_message #: String
97
100
 
98
101
  # Set the color of the auxiliary lines.
99
- attr_writer :marker_color
102
+ attr_writer :marker_color #: String
100
103
 
101
104
  # Set the shadow color of the auxiliary lines.
102
- attr_writer :marker_shadow_color
105
+ attr_writer :marker_shadow_color #: String
103
106
 
104
107
  # Set the number of horizontal lines shown for reference.
105
- attr_writer :marker_count
108
+ attr_writer :marker_count #: Float | Integer
106
109
 
107
110
  # Set to +true+ if you want the data sets sorted with largest avg values drawn
108
111
  # first. Default is +false+.
109
- attr_writer :sort
112
+ attr_writer :sort #: bool
110
113
 
111
114
  # Set to +true+ if you want the data sets drawn with largest avg values drawn
112
115
  # first. This does not affect the legend. Default is +false+.
113
- attr_writer :sorted_drawing
116
+ attr_writer :sorted_drawing #: bool
114
117
 
115
118
  # Display the legend under the graph. Default is +false+.
116
- attr_writer :legend_at_bottom
119
+ attr_writer :legend_at_bottom #: bool
117
120
 
118
121
  # Optionally set the size of the colored box by each item in the legend.
119
122
  # Default is +20.0+.
120
123
  #
121
124
  # Will be scaled down if graph is smaller than 800px wide.
122
- attr_writer :legend_box_size
125
+ attr_writer :legend_box_size #: Float | Integer
123
126
 
124
127
  # If one numerical argument is given, the graph is drawn at 4/3 ratio
125
128
  # according to the given width (+800+ results in 800x600, +400+ gives 400x300,
@@ -129,6 +132,8 @@ module Gruff
129
132
  #
130
133
  # @param target_width [Numeric, String] The graph image width.
131
134
  #
135
+ # @rbs target_width: (String | Float | Integer)
136
+ # @rbs return: void
132
137
  def initialize(target_width = DEFAULT_TARGET_WIDTH)
133
138
  if target_width.is_a?(String)
134
139
  @columns, @rows = target_width.split('x').map(&:to_f)
@@ -214,13 +219,15 @@ module Gruff
214
219
  # Or, an array corresponding to the data values.
215
220
  #
216
221
  # @param labels [Hash, Array] the labels.
222
+ # @rbs labels: (Hash[Integer, String] | [String | nil])
217
223
  #
218
224
  # @example
219
225
  # g = Gruff::Bar.new
220
- # g.labels = { 0 => 2005, 3 => 2006, 5 => 2007, 7 => 2008 }
226
+ # g.labels = { 0 => '2005', 3 => '2006', 5 => '2007', 7 => '2008' }
221
227
  #
222
228
  # g = Gruff::Bar.new
223
229
  # g.labels = ['2005', nil, nil, '2006', nil, nil, '2007', nil, nil, '2008'] # same labels for columns
230
+ #
224
231
  def labels=(labels)
225
232
  if labels.is_a?(Array)
226
233
  labels = labels.each_with_index.with_object({}) do |(label, index), hash|
@@ -235,7 +242,7 @@ module Gruff
235
242
  # You can use a rotation between +0.0+ and +45.0+, or between +0.0+ and +-45.0+.
236
243
  #
237
244
  # @param rotation [Numeric] the rotation.
238
- #
245
+ # @rbs rotation: Float | Integer
239
246
  def label_rotation=(rotation)
240
247
  raise ArgumentError, 'rotation must be between 0.0 and 45.0 or between 0.0 and -45.0' if rotation > 45.0 || rotation < -45.0
241
248
 
@@ -253,6 +260,7 @@ module Gruff
253
260
  # or by setting an array as argument.
254
261
  #
255
262
  # @param title [String, Array] the title.
263
+ # @rbs title: (String | Array[String])
256
264
  #
257
265
  # @example
258
266
  # g = Gruff::Bar.new
@@ -260,6 +268,7 @@ module Gruff
260
268
  #
261
269
  # g = Gruff::Bar.new
262
270
  # g.title = ['The first line of title', 'The second line of title']
271
+ #
263
272
  def title=(title)
264
273
  if title.is_a?(Array)
265
274
  title = title.join("\n")
@@ -271,7 +280,7 @@ module Gruff
271
280
  # Sets the top, bottom, left and right margins to +margin+.
272
281
  #
273
282
  # @param margin [Numeric] The margin size.
274
- #
283
+ # @rbs margin: Float | Integer
275
284
  def margins=(margin)
276
285
  @top_margin = @left_margin = @right_margin = @bottom_margin = margin
277
286
  end
@@ -279,7 +288,7 @@ module Gruff
279
288
  # Sets the font for graph text to the font at +font_path+.
280
289
  #
281
290
  # @param font_path [String] The path to font.
282
- #
291
+ # @rbs font_path: String
283
292
  def font=(font_path)
284
293
  @title_font.path = font_path unless @title_font.path
285
294
  @marker_font.path = font_path
@@ -290,7 +299,7 @@ module Gruff
290
299
  # Same as {#font=} but for the title.
291
300
  #
292
301
  # @param font_path [String] The path to font.
293
- #
302
+ # @rbs font_path: String
294
303
  def title_font=(font_path)
295
304
  @title_font.path = font_path
296
305
  end
@@ -298,7 +307,7 @@ module Gruff
298
307
  # Set the font size of the large title at the top of the graph. Default is +36+.
299
308
  #
300
309
  # @param value [Numeric] title font size
301
- #
310
+ # @rbs value: Float | Integer
302
311
  def title_font_size=(value)
303
312
  @title_font.size = value
304
313
  end
@@ -306,7 +315,7 @@ module Gruff
306
315
  # The font size of the labels around the graph. Default is +21+.
307
316
  #
308
317
  # @param value [Numeric] marker font size
309
- #
318
+ # @rbs value: Float | Integer
310
319
  def marker_font_size=(value)
311
320
  @marker_font.size = value
312
321
  end
@@ -317,7 +326,7 @@ module Gruff
317
326
  # Will be scaled down if the graph is smaller than 800px wide.
318
327
  #
319
328
  # @param value [Numeric] legend font size
320
- #
329
+ # @rbs value: Float | Integer
321
330
  def legend_font_size=(value)
322
331
  @legend_font.size = value
323
332
  end
@@ -325,7 +334,7 @@ module Gruff
325
334
  # Set the font size of the no data message. Default is +80+.
326
335
  #
327
336
  # @param value [Numeric] no data font size
328
- #
337
+ # @rbs value: Float | Integer
329
338
  def no_data_font_size=(value)
330
339
  @no_data_font.size = value
331
340
  end
@@ -333,7 +342,7 @@ module Gruff
333
342
  # Specifies whether to draw the title bolded or not. Default is +true+.
334
343
  #
335
344
  # @param value [Boolean] specifies whether to draw the title bolded or not.
336
- #
345
+ # @rbs value: bool
337
346
  def bold_title=(value)
338
347
  @title_font.bold = value
339
348
  end
@@ -341,7 +350,7 @@ module Gruff
341
350
  # Specifies the text color.
342
351
  #
343
352
  # @param value [String] color
344
- #
353
+ # @rbs value: String
345
354
  def font_color=(value)
346
355
  @title_font.color = value
347
356
  @marker_font.color = value
@@ -352,6 +361,7 @@ module Gruff
352
361
  # Add a color to the list of available colors for lines.
353
362
  #
354
363
  # @param colorname [String] The color.
364
+ # @rbs colorname: String
355
365
  #
356
366
  # @example
357
367
  # add_color('#c0e9d3')
@@ -371,6 +381,7 @@ module Gruff
371
381
  # was in place at the time data was called.
372
382
  #
373
383
  # @param color_list [Array] The array of colors.
384
+ # @rbs color_list: Array[String]
374
385
  #
375
386
  # @example
376
387
  # replace_colors ['#cc99cc', '#d9e043', '#34d8a2']
@@ -381,7 +392,7 @@ module Gruff
381
392
  # Set whether to make background transparent.
382
393
  #
383
394
  # @param value [Boolean] Specify whether to make background transparent.
384
- #
395
+ # @rbs value: bool
385
396
  def transparent_background=(value)
386
397
  @renderer.transparent_background(@columns, @rows) if value
387
398
  end
@@ -416,7 +427,7 @@ module Gruff
416
427
  # (Or hopefully something better looking than that.)
417
428
  #
418
429
  # @param options [Hash] The optional setting for theme
419
- #
430
+ # @rbs options: Hash[Symbol, untyped]
420
431
  def theme=(options)
421
432
  reset_themes
422
433
 
@@ -481,8 +492,11 @@ module Gruff
481
492
  # be used.
482
493
  #
483
494
  # @param name [String, Symbol] The name of the dataset.
495
+ # @rbs name: (String | Symbol)
484
496
  # @param data_points [Array] The array of dataset.
497
+ # @rbs data_points: Array[Float | Integer] | nil
485
498
  # @param color [String] The color for drawing graph of dataset.
499
+ # @rbs color: String
486
500
  #
487
501
  # @note
488
502
  # If you want to use a preset theme, you must set it before calling {#data}.
@@ -497,25 +511,32 @@ module Gruff
497
511
  # guessed for you.
498
512
  #
499
513
  # Set it after you have given all your data to the graph object.
514
+ #
515
+ # @return [Float] The minimum value.
516
+ # @rbs return: Float
500
517
  def minimum_value
501
518
  min = [0.0, store.min.to_f].min
502
519
  (@minimum_value || min).to_f
503
520
  end
504
- attr_writer :minimum_value
521
+ attr_writer :minimum_value #: Float | Integer
505
522
 
506
523
  # You can manually set a maximum value, such as a percentage-based graph
507
524
  # that always goes to 100.
508
525
  #
509
526
  # If you use this, you must set it after you have given all your data to
510
527
  # the graph object.
528
+ #
529
+ # @return [Float] The maximum value.
530
+ # @rbs return: Float
511
531
  def maximum_value
512
532
  (@maximum_value || store.max).to_f
513
533
  end
514
- attr_writer :maximum_value
534
+ attr_writer :maximum_value #: Float | Integer
515
535
 
516
536
  # Writes the graph to a file. Defaults to +'graph.png'+
517
537
  #
518
538
  # @param file_name [String] The file name of output image.
539
+ # @rbs file_name: String
519
540
  #
520
541
  # @example
521
542
  # write('graphs/my_pretty_graph.png')
@@ -527,8 +548,10 @@ module Gruff
527
548
  # This can use RMagick's methods to adjust the image before saving.
528
549
  #
529
550
  # @param format [String] The output image format.
551
+ # @rbs format: String
530
552
  #
531
553
  # @return [Magick::Image] The rendered image.
554
+ # TODO: RBS signature
532
555
  #
533
556
  # @example
534
557
  # g = Gruff::Line.new
@@ -551,6 +574,10 @@ module Gruff
551
574
  # Return the graph as a rendered binary blob.
552
575
  #
553
576
  # @param format [String] The image format of binary blob.
577
+ # @rbs format: String
578
+ #
579
+ # @return [String] The binary string.
580
+ # @rbs return: String
554
581
  #
555
582
  # @deprecated Please use +to_image.to_blob+ instead.
556
583
  def to_blob(format = 'PNG')
@@ -580,7 +607,7 @@ module Gruff
580
607
 
581
608
  protected
582
609
 
583
- attr_reader :renderer
610
+ attr_reader :renderer #: Gruff::Renderer
584
611
 
585
612
  # Perform data manipulation before calculating chart measurements
586
613
  def setup_data
@@ -606,8 +633,9 @@ module Gruff
606
633
  sort_norm_data if @sorted_drawing # Sort norm_data with avg largest values set first (for display)
607
634
  end
608
635
 
609
- attr_reader :store
636
+ attr_reader :store #: Gruff::Store
610
637
 
638
+ # @rbs return: bool
611
639
  def data_given?
612
640
  @data_given ||= begin
613
641
  if store.empty?
@@ -618,10 +646,12 @@ module Gruff
618
646
  end
619
647
  end
620
648
 
649
+ # @rbs return: Integer
621
650
  def column_count
622
651
  store.columns
623
652
  end
624
653
 
654
+ # @rbs return: Integer
625
655
  def marker_count
626
656
  @marker_count ||= begin
627
657
  count = nil
@@ -635,6 +665,7 @@ module Gruff
635
665
  end
636
666
 
637
667
  # Make copy of data with values scaled between 0-100
668
+ # @rbs return: Array[Gruff::Store::BasicData | Gruff::Store::XYData | Gruff::Store::XYPointsizeData]
638
669
  def normalize
639
670
  store.normalize(minimum: minimum_value, spread: @spread)
640
671
  end
@@ -644,18 +675,22 @@ module Gruff
644
675
  @spread = @spread > 0 ? @spread : 1.0
645
676
  end
646
677
 
678
+ # @rbs return: bool
647
679
  def hide_title?
648
680
  @hide_title || @title.nil? || @title.empty?
649
681
  end
650
682
 
683
+ # @rbs return: bool
651
684
  def hide_labels?
652
685
  @hide_line_markers
653
686
  end
654
687
 
688
+ # @rbs return: bool
655
689
  def hide_left_label_area?
656
690
  @hide_line_markers && @y_axis_label.nil?
657
691
  end
658
692
 
693
+ # @rbs return: bool
659
694
  def hide_bottom_label_area?
660
695
  @hide_line_markers && @x_axis_label.nil?
661
696
  end
@@ -732,8 +767,10 @@ module Gruff
732
767
  end
733
768
 
734
769
  # Return a calculation of center
770
+ # @rbs size: Float | Integer
771
+ # @rbs return: Float
735
772
  def center(size)
736
- (@raw_columns - size) / 2
773
+ (@raw_columns - size) / 2.0
737
774
  end
738
775
 
739
776
  # Draws a legend with the names of the datasets matched
@@ -800,6 +837,11 @@ module Gruff
800
837
  end
801
838
 
802
839
  # Draws column labels below graph, centered over x
840
+ #
841
+ # @rbs x: Float | Integer
842
+ # @rbs index: Integer
843
+ # @rbs gravity: untyped
844
+ # @rbs &: () -> void
803
845
  def draw_label(x, index, gravity = Magick::NorthGravity, &block)
804
846
  draw_unique_label(index) do
805
847
  if x.between?(@graph_left, @graph_right)
@@ -812,6 +854,8 @@ module Gruff
812
854
  end
813
855
  end
814
856
 
857
+ # @rbs index: Integer
858
+ # @rbs &: () -> void
815
859
  def draw_unique_label(index)
816
860
  return if hide_labels?
817
861
 
@@ -822,6 +866,13 @@ module Gruff
822
866
  end
823
867
  end
824
868
 
869
+ # @rbs width: Float | Integer
870
+ # @rbs height: Float | Integer
871
+ # @rbs x: Float | Integer
872
+ # @rbs y: Float | Integer
873
+ # @rbs text: String | _ToS
874
+ # @rbs gravity: untyped
875
+ # @rbs rotation: Float | Integer
825
876
  def draw_label_at(width, height, x, y, text, gravity: Magick::NorthGravity, rotation: 0)
826
877
  label_text = truncate_label_text(text)
827
878
  text_renderer = Gruff::Renderer::Text.new(renderer, label_text, font: @marker_font, rotation: rotation)
@@ -829,6 +880,13 @@ module Gruff
829
880
  end
830
881
 
831
882
  # Draws the data value over the data point in bar graphs
883
+ #
884
+ # @rbs width: Float | Integer
885
+ # @rbs height: Float | Integer
886
+ # @rbs x_offset: Float | Integer
887
+ # @rbs y_offset: Float | Integer
888
+ # @rbs data_point: String | _ToS
889
+ # @rbs gravity: untyped
832
890
  def draw_value_label(width, height, x_offset, y_offset, data_point, gravity: Magick::CenterGravity)
833
891
  return if @hide_line_markers
834
892
 
@@ -851,10 +909,16 @@ module Gruff
851
909
  @theme_options = {}
852
910
  end
853
911
 
912
+ # @rbs value: Float | Integer
913
+ # @rbs max_value: Float | Integer
914
+ # @rbs return: Float | Integer
854
915
  def clip_value_if_greater_than(value, max_value)
855
916
  [value, max_value].min
856
917
  end
857
918
 
919
+ # @rbs i: Integer
920
+ # @rbs return: Integer | Float | BigDecimal
921
+ # TODO: Fix return RBS signature
858
922
  def significant(i)
859
923
  return 1.0 if i == 0 # Keep from going into infinite loop
860
924
 
@@ -898,22 +962,27 @@ module Gruff
898
962
 
899
963
  private
900
964
 
965
+ # @rbs return: Float
901
966
  def marker_caps_height
902
- hide_bottom_label_area? ? 0 : calculate_caps_height(@marker_font)
967
+ hide_bottom_label_area? ? 0.0 : calculate_caps_height(@marker_font)
903
968
  end
904
969
 
970
+ # @rbs return: Float
905
971
  def labels_caps_height
906
- hide_bottom_label_area? ? 0 : calculate_labels_height(@marker_font)
972
+ hide_bottom_label_area? ? 0.0 : calculate_labels_height(@marker_font)
907
973
  end
908
974
 
975
+ # @rbs return: Float
909
976
  def title_caps_height
910
- hide_title? ? 0 : calculate_caps_height(@title_font) * @title.lines.to_a.size
977
+ hide_title? ? 0.0 : Float(calculate_caps_height(@title_font) * @title.lines.to_a.size)
911
978
  end
912
979
 
980
+ # @rbs return: Float
913
981
  def legend_caps_height
914
- @hide_legend ? 0 : calculate_caps_height(@legend_font)
982
+ @hide_legend ? 0.0 : calculate_caps_height(@legend_font)
915
983
  end
916
984
 
985
+ # @rbs return: Float | Integer
917
986
  def setup_left_margin
918
987
  return @left_margin if hide_left_label_area?
919
988
 
@@ -941,49 +1010,60 @@ module Gruff
941
1010
  @left_margin + [margin, bottom_label_width].max
942
1011
  end
943
1012
 
1013
+ # @rbs return: Float
944
1014
  def setup_right_margin
945
1015
  @raw_columns - (@hide_line_markers ? @right_margin : @right_margin + extra_right_room_for_long_label)
946
1016
  end
947
1017
 
1018
+ # @rbs return: Float | Integer
948
1019
  def extra_left_room_for_long_label
949
1020
  if require_extra_side_margin?
950
1021
  width = calculate_width(@marker_font, truncate_label_text(@labels[0]), rotation: @label_rotation)
951
- case @label_rotation
952
- when 0
953
- width / 2.0
954
- when 0..45
955
- 0
956
- when -45..0
957
- width
1022
+ result = begin
1023
+ case @label_rotation
1024
+ when 0
1025
+ width / 2.0
1026
+ when 0..45
1027
+ 0
1028
+ when -45..0
1029
+ width
1030
+ end
958
1031
  end
1032
+ result || 0
959
1033
  else
960
1034
  0
961
1035
  end
962
1036
  end
963
1037
 
1038
+ # @rbs return: Float | Integer
964
1039
  def extra_right_room_for_long_label
965
1040
  # Make space for half the width of the rightmost column label.
966
1041
  # Might be greater than the number of columns if between-style bar markers are used.
967
1042
  last_label = @labels.keys.max.to_i
968
1043
  if last_label >= (column_count - 1) && require_extra_side_margin?
969
1044
  width = calculate_width(@marker_font, truncate_label_text(@labels[last_label]), rotation: @label_rotation)
970
- case @label_rotation
971
- when 0
972
- width / 2.0
973
- when 0..45
974
- width
975
- when -45..0
976
- 0
1045
+ result = begin
1046
+ case @label_rotation
1047
+ when 0
1048
+ width / 2.0
1049
+ when 0..45
1050
+ width
1051
+ when -45..0
1052
+ 0
1053
+ end
977
1054
  end
1055
+ result || 0
978
1056
  else
979
1057
  0
980
1058
  end
981
1059
  end
982
1060
 
1061
+ # @rbs return: bool
983
1062
  def require_extra_side_margin?
984
1063
  !hide_bottom_label_area? && @center_labels_over_point
985
1064
  end
986
1065
 
1066
+ # @rbs return: Float
987
1067
  def setup_top_margin
988
1068
  # When @hide title, leave a title_margin space for aesthetics.
989
1069
  # Same with @hide_legend
@@ -992,6 +1072,7 @@ module Gruff
992
1072
  (@hide_legend || @legend_at_bottom ? @legend_margin : calculate_legend_height + @legend_margin)
993
1073
  end
994
1074
 
1075
+ # @rbs return: Float
995
1076
  def setup_bottom_margin
996
1077
  graph_bottom_margin = hide_bottom_label_area? ? @bottom_margin : @bottom_margin + labels_caps_height + @label_margin
997
1078
  graph_bottom_margin += (calculate_legend_height + @legend_margin) if @legend_at_bottom
@@ -1000,6 +1081,8 @@ module Gruff
1000
1081
  @raw_rows - graph_bottom_margin - x_axis_label_height
1001
1082
  end
1002
1083
 
1084
+ # @rbs text: String | _ToS
1085
+ # @rbs return: String
1003
1086
  def truncate_label_text(text)
1004
1087
  text = text.to_s
1005
1088
  return text if text.size <= @label_max_size
@@ -1010,11 +1093,15 @@ module Gruff
1010
1093
  else
1011
1094
  text = text[0..(@label_max_size - 1)]
1012
1095
  end
1013
- text
1096
+ text || ''
1014
1097
  end
1015
1098
 
1016
1099
  # Return a formatted string representing a number value that should be
1017
1100
  # printed as a label.
1101
+ #
1102
+ # @rbs value: Float | Integer | BigDecimal
1103
+ # @rbs increment: Float | Integer | BigDecimal
1104
+ # @rbs return: String
1018
1105
  def label(value, increment)
1019
1106
  label = begin
1020
1107
  if increment
@@ -1043,10 +1130,13 @@ module Gruff
1043
1130
  end
1044
1131
 
1045
1132
  parts = label.split('.')
1046
- parts[0] = parts[0].commify
1133
+ parts[0] = parts[0].commify # steep:ignore
1047
1134
  parts.join('.')
1048
1135
  end
1049
1136
 
1137
+ # @rbs value: Float | Integer | BigDecimal
1138
+ # @rbs increment: Float | Integer | BigDecimal
1139
+ # @rbs return: String
1050
1140
  def x_axis_label(value, increment)
1051
1141
  if @x_axis_label_format
1052
1142
  @x_axis_label_format.call(value)
@@ -1055,6 +1145,9 @@ module Gruff
1055
1145
  end
1056
1146
  end
1057
1147
 
1148
+ # @rbs value: Float | Integer | BigDecimal
1149
+ # @rbs increment: Float | Integer
1150
+ # @rbs return: String
1058
1151
  def y_axis_label(value, increment)
1059
1152
  if @y_axis_label_format
1060
1153
  @y_axis_label_format.call(value)
@@ -1063,6 +1156,7 @@ module Gruff
1063
1156
  end
1064
1157
  end
1065
1158
 
1159
+ # TODO: RBS signature
1066
1160
  def calculate_legend_label_widths_for_each_line(legend_labels, legend_square_width)
1067
1161
  label_widths = [[]]
1068
1162
  label_lines = [[]]
@@ -1085,6 +1179,7 @@ module Gruff
1085
1179
  label_widths.map(&:sum).zip(label_lines)
1086
1180
  end
1087
1181
 
1182
+ # TODO: RBS signature
1088
1183
  def calculate_legend_height
1089
1184
  return 0.0 if @hide_legend
1090
1185
 
@@ -1100,10 +1195,15 @@ module Gruff
1100
1195
  #
1101
1196
  # Not scaled since it deals with dimensions that the regular scaling will
1102
1197
  # handle.
1198
+ #
1199
+ # @rbs font: Gruff::Font
1200
+ # @rbs return: Float
1103
1201
  def calculate_caps_height(font)
1104
1202
  calculate_height(font, 'X')
1105
1203
  end
1106
1204
 
1205
+ # @rbs font: Gruff::Font
1206
+ # @rbs return: Float
1107
1207
  def calculate_labels_height(font)
1108
1208
  @labels.values.map { |label| calculate_height(font, label, rotation: @label_rotation) }.max || marker_caps_height
1109
1209
  end
@@ -1112,9 +1212,14 @@ module Gruff
1112
1212
  #
1113
1213
  # Not scaled since it deals with dimensions that the regular scaling will
1114
1214
  # handle.
1215
+ #
1216
+ # @rbs font: Gruff::Font
1217
+ # @rbs text: String
1218
+ # @rbs rotation: Float | Integer
1219
+ # @rbs return: Float
1115
1220
  def calculate_height(font, text, rotation: 0)
1116
1221
  text = text.to_s
1117
- return 0 if text.empty?
1222
+ return 0.0 if text.empty?
1118
1223
 
1119
1224
  metrics = text_metrics(font, text, rotation: rotation)
1120
1225
  # Calculate manually because it does not return the height after rotation.
@@ -1125,6 +1230,11 @@ module Gruff
1125
1230
  #
1126
1231
  # Not scaled since it deals with dimensions that the regular
1127
1232
  # scaling will handle.
1233
+ #
1234
+ # @rbs font: Gruff::Font
1235
+ # @rbs text: String
1236
+ # @rbs rotation: Float | Integer
1237
+ # @rbs return: Float | Integer
1128
1238
  def calculate_width(font, text, rotation: 0)
1129
1239
  text = text.to_s
1130
1240
  return 0 if text.empty?
@@ -1134,10 +1244,15 @@ module Gruff
1134
1244
  (metrics.width * Math.cos(deg2rad(rotation))).abs - (metrics.height * Math.sin(deg2rad(rotation))).abs
1135
1245
  end
1136
1246
 
1247
+ # @rbs font: Gruff::Font
1248
+ # @rbs text: String
1249
+ # @rbs rotation: Float | Integer
1250
+ # @rbs return: untyped
1137
1251
  def text_metrics(font, text, rotation: 0)
1138
1252
  Gruff::Renderer::Text.new(renderer, text, font: font, rotation: rotation).metrics
1139
1253
  end
1140
1254
 
1255
+ # @rbs return: Float | Integer | BigDecimal
1141
1256
  def calculate_increment
1142
1257
  if @y_axis_increment.nil?
1143
1258
  # Try to use a number of horizontal lines that will come out even.
@@ -1151,6 +1266,11 @@ module Gruff
1151
1266
  end
1152
1267
  end
1153
1268
 
1269
+ # @rbs font: Gruff::Font
1270
+ # @rbs label: String
1271
+ # @rbs margin: Float | Integer
1272
+ # @rbs rotation: Float | Integer
1273
+ # @rbs return: [Float | Integer, Float | Integer]
1154
1274
  def calculate_label_offset(font, label, margin, rotation)
1155
1275
  width = calculate_width(font, label, rotation: rotation)
1156
1276
  height = calculate_height(font, label, rotation: rotation)
@@ -1164,16 +1284,21 @@ module Gruff
1164
1284
  -(width / 2.0)
1165
1285
  end
1166
1286
  end
1287
+ x_offset ||= 0
1167
1288
  y_offset = [(height / 2.0), margin].max
1168
1289
 
1169
1290
  [x_offset, y_offset]
1170
1291
  end
1171
1292
 
1172
1293
  # Used for degree <=> radian conversions
1294
+ # @rbs angle: Float | Integer
1295
+ # @rbs return: Float
1173
1296
  def deg2rad(angle)
1174
1297
  (angle * Math::PI) / 180.0
1175
1298
  end
1176
1299
 
1300
+ # @rbs angle: Float | Integer
1301
+ # @rbs return: Float
1177
1302
  def rad2deg(angle)
1178
1303
  (angle / Math::PI) * 180.0
1179
1304
  end