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 +4 -4
- data/.github/workflows/ci.yml +5 -2
- data/.gitignore +1 -0
- data/.rubocop.yml +0 -6
- data/CHANGELOG.md +19 -0
- data/gruff.gemspec +2 -3
- data/lib/gruff/area.rb +2 -0
- data/lib/gruff/bar.rb +26 -23
- data/lib/gruff/base.rb +198 -81
- data/lib/gruff/bezier.rb +2 -0
- data/lib/gruff/box_plot.rb +7 -1
- data/lib/gruff/candlestick.rb +21 -13
- data/lib/gruff/dot.rb +4 -5
- data/lib/gruff/helper/bar_conversion.rb +1 -5
- data/lib/gruff/helper/bar_mixin.rb +25 -0
- data/lib/gruff/helper/bar_value_label.rb +0 -22
- data/lib/gruff/helper/stacked_mixin.rb +16 -0
- data/lib/gruff/histogram.rb +8 -4
- data/lib/gruff/line.rb +2 -5
- data/lib/gruff/mini/legend.rb +9 -9
- data/lib/gruff/net.rb +16 -11
- data/lib/gruff/pie.rb +6 -1
- data/lib/gruff/renderer/dot.rb +25 -14
- data/lib/gruff/renderer/renderer.rb +0 -4
- data/lib/gruff/renderer/text.rb +7 -1
- data/lib/gruff/scatter.rb +20 -18
- data/lib/gruff/side_bar.rb +28 -23
- data/lib/gruff/side_stacked_bar.rb +36 -41
- data/lib/gruff/spider.rb +7 -2
- data/lib/gruff/stacked_area.rb +7 -2
- data/lib/gruff/stacked_bar.rb +46 -38
- data/lib/gruff/version.rb +1 -1
- data/lib/gruff.rb +0 -3
- metadata +10 -9
data/lib/gruff/stacked_bar.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'helper/stacked_mixin'
|
4
|
+
|
3
5
|
#
|
4
6
|
# Here's how to set up a Gruff::StackedBar.
|
5
7
|
#
|
@@ -42,6 +44,15 @@ private
|
|
42
44
|
@minimum_value = 0.0
|
43
45
|
end
|
44
46
|
|
47
|
+
def setup_drawing
|
48
|
+
# Labels will be centered over the left of the bar if
|
49
|
+
# there are more labels than columns. This is basically the same
|
50
|
+
# as where it would be for a line graph.
|
51
|
+
@center_labels_over_point = (@labels.keys.length > column_count)
|
52
|
+
|
53
|
+
super
|
54
|
+
end
|
55
|
+
|
45
56
|
def setup_data
|
46
57
|
calculate_maximum_by_stack
|
47
58
|
super
|
@@ -52,8 +63,6 @@ private
|
|
52
63
|
return if @hide_line_markers
|
53
64
|
|
54
65
|
if @show_labels_for_bar_values
|
55
|
-
proc_text_metrics = ->(text) { text_metrics(@marker_font, text) }
|
56
|
-
|
57
66
|
if maximum_value >= 0
|
58
67
|
_, metrics = Gruff::BarValueLabel.metrics(maximum_value, @label_formatting, proc_text_metrics)
|
59
68
|
@graph_top += metrics.height
|
@@ -71,44 +80,39 @@ private
|
|
71
80
|
bar_width = @graph_width / column_count
|
72
81
|
padding = (bar_width * (1 - @bar_spacing)) / 2
|
73
82
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
rect_renderer.render(left_x, left_y, right_x, right_y)
|
98
|
-
|
99
|
-
# Calculate center based on bar_width and current row
|
100
|
-
label_center = left_x + (bar_width * @bar_spacing / 2.0)
|
101
|
-
draw_label(label_center, point_index)
|
102
|
-
|
103
|
-
bar_value_label = Gruff::BarValueLabel::Bar.new([left_x, left_y, right_x, right_y], store.data[row_index].points[point_index])
|
104
|
-
stack_bar_value_labels.add(bar_value_label, point_index)
|
83
|
+
# Setup the BarConversion Object
|
84
|
+
conversion = Gruff::BarConversion.new(
|
85
|
+
top: @graph_top, bottom: @graph_bottom,
|
86
|
+
minimum_value: minimum_value, maximum_value: maximum_value, spread: @spread
|
87
|
+
)
|
88
|
+
|
89
|
+
normalized_stacked_bars.each_with_index do |stacked_bars, stacked_index|
|
90
|
+
total = 0
|
91
|
+
left_x = @graph_left + (bar_width * stacked_index) + padding
|
92
|
+
right_x = left_x + (bar_width * @bar_spacing)
|
93
|
+
|
94
|
+
top_y = 0
|
95
|
+
stacked_bars.each do |bar|
|
96
|
+
next if bar.point == 0
|
97
|
+
|
98
|
+
bottom_y, = conversion.get_top_bottom_scaled(total)
|
99
|
+
bottom_y -= @segment_spacing
|
100
|
+
top_y, = conversion.get_top_bottom_scaled(total + bar.point)
|
101
|
+
|
102
|
+
rect_renderer = Gruff::Renderer::Rectangle.new(renderer, color: bar.color)
|
103
|
+
rect_renderer.render(left_x, bottom_y, right_x, top_y)
|
104
|
+
|
105
|
+
total += bar.point
|
105
106
|
end
|
106
|
-
end
|
107
107
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
108
|
+
label_center = left_x + (bar_width * @bar_spacing / 2.0)
|
109
|
+
draw_label(label_center, stacked_index)
|
110
|
+
|
111
|
+
if @show_labels_for_bar_values
|
112
|
+
bar_value_label = Gruff::BarValueLabel::Bar.new([left_x, top_y, right_x, @graph_bottom], stacked_bars.sum(&:value))
|
113
|
+
bar_value_label.prepare_rendering(@label_formatting, proc_text_metrics) do |x, y, text, _text_width, text_height|
|
114
|
+
draw_value_label(bar_width * @bar_spacing, text_height, x, y, text)
|
115
|
+
end
|
112
116
|
end
|
113
117
|
end
|
114
118
|
end
|
@@ -124,4 +128,8 @@ private
|
|
124
128
|
def hide_bottom_label_area?
|
125
129
|
hide_labels? && @x_axis_label.nil? && @legend_at_bottom == false
|
126
130
|
end
|
131
|
+
|
132
|
+
def proc_text_metrics
|
133
|
+
->(text) { text_metrics(@marker_font, text) }
|
134
|
+
end
|
127
135
|
end
|
data/lib/gruff/version.rb
CHANGED
data/lib/gruff.rb
CHANGED
@@ -21,9 +21,6 @@ module Gruff
|
|
21
21
|
|
22
22
|
autoload :BarConversion, Gruff.libpath('helper/bar_conversion')
|
23
23
|
autoload :BarValueLabel, Gruff.libpath('helper/bar_value_label')
|
24
|
-
class Base
|
25
|
-
autoload :StackedMixin, Gruff.libpath('helper/stacked_mixin')
|
26
|
-
end
|
27
24
|
|
28
25
|
autoload :AccumulatorBar, Gruff.libpath('accumulator_bar')
|
29
26
|
autoload :Area, Gruff.libpath('area')
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gruff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geoffrey Grosenbach
|
8
8
|
- Uwe Kubosch
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-06-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rmagick
|
@@ -31,14 +31,14 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 1.
|
34
|
+
version: 1.28.2
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: 1.
|
41
|
+
version: 1.28.2
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rubocop-performance
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,14 +129,14 @@ dependencies:
|
|
129
129
|
requirements:
|
130
130
|
- - "~>"
|
131
131
|
- !ruby/object:Gem::Version
|
132
|
-
version: 0.9.
|
132
|
+
version: 0.9.28
|
133
133
|
type: :development
|
134
134
|
prerelease: false
|
135
135
|
version_requirements: !ruby/object:Gem::Requirement
|
136
136
|
requirements:
|
137
137
|
- - "~>"
|
138
138
|
- !ruby/object:Gem::Version
|
139
|
-
version: 0.9.
|
139
|
+
version: 0.9.28
|
140
140
|
description: Beautiful graphs for one or multiple datasets. Can be used on websites
|
141
141
|
or in documents.
|
142
142
|
email: boss@topfunky.com
|
@@ -171,6 +171,7 @@ files:
|
|
171
171
|
- lib/gruff/dot.rb
|
172
172
|
- lib/gruff/font.rb
|
173
173
|
- lib/gruff/helper/bar_conversion.rb
|
174
|
+
- lib/gruff/helper/bar_mixin.rb
|
174
175
|
- lib/gruff/helper/bar_value_label.rb
|
175
176
|
- lib/gruff/helper/stacked_mixin.rb
|
176
177
|
- lib/gruff/histogram.rb
|
@@ -213,7 +214,7 @@ licenses:
|
|
213
214
|
- MIT
|
214
215
|
metadata:
|
215
216
|
rubygems_mfa_required: 'true'
|
216
|
-
post_install_message:
|
217
|
+
post_install_message:
|
217
218
|
rdoc_options: []
|
218
219
|
require_paths:
|
219
220
|
- lib
|
@@ -229,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
229
230
|
version: '0'
|
230
231
|
requirements: []
|
231
232
|
rubygems_version: 3.3.7
|
232
|
-
signing_key:
|
233
|
+
signing_key:
|
233
234
|
specification_version: 4
|
234
235
|
summary: Beautiful graphs for one or multiple datasets.
|
235
236
|
test_files: []
|