gruff 0.21.0 → 0.22.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d83fb72593318497b0fe0ff48a98f9f30f7f6c2795b30d1695757ae5d2b808df
4
- data.tar.gz: 77bf7f31d3339c4a4065dbd47a9ed586f486781641fd59c9fc01b1ff9779e605
3
+ metadata.gz: 94b068b7869b405ca194785d34d320aba16ff0cff793982571039498590b31e8
4
+ data.tar.gz: 1e423203482f8b02d5a678f48237c627f39d09b3bbe7921b758284caf2a3f978
5
5
  SHA512:
6
- metadata.gz: 4bc158cc912fdc90f795c280e2ae3fab90ffb7d7513b9a6ed3432b4d732b0acbaf8ff52dfd674c2cd30758e0423744002e6bc2fd96bd8db98f2222bfb2224f78
7
- data.tar.gz: 7a2bcddc07f2225eaac48304de583235818ead0d1664b90818913953b0baff25e410c90bf899ba8866d26605886dbba6e352a8ce6e8e71df615f1d56e7c8c99a
6
+ metadata.gz: 30e1d06427a70bb4dd5c551f7154a34825f3800890f96fb56649e0b95f0eb0d8539c636535f292217b6730c0ff27652246d7444a20d60aa49c4ef50ca2eca59b
7
+ data.tar.gz: 03af63b9451e5e7f62ed7260026cf6e968694f82f43d50f6eb0efd7dbf03b112d3ea6a00deb63b0b20248321f847ad1bb3c5bccd0148e337ae755526bc85ccc7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.22.0
4
+ Fix Gruff::Bar and Gruff::SideBar in order to draw positive and negative mixed graph (#620)
5
+ Allow to override label margin value (#618)
6
+ Accept image format in Base#to_image in order to fix `no decode delegate for this image format` error (#619)
7
+
3
8
  ## 0.21.0
4
9
  - Fix legend color with empty label (#615)
5
10
 
data/README.md CHANGED
@@ -144,8 +144,8 @@ http://www.rubydoc.info/github/topfunky/gruff/frames
144
144
 
145
145
  ## Supported Ruby Versions
146
146
 
147
- - Ruby 2.5 or later
148
- - JRuby 9.2.x or later
147
+ - Ruby 2.6 or later
148
+ - JRuby 9.3.x or later
149
149
 
150
150
  ## Development
151
151
  1. Build docker image
data/lib/gruff/bar.rb CHANGED
@@ -123,7 +123,7 @@ private
123
123
  right_x = left_x + (bar_width * @bar_spacing)
124
124
 
125
125
  top_y, bottom_y = conversion.get_top_bottom_scaled(bar.point)
126
- if bar.point != 0
126
+ if top_y != bottom_y
127
127
  rect_renderer = Gruff::Renderer::Rectangle.new(renderer, color: bar.color)
128
128
  rect_renderer.render(left_x, bottom_y - AXIS_MARGIN, right_x, top_y)
129
129
  end
data/lib/gruff/base.rb CHANGED
@@ -27,6 +27,9 @@ module Gruff
27
27
 
28
28
  DEFAULT_TARGET_WIDTH = 800.0
29
29
 
30
+ # Blank space between graph and labels. Default is +15+.
31
+ attr_writer :label_margin
32
+
30
33
  # Blank space above the graph. Default is +20+.
31
34
  attr_writer :top_margin
32
35
 
@@ -180,6 +183,7 @@ module Gruff
180
183
  @marker_font = Gruff::Font.new(size: 21.0)
181
184
  @legend_font = Gruff::Font.new(size: 20.0)
182
185
 
186
+ @label_margin = LABEL_MARGIN
183
187
  @top_margin = @bottom_margin = @left_margin = @right_margin = DEFAULT_MARGIN
184
188
  @legend_margin = LEGEND_MARGIN
185
189
  @title_margin = TITLE_MARGIN
@@ -497,6 +501,8 @@ module Gruff
497
501
  # Return a rendered graph image.
498
502
  # This can use RMagick's methods to adjust the image before saving.
499
503
  #
504
+ # @param format [String] The output image format.
505
+ #
500
506
  # @return [Magick::Image] The rendered image.
501
507
  #
502
508
  # @example
@@ -507,22 +513,24 @@ module Gruff
507
513
  # image = image.resize(400, 300).quantize(128, Magick::RGBColorspace)
508
514
  # image.write('test.png')
509
515
  #
510
- def to_image
516
+ def to_image(format = 'PNG')
511
517
  @to_image ||= begin
512
518
  draw
513
519
  renderer.finish
514
- renderer.image
520
+ image = renderer.image
521
+ image.format = format
522
+ image
515
523
  end
516
524
  end
517
525
 
518
526
  # Return the graph as a rendered binary blob.
519
527
  #
520
- # @param image_format [String] The image format of binary blob.
528
+ # @param format [String] The image format of binary blob.
521
529
  #
522
530
  # @deprecated Please use +to_image.to_blob+ instead.
523
- def to_blob(image_format = 'PNG')
531
+ def to_blob(format = 'PNG')
524
532
  warn '#to_blob is deprecated. Please use `to_image.to_blob` instead'
525
- to_image.format = image_format
533
+ to_image.format = format
526
534
  to_image.to_blob
527
535
  end
528
536
 
@@ -646,7 +654,7 @@ module Gruff
646
654
  # X Axis
647
655
  # Centered vertically and horizontally by setting the
648
656
  # height to 1.0 and the width to the width of the graph.
649
- x_axis_label_y_coordinate = @graph_bottom + (LABEL_MARGIN * 2) + labels_caps_height
657
+ x_axis_label_y_coordinate = @graph_bottom + (@label_margin * 2) + labels_caps_height
650
658
 
651
659
  text_renderer = Gruff::Renderer::Text.new(renderer, @x_axis_label, font: @marker_font)
652
660
  text_renderer.add_to_render_queue(@raw_columns, 1.0, 0.0, x_axis_label_y_coordinate)
@@ -674,7 +682,7 @@ module Gruff
674
682
  marker_label = (BigDecimal(index.to_s) * BigDecimal(@increment.to_s)) + BigDecimal(minimum_value.to_s)
675
683
  label = y_axis_label(marker_label, @increment)
676
684
  text_renderer = Gruff::Renderer::Text.new(renderer, label, font: @marker_font)
677
- text_renderer.add_to_render_queue(@graph_left - LABEL_MARGIN, 1.0, 0.0, y, Magick::EastGravity)
685
+ text_renderer.add_to_render_queue(@graph_left - @label_margin, 1.0, 0.0, y, Magick::EastGravity)
678
686
  end
679
687
  end
680
688
  end
@@ -715,7 +723,7 @@ module Gruff
715
723
 
716
724
  current_y_offset = begin
717
725
  if @legend_at_bottom
718
- @graph_bottom + @legend_margin + labels_caps_height + LABEL_MARGIN + (@x_axis_label ? (LABEL_MARGIN * 2) + marker_caps_height : 0)
726
+ @graph_bottom + @legend_margin + labels_caps_height + @label_margin + (@x_axis_label ? (@label_margin * 2) + marker_caps_height : 0)
719
727
  else
720
728
  hide_title? ? @top_margin + @title_margin : @top_margin + @title_margin + title_caps_height
721
729
  end
@@ -771,7 +779,7 @@ module Gruff
771
779
  draw_unique_label(index) do
772
780
  if x >= @graph_left && x <= @graph_right
773
781
  y = @graph_bottom
774
- x_offset, y_offset = calculate_label_offset(@marker_font, @labels[index], LABEL_MARGIN, @label_rotation)
782
+ x_offset, y_offset = calculate_label_offset(@marker_font, @labels[index], @label_margin, @label_rotation)
775
783
 
776
784
  draw_label_at(1.0, 1.0, x + x_offset, y + y_offset, @labels[index], gravity: gravity, rotation: @label_rotation)
777
785
  yield if block
@@ -899,10 +907,10 @@ module Gruff
899
907
  if !@has_left_labels && (@hide_line_markers || @hide_line_numbers)
900
908
  0.0
901
909
  else
902
- longest_left_label_width + LABEL_MARGIN
910
+ longest_left_label_width + @label_margin
903
911
  end
904
912
  end
905
- y_axis_label_width = @y_axis_label.nil? ? 0.0 : marker_caps_height + (LABEL_MARGIN * 2)
913
+ y_axis_label_width = @y_axis_label.nil? ? 0.0 : marker_caps_height + (@label_margin * 2)
906
914
 
907
915
  bottom_label_width = extra_left_room_for_long_label
908
916
 
@@ -962,10 +970,10 @@ module Gruff
962
970
  end
963
971
 
964
972
  def setup_bottom_margin
965
- graph_bottom_margin = hide_bottom_label_area? ? @bottom_margin : @bottom_margin + labels_caps_height + LABEL_MARGIN
973
+ graph_bottom_margin = hide_bottom_label_area? ? @bottom_margin : @bottom_margin + labels_caps_height + @label_margin
966
974
  graph_bottom_margin += (calculate_legend_height + @legend_margin) if @legend_at_bottom
967
975
 
968
- x_axis_label_height = @x_axis_label.nil? ? 0.0 : marker_caps_height + (LABEL_MARGIN * 2)
976
+ x_axis_label_height = @x_axis_label.nil? ? 0.0 : marker_caps_height + (@label_margin * 2)
969
977
  @raw_rows - graph_bottom_margin - x_axis_label_height
970
978
  end
971
979
 
data/lib/gruff/dot.rb CHANGED
@@ -59,7 +59,7 @@ private
59
59
  unless @hide_line_numbers
60
60
  label = y_axis_label(marker_label, @increment)
61
61
  text_renderer = Gruff::Renderer::Text.new(renderer, label, font: @marker_font)
62
- text_renderer.add_to_render_queue(0, 0, x, @graph_bottom + (LABEL_MARGIN * 1.5), Magick::CenterGravity)
62
+ text_renderer.add_to_render_queue(0, 0, x, @graph_bottom + (@label_margin * 1.5), Magick::CenterGravity)
63
63
  end
64
64
  end
65
65
  end
@@ -69,7 +69,7 @@ private
69
69
 
70
70
  def draw_label(y_offset, index)
71
71
  draw_unique_label(index) do
72
- draw_label_at(@graph_left - LABEL_MARGIN, 1.0, 0.0, y_offset, @labels[index], gravity: Magick::EastGravity)
72
+ draw_label_at(@graph_left - @label_margin, 1.0, 0.0, y_offset, @labels[index], gravity: Magick::EastGravity)
73
73
  end
74
74
  end
75
75
  end
data/lib/gruff/net.rb CHANGED
@@ -112,8 +112,8 @@ private
112
112
  def draw_label(center_x, center_y, angle, radius, amount)
113
113
  x_offset = center_x # + 15 # The label points need to be tweaked slightly
114
114
  y_offset = center_y # + 0 # This one doesn't though
115
- x = x_offset + ((radius + LABEL_MARGIN) * Math.sin(deg2rad(angle)))
116
- y = y_offset - ((radius + LABEL_MARGIN) * Math.cos(deg2rad(angle)))
115
+ x = x_offset + ((radius + @label_margin) * Math.sin(deg2rad(angle)))
116
+ y = y_offset - ((radius + @label_margin) * Math.cos(deg2rad(angle)))
117
117
 
118
118
  draw_label_at(1.0, 1.0, x, y, amount, gravity: Magick::CenterGravity)
119
119
  end
data/lib/gruff/scatter.rb CHANGED
@@ -188,7 +188,7 @@ private
188
188
  label = x_axis_label(marker_label, x_increment)
189
189
  x = @graph_left + (increment_x_scaled * index)
190
190
  y = @graph_bottom
191
- x_offset, y_offset = calculate_label_offset(@marker_font, label, LABEL_MARGIN, @label_rotation)
191
+ x_offset, y_offset = calculate_label_offset(@marker_font, label, @label_margin, @label_rotation)
192
192
 
193
193
  draw_label_at(1.0, 1.0, x + x_offset, y + y_offset, label, rotation: @label_rotation)
194
194
  end
@@ -90,7 +90,7 @@ private
90
90
 
91
91
  if minimum_value < 0
92
92
  _, metrics = Gruff::BarValueLabel.metrics(minimum_value, @label_formatting, proc_text_metrics)
93
- width = metrics.width + LABEL_MARGIN
93
+ width = metrics.width + @label_margin
94
94
  @graph_left += width - @graph_left if width > @graph_left
95
95
  end
96
96
 
@@ -120,7 +120,7 @@ private
120
120
  right_y = left_y + (bar_width * @bar_spacing)
121
121
 
122
122
  bottom_x, top_x = conversion.get_top_bottom_scaled(bar.point).sort
123
- if bar.point != 0
123
+ if bottom_x != top_x
124
124
  rect_renderer = Gruff::Renderer::Rectangle.new(renderer, color: bar.color)
125
125
  rect_renderer.render(bottom_x + AXIS_MARGIN, left_y, top_x, right_y)
126
126
  end
@@ -160,7 +160,7 @@ private
160
160
  marker_label = (BigDecimal(diff.abs.to_s) * BigDecimal(increment.to_s)) + BigDecimal(minimum_value.to_s)
161
161
  label = x_axis_label(marker_label, @increment)
162
162
  text_renderer = Gruff::Renderer::Text.new(renderer, label, font: @marker_font)
163
- text_renderer.add_to_render_queue(0, 0, x, @graph_bottom + LABEL_MARGIN, Magick::CenterGravity)
163
+ text_renderer.add_to_render_queue(0, 0, x, @graph_bottom + @label_margin, Magick::CenterGravity)
164
164
  end
165
165
  end
166
166
  end
@@ -170,7 +170,7 @@ private
170
170
 
171
171
  def draw_label(y_offset, index)
172
172
  draw_unique_label(index) do
173
- draw_label_at(@graph_left - LABEL_MARGIN, 1.0, 0.0, y_offset, @labels[index], gravity: Magick::EastGravity)
173
+ draw_label_at(@graph_left - @label_margin, 1.0, 0.0, y_offset, @labels[index], gravity: Magick::EastGravity)
174
174
  end
175
175
  end
176
176
 
data/lib/gruff/spider.rb CHANGED
@@ -54,10 +54,10 @@ private
54
54
  def setup_graph_measurements
55
55
  super
56
56
 
57
- @graph_left += LABEL_MARGIN
58
- @graph_top += LABEL_MARGIN
59
- @graph_right -= LABEL_MARGIN
60
- @graph_bottom -= LABEL_MARGIN
57
+ @graph_left += @label_margin
58
+ @graph_top += @label_margin
59
+ @graph_right -= @label_margin
60
+ @graph_bottom -= @label_margin
61
61
 
62
62
  @graph_width = @graph_right - @graph_left
63
63
  @graph_height = @graph_bottom - @graph_top
@@ -94,7 +94,7 @@ private
94
94
  degree = rad2deg(angle)
95
95
  metrics = text_metrics(@marker_font, amount)
96
96
 
97
- r_offset = LABEL_MARGIN # The distance out from the center of the pie to get point
97
+ r_offset = @label_margin # The distance out from the center of the pie to get point
98
98
  x_offset = center_x # The label points need to be tweaked slightly
99
99
 
100
100
  x_offset -= begin
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.21.0'
4
+ VERSION = '0.22.0'
5
5
  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.21.0
4
+ version: 0.22.0
5
5
  platform: ruby
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: 2023-06-04 00:00:00.000000000 Z
12
+ date: 2023-06-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rmagick