gruff 0.16.0 → 0.17.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: 53adc2df58a382381368665252e0e5862ea81ebd4d513e051058aa5369d379a9
4
- data.tar.gz: a63a2c06b2f2f936a8ee663463248faab871cab07ba0b58c84febff858b3c08b
3
+ metadata.gz: f16153da348397448dc35f4d6435860b53040b14b0a7cbc3ca84bcaf9dd68b90
4
+ data.tar.gz: 68efd965f5b00403281ff46cc377fae9503b3b4290f49b66e6ceb424d24b4d27
5
5
  SHA512:
6
- metadata.gz: fa57dd19908889380ac8ca2ad4cf3d71da6349370ad90e6c318a01aa79fafd1db9c09f5118a4c1034aaad026596d5b42e4a5837e69ea360909c2b16e054c9fa3
7
- data.tar.gz: 2334380acbf92ebbcfc2c090912e79955c5d28f6de4fb714f2d30de4a4b2b922fd661068641a4057ba94bba90359bd1a45fd0902da941e246df93bf80e9a0601
6
+ metadata.gz: c2436acee944766653a6497854eb89493fc67f940d846e7299bdf92e2a31c8f7e267f508dad3b8593d596d31a277702983a58b7a2282b00395c33c152c657407
7
+ data.tar.gz: 7d75accebb94e9ae9362ae487265de84b7bbd6b6b90087c3ce5bd0f0e573d51d270f74bd04f3451d64aedba189fc09d5ef69b3a8c14785cb1b7d2c24b8581cc5
@@ -6,6 +6,9 @@ on:
6
6
  pull_request:
7
7
  branches: [ master ]
8
8
 
9
+ permissions:
10
+ contents: read
11
+
9
12
  jobs:
10
13
  lint:
11
14
  runs-on: ubuntu-20.04
@@ -23,7 +26,7 @@ jobs:
23
26
  - name: Install dependencies
24
27
  run: bundle install --path=vendor/bundle --jobs 4 --retry 3
25
28
  - name: RuboCop Problem Matchers
26
- uses: r7kamura/rubocop-problem-matchers-action@v1.1.0
29
+ uses: r7kamura/rubocop-problem-matchers-action@v1
27
30
  - name: Run tests
28
31
  run: bundle exec rubocop
29
32
 
@@ -34,7 +37,7 @@ jobs:
34
37
  matrix:
35
38
  ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1']
36
39
  imagemagick-version:
37
- - { full: 7.1.0-31, major-minor: '7.0' }
40
+ - { full: 7.1.0-35, major-minor: '7.0' }
38
41
  name: Ruby ${{ matrix.ruby-version }}
39
42
  steps:
40
43
  - uses: actions/checkout@v3
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  *~
2
2
  /.idea/
3
3
  /pkg/
4
+ /doc/
4
5
  /coverage/
5
6
  /vendor/
6
7
  /test/output/
data/.rubocop.yml CHANGED
@@ -48,9 +48,6 @@ Lint/FloatComparison:
48
48
  Lint/NumberConversion:
49
49
  Enabled: false
50
50
 
51
- Naming/MemoizedInstanceVariableName:
52
- Enabled: false
53
-
54
51
  Naming/MethodParameterName:
55
52
  Enabled: false
56
53
 
@@ -122,6 +119,3 @@ Style/StructInheritance:
122
119
 
123
120
  Performance/ChainArrayAllocation:
124
121
  Enabled: false
125
-
126
- Performance/StringReplacement:
127
- Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.17.0
4
+ - Add Gruff::Base#label_rotation= method to rotate bottom label (#599)
5
+ - Mark #label_stagger_height= as deprecated (#598)
6
+ - Fixed truncation of long legends in mini graph (#597)
7
+ - Fix error when input empty data in Gruff::Bezier (#596)
8
+ - Fix error when input empty data in Gruff::StackedArea (#595)
9
+ - Fix error when input empty data in Gruff::BoxPlot (#594)
10
+ - Fix error when input empty data in Gruff::Spider (#593)
11
+ - Fix error when input empty data in Gruff::Histogram (#592)
12
+ - Fix error when input empty data in Gruff::Area (#591)
13
+ - Stop adjusting the square radius in Gruff::Line (#589)
14
+ - Add diamond dot stype in Gruff::Line (#588)
15
+ - Allow title to be set as an array (#587)
16
+ - Allow labels to be set as an array corresponding to the data values (#586)
17
+ - Fixed a bug that breaks the colors in the theme when using the add_color method (#583)
18
+ - Ensure to raise an exception if use sort feature in Candlestick
19
+ - Fix column_count in BoxPlot/Candlestick (#581)
20
+ - Fix left/right graph margin (#579)
21
+
3
22
  ## 0.16.0
4
23
  - Add Candlestick (#575)
5
24
  - Add BoxPlot (#574)
data/gruff.gemspec CHANGED
@@ -16,7 +16,6 @@ Gem::Specification.new do |s|
16
16
  s.require_paths = %w[lib]
17
17
  s.summary = 'Beautiful graphs for one or multiple datasets.'
18
18
  s.license = 'MIT'
19
- s.test_files = s.files.grep(%r{^(test|spec|features)/})
20
19
  s.executables = s.files.grep(%r{^bin/}).map { |f| File.basename(f) }
21
20
  s.specification_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
22
21
 
@@ -25,7 +24,7 @@ Gem::Specification.new do |s|
25
24
  s.add_dependency 'rmagick4j'
26
25
  else
27
26
  s.add_dependency 'rmagick', '>= 4.2'
28
- s.add_development_dependency 'rubocop', '~> 1.27.0'
27
+ s.add_development_dependency 'rubocop', '~> 1.28.2'
29
28
  s.add_development_dependency 'rubocop-performance', '~> 1.13.3'
30
29
  s.add_development_dependency 'rubocop-rake', '~> 0.6.0'
31
30
  end
@@ -35,7 +34,7 @@ Gem::Specification.new do |s|
35
34
  s.add_development_dependency 'rake'
36
35
  s.add_development_dependency 'minitest-reporters'
37
36
  s.add_development_dependency 'simplecov'
38
- s.add_development_dependency 'yard', '~> 0.9.25'
37
+ s.add_development_dependency 'yard', '~> 0.9.28'
39
38
 
40
39
  s.metadata['rubygems_mfa_required'] = 'true'
41
40
  end
data/lib/gruff/area.rb CHANGED
@@ -33,6 +33,8 @@ private
33
33
  x_increment = @graph_width / (column_count - 1)
34
34
 
35
35
  store.norm_data.each do |data_row|
36
+ next if data_row.points.empty?
37
+
36
38
  poly_points = []
37
39
 
38
40
  data_row.points.each_with_index do |data_point, index|
data/lib/gruff/bar.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'helper/bar_mixin'
4
+
3
5
  #
4
6
  # Gruff::Bar provide a bar graph that presents categorical data
5
7
  # with rectangular bars.
@@ -16,6 +18,8 @@
16
18
  # g.write('bar.png')
17
19
  #
18
20
  class Gruff::Bar < Gruff::Base
21
+ include BarMixin
22
+
19
23
  # Spacing factor applied between bars.
20
24
  attr_writer :bar_spacing
21
25
 
@@ -86,8 +90,6 @@ private
86
90
  return if @hide_line_markers
87
91
 
88
92
  if @show_labels_for_bar_values
89
- proc_text_metrics = ->(text) { text_metrics(@marker_font, text) }
90
-
91
93
  if maximum_value >= 0
92
94
  _, metrics = Gruff::BarValueLabel.metrics(maximum_value, @label_formatting, proc_text_metrics)
93
95
  @graph_top += metrics.height
@@ -112,36 +114,33 @@ private
112
114
  minimum_value: minimum_value, maximum_value: maximum_value, spread: @spread
113
115
  )
114
116
 
115
- proc_text_metrics = ->(text) { text_metrics(@marker_font, text) }
117
+ group_spacing = @group_spacing * @scale
118
+ group_left_x = @graph_left
116
119
 
117
- # iterate over all normalised data
118
- store.norm_data.each_with_index do |data_row, row_index|
119
- data_row.points.each_with_index do |data_point, point_index|
120
- group_spacing = @group_spacing * @scale * point_index
121
-
122
- # Use incremented x and scaled y
123
- # x
124
- left_x = @graph_left + (bar_width * (row_index + point_index + ((store.length - 1) * point_index))) + padding + group_spacing
120
+ normalized_group_bars.each_with_index do |group_bars, group_index|
121
+ right_x = 0
122
+ group_bars.each_with_index do |bar, index|
123
+ left_x = group_left_x + (bar_width * index) + padding
125
124
  right_x = left_x + (bar_width * @bar_spacing)
126
- # y
127
- left_y, right_y = conversion.get_top_bottom_scaled(data_point)
128
-
129
- # create new bar
130
- rect_renderer = Gruff::Renderer::Rectangle.new(renderer, color: data_row.color)
131
- rect_renderer.render(left_x, left_y - AXIS_MARGIN, right_x, right_y - AXIS_MARGIN)
132
125
 
133
- # Calculate center based on bar_width and current row
134
- label_center = @graph_left + group_spacing + (store.length * bar_width * point_index) + (store.length * bar_width / 2.0)
126
+ top_y, bottom_y = conversion.get_top_bottom_scaled(bar.point)
127
+ if bar.point != 0
128
+ rect_renderer = Gruff::Renderer::Rectangle.new(renderer, color: bar.color)
129
+ rect_renderer.render(left_x, bottom_y - AXIS_MARGIN, right_x, top_y)
130
+ end
135
131
 
136
- # Subtract half a bar width to center left if requested
137
- draw_label(label_center, point_index)
138
- if @show_labels_for_bar_values
139
- bar_value_label = Gruff::BarValueLabel::Bar.new([left_x, left_y, right_x, right_y], store.data[row_index].points[point_index])
132
+ if @show_labels_for_bar_values && bar.value
133
+ bar_value_label = Gruff::BarValueLabel::Bar.new([left_x, top_y, right_x, bottom_y], bar.value)
140
134
  bar_value_label.prepare_rendering(@label_formatting, proc_text_metrics) do |x, y, text, _text_width, text_height|
141
135
  draw_value_label(bar_width * @bar_spacing, text_height, x, y, text)
142
136
  end
143
137
  end
144
138
  end
139
+
140
+ label_center = group_left_x + ((right_x - group_left_x) / 2.0)
141
+ draw_label(label_center, group_index)
142
+
143
+ group_left_x = right_x + padding + group_spacing
145
144
  end
146
145
 
147
146
  # Draw the last label if requested
@@ -151,4 +150,8 @@ private
151
150
  def calculate_spacing
152
151
  @scale * @group_spacing * (column_count - 1)
153
152
  end
153
+
154
+ def proc_text_metrics
155
+ ->(text) { text_metrics(@marker_font, text) }
156
+ end
154
157
  end