gruff 0.11.0-java → 0.12.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/gruff.gemspec +7 -3
  4. data/lib/gruff.rb +8 -3
  5. data/lib/gruff/accumulator_bar.rb +0 -2
  6. data/lib/gruff/area.rb +0 -4
  7. data/lib/gruff/bar.rb +18 -5
  8. data/lib/gruff/base.rb +78 -41
  9. data/lib/gruff/bezier.rb +0 -4
  10. data/lib/gruff/bullet.rb +2 -9
  11. data/lib/gruff/dot.rb +1 -5
  12. data/lib/gruff/helper/bar_conversion.rb +1 -1
  13. data/lib/gruff/helper/bar_value_label_mixin.rb +3 -0
  14. data/lib/gruff/histogram.rb +0 -1
  15. data/lib/gruff/line.rb +5 -11
  16. data/lib/gruff/mini/bar.rb +1 -1
  17. data/lib/gruff/mini/legend.rb +9 -4
  18. data/lib/gruff/mini/pie.rb +1 -2
  19. data/lib/gruff/mini/side_bar.rb +1 -2
  20. data/lib/gruff/net.rb +5 -6
  21. data/lib/gruff/patch/rmagick.rb +22 -24
  22. data/lib/gruff/patch/string.rb +7 -4
  23. data/lib/gruff/photo_bar.rb +0 -4
  24. data/lib/gruff/pie.rb +1 -5
  25. data/lib/gruff/renderer/bezier.rb +4 -3
  26. data/lib/gruff/renderer/circle.rb +4 -3
  27. data/lib/gruff/renderer/dash_line.rb +4 -3
  28. data/lib/gruff/renderer/dot.rb +4 -3
  29. data/lib/gruff/renderer/ellipse.rb +4 -3
  30. data/lib/gruff/renderer/line.rb +5 -4
  31. data/lib/gruff/renderer/polygon.rb +5 -4
  32. data/lib/gruff/renderer/polyline.rb +4 -3
  33. data/lib/gruff/renderer/rectangle.rb +3 -2
  34. data/lib/gruff/renderer/renderer.rb +31 -43
  35. data/lib/gruff/renderer/text.rb +10 -6
  36. data/lib/gruff/scatter.rb +1 -5
  37. data/lib/gruff/scene.rb +0 -1
  38. data/lib/gruff/side_bar.rb +22 -6
  39. data/lib/gruff/side_stacked_bar.rb +19 -6
  40. data/lib/gruff/spider.rb +2 -6
  41. data/lib/gruff/stacked_area.rb +0 -5
  42. data/lib/gruff/stacked_bar.rb +17 -5
  43. data/lib/gruff/store/{base_data.rb → basic_data.rb} +5 -7
  44. data/lib/gruff/store/custom_data.rb +4 -6
  45. data/lib/gruff/store/store.rb +5 -4
  46. data/lib/gruff/store/xy_data.rb +6 -7
  47. data/lib/gruff/version.rb +1 -1
  48. metadata +18 -15
  49. data/.editorconfig +0 -14
  50. data/.github/ISSUE_TEMPLATE.md +0 -18
  51. data/.gitignore +0 -10
  52. data/.rubocop.yml +0 -109
  53. data/.rubocop_todo.yml +0 -112
  54. data/.travis.yml +0 -26
  55. data/.yardopts +0 -1
  56. data/Rakefile +0 -47
  57. data/docker/Dockerfile +0 -14
  58. data/docker/build.sh +0 -4
  59. data/docker/launch.sh +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2eb363f545e171df5a5d457b5d34e867a060dc4d84eda87d77b2447172d2c04
4
- data.tar.gz: fa7708d508f2a016c11af3c08d2b877ff65eaf62955658c9b57fbd08b9f45659
3
+ metadata.gz: 86f7128ad67d7111e7f286742bef3ec55674923f120f7b53747c2aeb19011aa7
4
+ data.tar.gz: 8a8554f44e0c642a04d2aa87763696be6cba4d207e7bd33a8945df860fac9246
5
5
  SHA512:
6
- metadata.gz: 06d22482b55dd1f478f9ad8ae660f8fe96a4f4b8c7f651207b3de2d1cacf9c1399cf6d88ebd3fdad3178acb020371924f189fa86ee6107d240850788dd9156f3
7
- data.tar.gz: 61461cbe1691e7aec5a6c178778c0f40ede97d496857f6a797867be3ae6f52565b33ad8556654ce592aec2717e11e7512bf2cfb25e7cfcdff9797da1faeb9b01
6
+ metadata.gz: c4c709368e7a3cb96390099e7577df107343e179005c374dda3ad0f1ec981304f556eea435c71b50214e622a11544c4bb7ca6ec8519af41616c9b463c69940ec
7
+ data.tar.gz: 19528b2ac748979d5acb64c7fd8ff3c66d819d03754249398ab4daacb16a44bac28afad60db20eac1c8b4e4b94e610508702c45c035e49da241847a4e42f834f
@@ -1,5 +1,14 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.12.0
4
+ - Mark Gruff::Base#to_blob as deprecated (#473)
5
+ - Add Gruff::Base#to_image method (#472)
6
+ - Drop support of Ruby v2.3.x or below (#453, #448)
7
+ - add hide_labels to stacked side bar graphs (#452)
8
+ - add hide_labels to side bar graphs (#451)
9
+ - add hide_labels to stacked bar graphs (#450)
10
+ - support hide_labels separate from hide_line_markers for bar graphs only (#446)
11
+
3
12
  ## 0.11.0
4
13
  - Fix regression in empty data handling (#445)
5
14
  - Rendering text in front most (#439)
@@ -13,7 +13,9 @@ Gem::Specification.new do |s|
13
13
  s.date = Date.today.to_s
14
14
  s.description = 'Beautiful graphs for one or multiple datasets. Can be used on websites or in documents.'
15
15
  s.email = 'boss@topfunky.com'
16
- s.files = `git ls-files`.split($/).reject { |f| f =~ /^test/ }
16
+ s.files = `git ls-files`.split.reject do |f|
17
+ f =~ /^\.|^test|^docker|^Rakefile/
18
+ end
17
19
  s.homepage = 'https://github.com/topfunky/gruff'
18
20
  s.require_paths = %w[lib]
19
21
  s.summary = 'Beautiful graphs for one or multiple datasets.'
@@ -27,12 +29,14 @@ Gem::Specification.new do |s|
27
29
  s.add_dependency 'rmagick4j'
28
30
  else
29
31
  s.add_dependency 'rmagick'
30
- s.add_development_dependency 'rubocop', '~> 0.81.0'
32
+ s.add_development_dependency 'rubocop', '~> 1.0.0'
33
+ s.add_development_dependency 'rubocop-performance', '~> 1.8'
31
34
  end
32
35
  s.add_dependency 'histogram'
33
- s.required_ruby_version = '>= 1.9.3'
36
+ s.required_ruby_version = '>= 2.4.0'
34
37
 
35
38
  s.add_development_dependency 'rake'
39
+ s.add_development_dependency 'parallel'
36
40
  s.add_development_dependency 'minitest-reporters'
37
41
  s.add_development_dependency 'yard', '~> 0.9.25'
38
42
  end
@@ -9,8 +9,13 @@ require 'gruff/version'
9
9
  patch/rmagick
10
10
  patch/string
11
11
 
12
- themes
13
12
  base
13
+
14
+ helper/bar_conversion.rb
15
+ helper/stacked_mixin
16
+ helper/bar_value_label_mixin
17
+
18
+ themes
14
19
  area
15
20
  bar
16
21
  bezier
@@ -22,10 +27,10 @@ require 'gruff/version'
22
27
  pie
23
28
  scatter
24
29
  spider
30
+ side_bar
25
31
  stacked_area
26
32
  stacked_bar
27
33
  side_stacked_bar
28
- side_bar
29
34
  accumulator_bar
30
35
 
31
36
  scene
@@ -43,7 +48,7 @@ require 'gruff/version'
43
48
  renderer/text
44
49
 
45
50
  store/store
46
- store/base_data
51
+ store/basic_data
47
52
  store/custom_data
48
53
  store/xy_data
49
54
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'gruff/base'
4
-
5
3
  #
6
4
  # Gruff::AccumulatorBar is a special bar graph that shows a
7
5
  # single dataset as a set of stacked bars.
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'gruff/base'
4
-
5
3
  #
6
4
  # Gruff::Area provides an area graph which displays graphically
7
5
  # quantitative data.
@@ -59,7 +57,5 @@ class Gruff::Area < Gruff::Base
59
57
 
60
58
  Gruff::Renderer::Polygon.new(color: data_row.color, width: @stroke_width, opacity: @fill_opacity).render(poly_points)
61
59
  end
62
-
63
- Gruff::Renderer.finish
64
60
  end
65
61
  end
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'gruff/base'
4
- require 'gruff/helper/bar_conversion'
5
-
6
3
  #
7
4
  # Gruff::Bar provide a bar graph that presents categorical data
8
5
  # with rectangular bars.
@@ -19,6 +16,8 @@ require 'gruff/helper/bar_conversion'
19
16
  # g.write('bar.png')
20
17
  #
21
18
  class Gruff::Bar < Gruff::Base
19
+ using String::GruffCommify
20
+
22
21
  # Spacing factor applied between bars.
23
22
  attr_writer :bar_spacing
24
23
 
@@ -33,12 +32,16 @@ class Gruff::Bar < Gruff::Base
33
32
  # Default is +false+.
34
33
  attr_writer :show_labels_for_bar_values
35
34
 
35
+ # Prevent drawing of column labels below a bar graph. Default is +false+.
36
+ attr_writer :hide_labels
37
+
36
38
  def initialize_ivars
37
39
  super
38
40
  @spacing_factor = 0.9
39
41
  @group_spacing = 10
40
42
  @label_formatting = nil
41
43
  @show_labels_for_bar_values = false
44
+ @hide_labels = false
42
45
  end
43
46
  private :initialize_ivars
44
47
 
@@ -68,6 +71,18 @@ class Gruff::Bar < Gruff::Base
68
71
 
69
72
  protected
70
73
 
74
+ def hide_labels?
75
+ @hide_labels
76
+ end
77
+
78
+ def hide_left_label_area?
79
+ @hide_line_markers
80
+ end
81
+
82
+ def hide_bottom_label_area?
83
+ hide_labels?
84
+ end
85
+
71
86
  def draw_bars
72
87
  # Setup spacing.
73
88
  #
@@ -129,8 +144,6 @@ protected
129
144
 
130
145
  # Draw the last label if requested
131
146
  draw_label(@graph_right, column_count, Magick::NorthWestGravity) if @center_labels_over_point
132
-
133
- Gruff::Renderer.finish
134
147
  end
135
148
 
136
149
  def calculate_spacing
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rmagick'
4
3
  require 'bigdecimal'
5
4
 
6
5
  ##
@@ -17,6 +16,9 @@ require 'bigdecimal'
17
16
  #
18
17
  # See {Gruff::Base#theme=} for setting themes.
19
18
  module Gruff
19
+ using String::GruffCommify
20
+
21
+ # A common base class inherited from class of drawing a graph.
20
22
  class Base
21
23
  # Space around text elements. Mostly used for vertical spacing.
22
24
  LEGEND_MARGIN = TITLE_MARGIN = 20.0
@@ -195,11 +197,11 @@ module Gruff
195
197
  protected :initialize_graph_scale
196
198
 
197
199
  def initialize_store
198
- @store = Gruff::Store.new(Gruff::Store::BaseData)
200
+ @store = Gruff::Store.new(Gruff::Store::BasicData)
199
201
  end
200
202
  protected :initialize_store
201
203
 
202
- # Initialize instance variable of attribures
204
+ # Initialize instance variable of attributes
203
205
  #
204
206
  # Subclasses can override this, call super, then set values separately.
205
207
  #
@@ -414,16 +416,40 @@ module Gruff
414
416
  # @example
415
417
  # write('graphs/my_pretty_graph.png')
416
418
  def write(file_name = 'graph.png')
417
- draw
418
- Gruff::Renderer.write(file_name)
419
+ to_image.write(file_name)
420
+ end
421
+
422
+ # Return a rendered graph image.
423
+ # This can use RMagick's methods to adjust the image before saving.
424
+ #
425
+ # @return [Magick::Image] The rendered image.
426
+ #
427
+ # @example
428
+ # g = Gruff::Line.new
429
+ # g.data :Jimmy, [25, 36, 86, 39, 25, 31, 79, 88]
430
+ # g.data :Charles, [80, 54, 67, 54, 68, 70, 90, 95]
431
+ # image = g.to_image
432
+ # image = image.resize(400, 300).quantize(128, Magick::RGBColorspace)
433
+ # image.write('test.png')
434
+ #
435
+ def to_image
436
+ @to_image ||= begin
437
+ draw
438
+ Gruff::Renderer.finish
439
+ Gruff::Renderer.instance.image
440
+ end
419
441
  end
420
442
 
421
443
  # Return the graph as a rendered binary blob.
422
444
  #
423
445
  # @param image_format [String] The image format of binary blob.
446
+ #
447
+ # @deprecated Please use +to_image.to_blob+ instead.
424
448
  def to_blob(image_format = 'PNG')
425
- draw
426
- Gruff::Renderer.to_blob(image_format)
449
+ warn '#to_blob is deprecated. Please use `to_image.to_blob` instead'
450
+ to_image.to_blob do
451
+ self.format = image_format
452
+ end
427
453
  end
428
454
 
429
455
  protected
@@ -486,6 +512,18 @@ module Gruff
486
512
  store.columns
487
513
  end
488
514
 
515
+ def marker_count
516
+ @marker_count ||= begin
517
+ count = nil
518
+ (3..7).each do |lines|
519
+ if @spread.to_f % lines == 0.0
520
+ count = lines and break
521
+ end
522
+ end
523
+ count || 4
524
+ end
525
+ end
526
+
489
527
  # Make copy of data with values scaled between 0-100
490
528
  def normalize
491
529
  store.normalize(minimum: minimum_value, spread: @spread)
@@ -500,6 +538,18 @@ module Gruff
500
538
  @hide_title || @title.nil? || @title.empty?
501
539
  end
502
540
 
541
+ def hide_labels?
542
+ @hide_line_markers
543
+ end
544
+
545
+ def hide_left_label_area?
546
+ @hide_line_markers
547
+ end
548
+
549
+ def hide_bottom_label_area?
550
+ @hide_line_markers
551
+ end
552
+
503
553
  ##
504
554
  # Calculates size of drawable area, general font dimensions, etc.
505
555
 
@@ -545,7 +595,7 @@ module Gruff
545
595
  increment_scaled = @graph_height.to_f / (@spread / @increment)
546
596
 
547
597
  # Draw horizontal line markers and annotate with numbers
548
- (0..@marker_count).each do |index|
598
+ (0..marker_count).each do |index|
549
599
  y = @graph_top + @graph_height - index.to_f * increment_scaled
550
600
 
551
601
  line_renderer = Gruff::Renderer::Line.new(color: @marker_color, shadow_color: @marker_shadow_color)
@@ -560,13 +610,6 @@ module Gruff
560
610
  end
561
611
  end
562
612
 
563
- # Return the sum of values in an array.
564
- #
565
- # Duplicated to not conflict with active_support in Rails.
566
- def sum(arr)
567
- arr.reduce(0) { |i, m| m + i }
568
- end
569
-
570
613
  # Return a calculation of center
571
614
  def center(size)
572
615
  (@raw_columns - size) / 2
@@ -581,7 +624,7 @@ module Gruff
581
624
  legend_square_width = @legend_box_size # small square with color of this item
582
625
  label_widths = calculate_legend_label_widths_for_each_line(legend_labels, legend_square_width)
583
626
 
584
- current_x_offset = center(sum(label_widths.first))
627
+ current_x_offset = center(label_widths.first.sum)
585
628
  current_y_offset = begin
586
629
  if @legend_at_bottom
587
630
  @graph_height + @title_margin
@@ -611,7 +654,7 @@ module Gruff
611
654
  # Handle wrapping
612
655
  if label_widths.first.empty?
613
656
  label_widths.shift
614
- current_x_offset = center(sum(label_widths.first)) unless label_widths.empty?
657
+ current_x_offset = center(label_widths.first.sum) unless label_widths.empty?
615
658
  line_height = [@legend_caps_height, legend_square_width].max + @legend_margin
616
659
  unless label_widths.empty?
617
660
  # Wrap to next line and shrink available graph dimensions
@@ -661,7 +704,7 @@ module Gruff
661
704
  end
662
705
 
663
706
  def draw_unique_label(index)
664
- return if @hide_line_markers
707
+ return if hide_labels?
665
708
 
666
709
  @labels_seen ||= {}
667
710
  if !@labels[index].nil? && @labels_seen[index].nil?
@@ -746,7 +789,7 @@ module Gruff
746
789
  private
747
790
 
748
791
  def setup_marker_caps_height
749
- @hide_line_markers ? 0 : calculate_caps_height(@marker_font_size)
792
+ hide_bottom_label_area? ? 0 : calculate_caps_height(@marker_font_size)
750
793
  end
751
794
 
752
795
  def setup_title_caps_height
@@ -769,15 +812,18 @@ module Gruff
769
812
  end
770
813
 
771
814
  def setup_left_margin
772
- return @left_margin if @hide_line_markers
815
+ return @left_margin if hide_left_label_area?
773
816
 
774
- if @has_left_labels
775
- longest_left_label_width = calculate_width(@marker_font_size,
776
- @labels.values.reduce('') { |value, memo| (value.to_s.length > memo.to_s.length) ? value : memo }) * 1.25
777
- else
778
- longest_left_label_width = calculate_width(@marker_font_size,
779
- label(maximum_value.to_f, @increment))
817
+ text = begin
818
+ if @has_left_labels
819
+ @labels.values.reduce('') { |value, memo| (value.to_s.length > memo.to_s.length) ? value : memo }
820
+ else
821
+ label(maximum_value.to_f, @increment)
822
+ end
780
823
  end
824
+ longest_left_label_width = calculate_width(@marker_font_size, text)
825
+ longest_left_label_width *= 1.25 if @has_left_labels
826
+
781
827
  # Shift graph if left line numbers are hidden
782
828
  line_number_width = @hide_line_numbers && !@has_left_labels ? 0.0 : (longest_left_label_width + LABEL_MARGIN * 2)
783
829
 
@@ -795,7 +841,7 @@ module Gruff
795
841
  end
796
842
 
797
843
  def setup_bottom_margin
798
- graph_bottom_margin = @hide_line_markers ? @bottom_margin : @bottom_margin + @marker_caps_height + LABEL_MARGIN
844
+ graph_bottom_margin = hide_bottom_label_area? ? @bottom_margin : @bottom_margin + @marker_caps_height + LABEL_MARGIN
799
845
 
800
846
  x_axis_label_height = @x_axis_label.nil? ? 0.0 : @marker_caps_height + LABEL_MARGIN
801
847
  # FIXME: Consider chart types other than bar
@@ -831,7 +877,7 @@ module Gruff
831
877
  else
832
878
  value.to_s
833
879
  end
834
- elsif (@spread.to_f % (@marker_count.to_f == 0 ? 1 : @marker_count.to_f) == 0) || !@y_axis_increment.nil?
880
+ elsif (@spread.to_f % (marker_count.to_f == 0 ? 1 : marker_count.to_f) == 0) || !@y_axis_increment.nil?
835
881
  value.to_i.to_s
836
882
  elsif @spread > 10.0
837
883
  sprintf('%0i', value)
@@ -854,7 +900,7 @@ module Gruff
854
900
  label_width = width + legend_square_width * 2.7
855
901
  label_widths.last.push label_width
856
902
 
857
- if sum(label_widths.last) > (@raw_columns * 0.9)
903
+ if label_widths.last.sum > (@raw_columns * 0.9)
858
904
  label_widths.push [label_widths.last.pop]
859
905
  end
860
906
  end
@@ -872,7 +918,7 @@ module Gruff
872
918
  metrics.height
873
919
  end
874
920
 
875
- # Returns the width of a string at this pointsize.
921
+ # Returns the width of a string at this point size.
876
922
  #
877
923
  # Not scaled since it deals with dimensions that the regular
878
924
  # scaling will handle.
@@ -889,19 +935,10 @@ module Gruff
889
935
  # Try to use a number of horizontal lines that will come out even.
890
936
  #
891
937
  # TODO Do the same for larger numbers...100, 75, 50, 25
892
- if @marker_count.nil?
893
- (3..7).each do |lines|
894
- if @spread % lines == 0.0
895
- @marker_count = lines
896
- break
897
- end
898
- end
899
- @marker_count ||= 4
900
- end
901
- @increment = (@spread > 0 && @marker_count > 0) ? significant(@spread / @marker_count) : 1
938
+ @increment = (@spread > 0 && marker_count > 0) ? significant(@spread / marker_count) : 1
902
939
  else
903
940
  # TODO: Make this work for negative values
904
- @marker_count = (@spread / @y_axis_increment).to_i
941
+ self.marker_count = (@spread / @y_axis_increment).to_i
905
942
  @increment = @y_axis_increment
906
943
  end
907
944
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'gruff/base'
4
-
5
3
  #
6
4
  # Gruff::Bezier is a special line graph that have
7
5
  # the bezier curve.
@@ -55,7 +53,5 @@ class Gruff::Bezier < Gruff::Base
55
53
  Gruff::Renderer::Bezier.new(color: data_row.color, width: stroke_width).render(poly_points)
56
54
  end
57
55
  end
58
-
59
- Gruff::Renderer.finish
60
56
  end
61
57
  end
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'gruff/base'
4
- require 'gruff/themes'
5
-
6
3
  #
7
4
  # A bullet graph is a variation of a bar graph.
8
5
  # http://en.wikipedia.org/wiki/Bullet_graph
@@ -16,6 +13,8 @@ require 'gruff/themes'
16
13
  #
17
14
  class Gruff::Bullet < Gruff::Base
18
15
  def initialize(target_width = '400x40')
16
+ super
17
+
19
18
  if target_width.is_a?(String)
20
19
  @columns, @rows = target_width.split('x').map(&:to_f)
21
20
  else
@@ -25,10 +24,6 @@ class Gruff::Bullet < Gruff::Base
25
24
  @columns.freeze
26
25
  @rows.freeze
27
26
 
28
- initialize_graph_scale
29
- initialize_ivars
30
- initialize_store
31
-
32
27
  self.theme = Gruff::Themes::GREYSCALE
33
28
  end
34
29
 
@@ -88,8 +83,6 @@ class Gruff::Bullet < Gruff::Base
88
83
  # Value
89
84
  rect_renderer = Gruff::Renderer::Rectangle.new(color: @font_color)
90
85
  rect_renderer.render(graph_left, thickness, graph_left + graph_width * (@value / maximum_value), thickness * 2)
91
-
92
- Gruff::Renderer.finish
93
86
  end
94
87
 
95
88
  private