gruff 0.14.0-java → 0.17.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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +28 -12
- data/.gitignore +1 -0
- data/.rubocop.yml +20 -24
- data/CHANGELOG.md +52 -0
- data/README.md +10 -3
- data/gruff.gemspec +9 -10
- data/lib/gruff/accumulator_bar.rb +1 -1
- data/lib/gruff/area.rb +6 -4
- data/lib/gruff/bar.rb +53 -31
- data/lib/gruff/base.rb +292 -184
- data/lib/gruff/bezier.rb +4 -2
- data/lib/gruff/box_plot.rb +180 -0
- data/lib/gruff/bullet.rb +6 -6
- data/lib/gruff/candlestick.rb +120 -0
- data/lib/gruff/dot.rb +11 -12
- data/lib/gruff/font.rb +3 -0
- data/lib/gruff/helper/bar_conversion.rb +6 -10
- data/lib/gruff/helper/bar_mixin.rb +25 -0
- data/lib/gruff/helper/bar_value_label.rb +24 -40
- data/lib/gruff/helper/stacked_mixin.rb +19 -1
- data/lib/gruff/histogram.rb +9 -5
- data/lib/gruff/line.rb +49 -48
- data/lib/gruff/mini/legend.rb +11 -11
- data/lib/gruff/net.rb +23 -18
- data/lib/gruff/patch/rmagick.rb +0 -1
- data/lib/gruff/patch/string.rb +1 -0
- data/lib/gruff/pie.rb +26 -12
- data/lib/gruff/renderer/dash_line.rb +3 -2
- data/lib/gruff/renderer/dot.rb +28 -15
- data/lib/gruff/renderer/line.rb +1 -3
- data/lib/gruff/renderer/rectangle.rb +6 -2
- data/lib/gruff/renderer/renderer.rb +4 -8
- data/lib/gruff/renderer/text.rb +7 -1
- data/lib/gruff/scatter.rb +64 -56
- data/lib/gruff/side_bar.rb +64 -30
- data/lib/gruff/side_stacked_bar.rb +43 -54
- data/lib/gruff/spider.rb +52 -18
- data/lib/gruff/stacked_area.rb +18 -8
- data/lib/gruff/stacked_bar.rb +59 -29
- data/lib/gruff/store/xy_data.rb +2 -0
- data/lib/gruff/version.rb +1 -1
- data/lib/gruff.rb +67 -58
- metadata +17 -16
- data/.rubocop_todo.yml +0 -116
- data/lib/gruff/scene.rb +0 -200
- data/lib/gruff/store/custom_data.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bee4569b7c7780fa68a3ae0273b921bf4e374ec207cd6381cd7feeb0ae8fd22
|
4
|
+
data.tar.gz: 3ceff033fcb2543ea8852fb11c4d56a5a1cf7dbd9dbf1bb62974602edd11b974
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4e5834e0d3efa6bf619591f009d4e63d22c26e0e3223bdb7861662a89ae2985f62d98141584d3c493fc29ad13af8597bb36466a5df956ae2feb159c4179ca6b
|
7
|
+
data.tar.gz: 80599d2b8eb034218d9af18fbc7f7c01ba2c66d7b17a16de36a9417171376c6fadf794e69011b34ec777c249604d1cfb48087eee97f3e6cdb1c0f84ad51bc22c
|
data/.github/workflows/ci.yml
CHANGED
@@ -6,55 +6,71 @@ on:
|
|
6
6
|
pull_request:
|
7
7
|
branches: [ master ]
|
8
8
|
|
9
|
+
permissions:
|
10
|
+
contents: read
|
11
|
+
|
9
12
|
jobs:
|
10
13
|
lint:
|
11
|
-
runs-on: ubuntu-
|
14
|
+
runs-on: ubuntu-20.04
|
12
15
|
timeout-minutes: 20
|
13
16
|
name: Lint
|
14
17
|
steps:
|
15
|
-
- uses: actions/checkout@
|
18
|
+
- uses: actions/checkout@v3
|
16
19
|
with:
|
17
20
|
ref: ${{ github.event.pull_request.head.sha }}
|
18
|
-
- name: Set up Ruby 2.
|
21
|
+
- name: Set up Ruby 2.5
|
19
22
|
uses: ruby/setup-ruby@master
|
20
23
|
with:
|
21
|
-
ruby-version: '2.
|
24
|
+
ruby-version: '2.5'
|
22
25
|
bundler-cache: true
|
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
|
29
|
+
uses: r7kamura/rubocop-problem-matchers-action@v1
|
27
30
|
- name: Run tests
|
28
31
|
run: bundle exec rubocop
|
29
32
|
|
30
33
|
test-ruby:
|
31
|
-
runs-on: ubuntu-
|
34
|
+
runs-on: ubuntu-20.04
|
32
35
|
timeout-minutes: 20
|
33
36
|
strategy:
|
34
37
|
matrix:
|
35
|
-
ruby-version: ['2.
|
38
|
+
ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1']
|
39
|
+
imagemagick-version:
|
40
|
+
- { full: 7.1.0-35, major-minor: '7.0' }
|
36
41
|
name: Ruby ${{ matrix.ruby-version }}
|
37
42
|
steps:
|
38
|
-
- uses: actions/checkout@
|
43
|
+
- uses: actions/checkout@v3
|
44
|
+
- name: Cache ImageMagick
|
45
|
+
uses: actions/cache@v3
|
46
|
+
with:
|
47
|
+
path: ./build-ImageMagick
|
48
|
+
key: v1-linux-imagemagick-${{ matrix.imagemagick-version.full }}
|
49
|
+
restore-keys: |
|
50
|
+
v1-linux-imagemagick-${{ matrix.imagemagick-version.full }}
|
51
|
+
- name: Install ImageMagick ${{ matrix.imagemagick-version.full }}
|
52
|
+
run: |
|
53
|
+
export IMAGEMAGICK_VERSION=${{ matrix.imagemagick-version.full }}
|
54
|
+
./before_install_linux.sh
|
39
55
|
- name: Set up Ruby
|
40
56
|
uses: ruby/setup-ruby@master
|
41
57
|
with:
|
42
58
|
ruby-version: ${{ matrix.ruby-version }}
|
43
|
-
bundler-cache:
|
59
|
+
bundler-cache: false
|
44
60
|
- name: Install dependencies
|
45
61
|
run: bundle install --path=vendor/bundle --jobs 4 --retry 3
|
46
62
|
- name: Run tests
|
47
63
|
run: bundle exec rake
|
48
64
|
|
49
65
|
test-jruby:
|
50
|
-
runs-on: ubuntu-
|
66
|
+
runs-on: ubuntu-20.04
|
51
67
|
timeout-minutes: 20
|
52
68
|
strategy:
|
53
69
|
matrix:
|
54
|
-
ruby-version: ['9.2.
|
70
|
+
ruby-version: ['9.2.20.1', '9.3.4.0']
|
55
71
|
name: JRuby ${{ matrix.ruby-version }}
|
56
72
|
steps:
|
57
|
-
- uses: actions/checkout@
|
73
|
+
- uses: actions/checkout@v3
|
58
74
|
- name: Set up Ruby
|
59
75
|
uses: ruby/setup-ruby@master
|
60
76
|
with:
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
-
inherit_from: .rubocop_todo.yml
|
2
1
|
require:
|
3
2
|
- rubocop-performance
|
4
3
|
- rubocop-rake
|
5
4
|
|
6
5
|
AllCops:
|
7
6
|
EnabledByDefault: true
|
8
|
-
TargetRubyVersion: 2.
|
7
|
+
TargetRubyVersion: 2.5
|
9
8
|
Exclude:
|
10
9
|
- 'vendor/bundle/**/*'
|
11
10
|
- 'rails_generators/gruff/**/*'
|
12
11
|
|
12
|
+
Metrics:
|
13
|
+
Enabled: false
|
14
|
+
|
13
15
|
Gemspec/OrderedDependencies:
|
14
16
|
Enabled: false
|
15
17
|
|
@@ -19,9 +21,6 @@ Gemspec/RequiredRubyVersion:
|
|
19
21
|
Layout/AccessModifierIndentation:
|
20
22
|
EnforcedStyle: outdent
|
21
23
|
|
22
|
-
Layout/ClassStructure:
|
23
|
-
Enabled: false
|
24
|
-
|
25
24
|
Layout/FirstMethodArgumentLineBreak:
|
26
25
|
Enabled: false
|
27
26
|
|
@@ -34,25 +33,31 @@ Layout/MultilineMethodArgumentLineBreaks:
|
|
34
33
|
Layout/MultilineAssignmentLayout:
|
35
34
|
EnforcedStyle: same_line
|
36
35
|
|
37
|
-
|
36
|
+
Layout/RedundantLineBreak:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
Layout/SingleLineBlockChain:
|
38
40
|
Enabled: false
|
39
41
|
|
40
42
|
Lint/ConstantResolution:
|
41
43
|
Enabled: false
|
42
44
|
|
45
|
+
Lint/FloatComparison:
|
46
|
+
Enabled: false
|
47
|
+
|
43
48
|
Lint/NumberConversion:
|
44
49
|
Enabled: false
|
45
50
|
|
46
51
|
Naming/MethodParameterName:
|
47
52
|
Enabled: false
|
48
53
|
|
49
|
-
|
54
|
+
Naming/VariableNumber:
|
50
55
|
Enabled: false
|
51
56
|
|
52
|
-
Style/
|
57
|
+
Style/AccessorGrouping:
|
53
58
|
Enabled: false
|
54
59
|
|
55
|
-
Style/
|
60
|
+
Style/ClassAndModuleChildren:
|
56
61
|
Enabled: false
|
57
62
|
|
58
63
|
Style/ConstantVisibility:
|
@@ -64,12 +69,15 @@ Style/Copyright:
|
|
64
69
|
Style/Documentation:
|
65
70
|
Enabled: true
|
66
71
|
|
67
|
-
Style/
|
68
|
-
|
72
|
+
Style/DocumentationMethod:
|
73
|
+
Enabled: false
|
69
74
|
|
70
|
-
Style/
|
75
|
+
Style/DocumentDynamicEvalDefinition:
|
71
76
|
Enabled: false
|
72
77
|
|
78
|
+
Style/FormatString:
|
79
|
+
EnforcedStyle: sprintf
|
80
|
+
|
73
81
|
Style/GuardClause:
|
74
82
|
Enabled: false
|
75
83
|
|
@@ -94,9 +102,6 @@ Style/MissingElse:
|
|
94
102
|
Style/Next:
|
95
103
|
Enabled: false
|
96
104
|
|
97
|
-
Style/NumericLiterals:
|
98
|
-
Enabled: false
|
99
|
-
|
100
105
|
Style/NumericPredicate:
|
101
106
|
Enabled: false
|
102
107
|
|
@@ -109,17 +114,8 @@ Style/RedundantBegin:
|
|
109
114
|
Style/SingleLineBlockParams:
|
110
115
|
Enabled: false
|
111
116
|
|
112
|
-
Style/SpecialGlobalVars:
|
113
|
-
Enabled: false
|
114
|
-
|
115
117
|
Style/StructInheritance:
|
116
118
|
Enabled: false
|
117
119
|
|
118
|
-
Style/SymbolArray:
|
119
|
-
Enabled: false
|
120
|
-
|
121
|
-
Style/TernaryParentheses:
|
122
|
-
Enabled: false
|
123
|
-
|
124
120
|
Performance/ChainArrayAllocation:
|
125
121
|
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,57 @@
|
|
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
|
+
|
22
|
+
## 0.16.0
|
23
|
+
- Add Candlestick (#575)
|
24
|
+
- Add BoxPlot (#574)
|
25
|
+
- Raise exception if less data set was given in Gruff::Spider (#573)
|
26
|
+
- Adjust default label offset value in Gruff::Pie
|
27
|
+
- Remove has_left_labels from attribute (#571)
|
28
|
+
- Remove center_labels_over_point from attribute (#570)
|
29
|
+
- Adjust legend label / box position
|
30
|
+
- Fix right margin when truncate the label
|
31
|
+
- Adjust axis label position
|
32
|
+
- Adjust left label margin
|
33
|
+
- Fix axis label position with hide_line_markers
|
34
|
+
- Fix margin of value label in Bar/StackedBar (#568)
|
35
|
+
- Fix label position in Gruff::Spider (#567)
|
36
|
+
- Fix axis label position with legend_at_bottom
|
37
|
+
- Fix axis label position with hide_line_markers
|
38
|
+
- Refactor: Remove instance variable usage
|
39
|
+
- Remove Gruff::Scene (#566)
|
40
|
+
- Fix exception with zero value in StackBar (#565)
|
41
|
+
- Fix segment spacing in SideStackedBar (#564)
|
42
|
+
- Fix margin of value label in SideBar/SideStackedBar (#563)
|
43
|
+
- Raise exception if negative values were given in stacked graph (#562)
|
44
|
+
- Fix centering in value label position (#561)
|
45
|
+
- Fix duck typing support in Gruff::Histogram (#560)
|
46
|
+
- Fix start drawing position to top in Pie and enabled sort option by default (#559)
|
47
|
+
|
48
|
+
## 0.15.0
|
49
|
+
- Fix SideStackedBar which bars overlap on the coordinate axes if data contains 0 (#558)
|
50
|
+
- Lazy loading library to reduce memory usage (#556)
|
51
|
+
- Drop Ruby 2.4 support (#554)
|
52
|
+
- Fix sort drawing in Gruff::Line (#553)
|
53
|
+
- Fix color value handling in Line#dataxy method (#552)
|
54
|
+
|
3
55
|
## 0.14.0
|
4
56
|
- Update rails template (#547)
|
5
57
|
- Remove singleton in order to support multi-thread processing (#546)
|
data/README.md
CHANGED
@@ -126,6 +126,13 @@ In progress!
|
|
126
126
|
|
127
127
|

|
128
128
|
|
129
|
+
### Box plot
|
130
|
+
|
131
|
+

|
132
|
+
|
133
|
+
### Candlestick
|
134
|
+
|
135
|
+

|
129
136
|
|
130
137
|
## Documentation
|
131
138
|
|
@@ -133,7 +140,7 @@ http://www.rubydoc.info/github/topfunky/gruff/frames
|
|
133
140
|
|
134
141
|
## Supported Ruby Versions
|
135
142
|
|
136
|
-
- Ruby 2.
|
143
|
+
- Ruby 2.5 or later
|
137
144
|
- JRuby 9.2.x or later
|
138
145
|
|
139
146
|
## Development
|
@@ -149,13 +156,13 @@ $ ./docker-launch.sh
|
|
149
156
|
|
150
157
|
3. Run tests
|
151
158
|
```sh
|
152
|
-
$ rake
|
159
|
+
$ bundle exec rake
|
153
160
|
```
|
154
161
|
|
155
162
|
If you have made changes that involve updating the expected image, you need to update the image with the following command after running tests.
|
156
163
|
|
157
164
|
```sh
|
158
|
-
$ rake test:image:update
|
165
|
+
$ bundle exec rake test:image:update
|
159
166
|
```
|
160
167
|
|
161
168
|
## Contributing
|
data/gruff.gemspec
CHANGED
@@ -11,14 +11,11 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.authors = ['Geoffrey Grosenbach', 'Uwe Kubosch']
|
12
12
|
s.description = 'Beautiful graphs for one or multiple datasets. Can be used on websites or in documents.'
|
13
13
|
s.email = 'boss@topfunky.com'
|
14
|
-
s.files = `git ls-files`.split.
|
15
|
-
f =~ /^test|^docker|^Rakefile/i
|
16
|
-
end
|
14
|
+
s.files = `git ls-files`.split.grep_v(/^test|^docker|^before_install_linux.sh|^Rakefile/i)
|
17
15
|
s.homepage = 'https://github.com/topfunky/gruff'
|
18
16
|
s.require_paths = %w[lib]
|
19
17
|
s.summary = 'Beautiful graphs for one or multiple datasets.'
|
20
18
|
s.license = 'MIT'
|
21
|
-
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
22
19
|
s.executables = s.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
23
20
|
s.specification_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
21
|
|
@@ -26,16 +23,18 @@ Gem::Specification.new do |s|
|
|
26
23
|
s.platform = 'java'
|
27
24
|
s.add_dependency 'rmagick4j'
|
28
25
|
else
|
29
|
-
s.add_dependency 'rmagick'
|
30
|
-
s.add_development_dependency 'rubocop', '~> 1.
|
31
|
-
s.add_development_dependency 'rubocop-performance', '~> 1.
|
32
|
-
s.add_development_dependency 'rubocop-rake', '~> 0.
|
26
|
+
s.add_dependency 'rmagick', '>= 4.2'
|
27
|
+
s.add_development_dependency 'rubocop', '~> 1.28.2'
|
28
|
+
s.add_development_dependency 'rubocop-performance', '~> 1.13.3'
|
29
|
+
s.add_development_dependency 'rubocop-rake', '~> 0.6.0'
|
33
30
|
end
|
34
31
|
s.add_dependency 'histogram'
|
35
|
-
s.required_ruby_version = '>= 2.
|
32
|
+
s.required_ruby_version = '>= 2.5.0'
|
36
33
|
|
37
34
|
s.add_development_dependency 'rake'
|
38
35
|
s.add_development_dependency 'minitest-reporters'
|
39
36
|
s.add_development_dependency 'simplecov'
|
40
|
-
s.add_development_dependency 'yard', '~> 0.9.
|
37
|
+
s.add_development_dependency 'yard', '~> 0.9.28'
|
38
|
+
|
39
|
+
s.metadata['rubygems_mfa_required'] = 'true'
|
41
40
|
end
|
@@ -19,7 +19,7 @@ private
|
|
19
19
|
def setup_data
|
20
20
|
raise(Gruff::IncorrectNumberOfDatasetsException) unless store.length == 1
|
21
21
|
|
22
|
-
accum_array = store.data.first.points[0..-2].reduce([0]) { |a, v| a << a.last + v }
|
22
|
+
accum_array = store.data.first.points[0..-2].reduce([0]) { |a, v| a << (a.last + v) }
|
23
23
|
data 'Accumulator', accum_array
|
24
24
|
set_colors
|
25
25
|
store.reverse!
|
data/lib/gruff/area.rb
CHANGED
@@ -30,15 +30,17 @@ private
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def draw_graph
|
33
|
-
x_increment = @graph_width / (column_count - 1)
|
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|
|
39
41
|
# Use incremented x and scaled y
|
40
42
|
new_x = @graph_left + (x_increment * index)
|
41
|
-
new_y = @graph_top + (@graph_height - data_point * @graph_height)
|
43
|
+
new_y = @graph_top + (@graph_height - (data_point * @graph_height))
|
42
44
|
|
43
45
|
poly_points << new_x
|
44
46
|
poly_points << new_y
|
@@ -48,9 +50,9 @@ private
|
|
48
50
|
|
49
51
|
# Add closing points, draw polygon
|
50
52
|
poly_points << @graph_right
|
51
|
-
poly_points << @graph_bottom - 1
|
53
|
+
poly_points << (@graph_bottom - 1)
|
52
54
|
poly_points << @graph_left
|
53
|
-
poly_points << @graph_bottom - 1
|
55
|
+
poly_points << (@graph_bottom - 1)
|
54
56
|
|
55
57
|
Gruff::Renderer::Polygon.new(renderer, color: data_row.color, width: @stroke_width, opacity: @fill_opacity).render(poly_points)
|
56
58
|
end
|
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
|
|
@@ -33,6 +37,10 @@ class Gruff::Bar < Gruff::Base
|
|
33
37
|
# Prevent drawing of column labels below a bar graph. Default is +false+.
|
34
38
|
attr_writer :hide_labels
|
35
39
|
|
40
|
+
# Value to avoid completely overwriting the coordinate axis
|
41
|
+
AXIS_MARGIN = 0.5
|
42
|
+
private_constant :AXIS_MARGIN
|
43
|
+
|
36
44
|
# Can be used to adjust the spaces between the bars.
|
37
45
|
# Accepts values between 0.00 and 1.00 where 0.00 means no spacing at all
|
38
46
|
# and 1 means that each bars' width is nearly 0 (so each bar is a simple
|
@@ -70,15 +78,26 @@ private
|
|
70
78
|
end
|
71
79
|
|
72
80
|
def hide_left_label_area?
|
73
|
-
@hide_line_markers
|
81
|
+
@hide_line_markers && @y_axis_label.nil?
|
74
82
|
end
|
75
83
|
|
76
84
|
def hide_bottom_label_area?
|
77
|
-
hide_labels?
|
85
|
+
hide_labels? && @x_axis_label.nil? && @legend_at_bottom == false
|
78
86
|
end
|
79
87
|
|
80
|
-
|
81
|
-
|
88
|
+
def setup_graph_measurements
|
89
|
+
super
|
90
|
+
return if @hide_line_markers
|
91
|
+
|
92
|
+
if @show_labels_for_bar_values
|
93
|
+
if maximum_value >= 0
|
94
|
+
_, metrics = Gruff::BarValueLabel.metrics(maximum_value, @label_formatting, proc_text_metrics)
|
95
|
+
@graph_top += metrics.height
|
96
|
+
end
|
97
|
+
|
98
|
+
@graph_height = @graph_bottom - @graph_top
|
99
|
+
end
|
100
|
+
end
|
82
101
|
|
83
102
|
def draw_graph
|
84
103
|
# Setup spacing.
|
@@ -86,8 +105,8 @@ private
|
|
86
105
|
# Columns sit side-by-side.
|
87
106
|
@bar_spacing ||= @spacing_factor # space between the bars
|
88
107
|
|
89
|
-
bar_width = (@graph_width - calculate_spacing) / (column_count * store.length)
|
90
|
-
padding = (bar_width * (1 - @bar_spacing)) / 2
|
108
|
+
bar_width = (@graph_width - calculate_spacing) / (column_count * store.length)
|
109
|
+
padding = (bar_width * (1 - @bar_spacing)) / 2.0
|
91
110
|
|
92
111
|
# Setup the BarConversion Object
|
93
112
|
conversion = Gruff::BarConversion.new(
|
@@ -95,34 +114,33 @@ private
|
|
95
114
|
minimum_value: minimum_value, maximum_value: maximum_value, spread: @spread
|
96
115
|
)
|
97
116
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
# Subtract half a bar width to center left if requested
|
118
|
-
draw_label(label_center, point_index)
|
119
|
-
if @show_labels_for_bar_values
|
120
|
-
bar_value_label = Gruff::BarValueLabel::Bar.new([left_x, left_y, right_x, right_y], store.data[row_index].points[point_index])
|
121
|
-
bar_value_label.prepare_rendering(@label_formatting, bar_width) do |x, y, text|
|
122
|
-
draw_value_label(x, y, text)
|
117
|
+
group_spacing = @group_spacing * @scale
|
118
|
+
group_left_x = @graph_left
|
119
|
+
|
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
|
124
|
+
right_x = left_x + (bar_width * @bar_spacing)
|
125
|
+
|
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
|
131
|
+
|
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)
|
134
|
+
bar_value_label.prepare_rendering(@label_formatting, proc_text_metrics) do |x, y, text, _text_width, text_height|
|
135
|
+
draw_value_label(bar_width * @bar_spacing, text_height, x, y, text)
|
123
136
|
end
|
124
137
|
end
|
125
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
|
126
144
|
end
|
127
145
|
|
128
146
|
# Draw the last label if requested
|
@@ -132,4 +150,8 @@ private
|
|
132
150
|
def calculate_spacing
|
133
151
|
@scale * @group_spacing * (column_count - 1)
|
134
152
|
end
|
153
|
+
|
154
|
+
def proc_text_metrics
|
155
|
+
->(text) { text_metrics(@marker_font, text) }
|
156
|
+
end
|
135
157
|
end
|