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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/gruff.gemspec +7 -3
- data/lib/gruff.rb +8 -3
- data/lib/gruff/accumulator_bar.rb +0 -2
- data/lib/gruff/area.rb +0 -4
- data/lib/gruff/bar.rb +18 -5
- data/lib/gruff/base.rb +78 -41
- data/lib/gruff/bezier.rb +0 -4
- data/lib/gruff/bullet.rb +2 -9
- data/lib/gruff/dot.rb +1 -5
- data/lib/gruff/helper/bar_conversion.rb +1 -1
- data/lib/gruff/helper/bar_value_label_mixin.rb +3 -0
- data/lib/gruff/histogram.rb +0 -1
- data/lib/gruff/line.rb +5 -11
- data/lib/gruff/mini/bar.rb +1 -1
- data/lib/gruff/mini/legend.rb +9 -4
- data/lib/gruff/mini/pie.rb +1 -2
- data/lib/gruff/mini/side_bar.rb +1 -2
- data/lib/gruff/net.rb +5 -6
- data/lib/gruff/patch/rmagick.rb +22 -24
- data/lib/gruff/patch/string.rb +7 -4
- data/lib/gruff/photo_bar.rb +0 -4
- data/lib/gruff/pie.rb +1 -5
- data/lib/gruff/renderer/bezier.rb +4 -3
- data/lib/gruff/renderer/circle.rb +4 -3
- data/lib/gruff/renderer/dash_line.rb +4 -3
- data/lib/gruff/renderer/dot.rb +4 -3
- data/lib/gruff/renderer/ellipse.rb +4 -3
- data/lib/gruff/renderer/line.rb +5 -4
- data/lib/gruff/renderer/polygon.rb +5 -4
- data/lib/gruff/renderer/polyline.rb +4 -3
- data/lib/gruff/renderer/rectangle.rb +3 -2
- data/lib/gruff/renderer/renderer.rb +31 -43
- data/lib/gruff/renderer/text.rb +10 -6
- data/lib/gruff/scatter.rb +1 -5
- data/lib/gruff/scene.rb +0 -1
- data/lib/gruff/side_bar.rb +22 -6
- data/lib/gruff/side_stacked_bar.rb +19 -6
- data/lib/gruff/spider.rb +2 -6
- data/lib/gruff/stacked_area.rb +0 -5
- data/lib/gruff/stacked_bar.rb +17 -5
- data/lib/gruff/store/{base_data.rb → basic_data.rb} +5 -7
- data/lib/gruff/store/custom_data.rb +4 -6
- data/lib/gruff/store/store.rb +5 -4
- data/lib/gruff/store/xy_data.rb +6 -7
- data/lib/gruff/version.rb +1 -1
- metadata +18 -15
- data/.editorconfig +0 -14
- data/.github/ISSUE_TEMPLATE.md +0 -18
- data/.gitignore +0 -10
- data/.rubocop.yml +0 -109
- data/.rubocop_todo.yml +0 -112
- data/.travis.yml +0 -26
- data/.yardopts +0 -1
- data/Rakefile +0 -47
- data/docker/Dockerfile +0 -14
- data/docker/build.sh +0 -4
- data/docker/launch.sh +0 -4
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Gruff
|
4
|
+
# @private
|
4
5
|
class Renderer::Polygon
|
5
|
-
def initialize(
|
6
|
-
@color =
|
7
|
-
@width =
|
8
|
-
@opacity =
|
6
|
+
def initialize(color:, width: 1.0, opacity: 1.0)
|
7
|
+
@color = color
|
8
|
+
@width = width
|
9
|
+
@opacity = opacity
|
9
10
|
end
|
10
11
|
|
11
12
|
def render(points)
|
@@ -1,10 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Gruff
|
4
|
+
# @private
|
4
5
|
class Renderer::Polyline
|
5
|
-
def initialize(
|
6
|
-
@color =
|
7
|
-
@width =
|
6
|
+
def initialize(color:, width:)
|
7
|
+
@color = color
|
8
|
+
@width = width
|
8
9
|
end
|
9
10
|
|
10
11
|
def render(points)
|
@@ -1,9 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Gruff
|
4
|
+
# @private
|
4
5
|
class Renderer::Rectangle
|
5
|
-
def initialize(
|
6
|
-
@color =
|
6
|
+
def initialize(color: nil)
|
7
|
+
@color = color
|
7
8
|
end
|
8
9
|
|
9
10
|
def render(upper_left_x, upper_left_y, lower_right_x, lower_right_y)
|
@@ -9,61 +9,49 @@ module Gruff
|
|
9
9
|
|
10
10
|
attr_accessor :draw, :image, :scale, :text_renderers
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
def setup_transparent_background(columns, rows)
|
28
|
-
image = Renderer.instance.render_transparent_background(columns, rows)
|
29
|
-
Renderer.instance.image = image
|
30
|
-
end
|
31
|
-
|
32
|
-
def background_image=(image)
|
33
|
-
Renderer.instance.image = image
|
34
|
-
end
|
12
|
+
def self.setup(columns, rows, font, scale, theme_options)
|
13
|
+
draw = Magick::Draw.new
|
14
|
+
draw.font = font if font
|
15
|
+
# Scale down from 800x600 used to calculate drawing.
|
16
|
+
draw.scale(scale, scale)
|
17
|
+
|
18
|
+
image = Renderer.instance.background(columns, rows, scale, theme_options)
|
19
|
+
|
20
|
+
Renderer.instance.draw = draw
|
21
|
+
Renderer.instance.scale = scale
|
22
|
+
Renderer.instance.image = image
|
23
|
+
Renderer.instance.text_renderers = []
|
24
|
+
end
|
35
25
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
26
|
+
def self.setup_transparent_background(columns, rows)
|
27
|
+
image = Renderer.instance.render_transparent_background(columns, rows)
|
28
|
+
Renderer.instance.image = image
|
29
|
+
end
|
40
30
|
|
41
|
-
|
42
|
-
|
43
|
-
|
31
|
+
def self.background_image=(image)
|
32
|
+
Renderer.instance.image = image
|
33
|
+
end
|
44
34
|
|
45
|
-
|
35
|
+
def self.font=(font)
|
36
|
+
draw = Renderer.instance.draw
|
37
|
+
draw.font = font if font
|
38
|
+
end
|
46
39
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
40
|
+
def self.finish
|
41
|
+
draw = Renderer.instance.draw
|
42
|
+
image = Renderer.instance.image
|
51
43
|
|
52
|
-
|
53
|
-
Renderer.instance.image.write(file_name)
|
54
|
-
end
|
44
|
+
draw.draw(image)
|
55
45
|
|
56
|
-
|
57
|
-
|
58
|
-
self.format = file_format
|
59
|
-
end
|
46
|
+
Renderer.instance.text_renderers.each do |renderer|
|
47
|
+
renderer.render(renderer.width, renderer.height, renderer.x, renderer.y, renderer.gravity)
|
60
48
|
end
|
61
49
|
end
|
62
50
|
|
63
51
|
def background(columns, rows, scale, theme_options)
|
64
52
|
case theme_options[:background_colors]
|
65
53
|
when Array
|
66
|
-
gradated_background(columns, rows, theme_options[:background_colors][0
|
54
|
+
gradated_background(columns, rows, *theme_options[:background_colors][0..1], theme_options[:background_direction])
|
67
55
|
when String
|
68
56
|
solid_background(columns, rows, theme_options[:background_colors])
|
69
57
|
else
|
data/lib/gruff/renderer/text.rb
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Gruff
|
4
|
+
# @private
|
4
5
|
class Renderer::Text
|
5
|
-
|
6
|
+
using Magick::GruffAnnotate
|
7
|
+
|
8
|
+
def initialize(text, font:, size:, color:, weight: Magick::NormalWeight, rotation: nil)
|
6
9
|
@text = text.to_s
|
7
|
-
@font =
|
8
|
-
@font_size =
|
9
|
-
@font_color =
|
10
|
-
@font_weight =
|
11
|
-
@rotation =
|
10
|
+
@font = font
|
11
|
+
@font_size = size
|
12
|
+
@font_color = color
|
13
|
+
@font_weight = weight
|
14
|
+
@rotation = rotation
|
12
15
|
end
|
13
16
|
|
14
17
|
attr_reader :width, :height, :x, :y, :gravity
|
18
|
+
|
15
19
|
def add_to_render_queue(width, height, x, y, gravity = Magick::NorthGravity)
|
16
20
|
@width = width
|
17
21
|
@height = height
|
data/lib/gruff/scatter.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'gruff/base'
|
4
|
-
|
5
3
|
#
|
6
4
|
# Here's how to set up a Gruff::Scatter.
|
7
5
|
#
|
@@ -84,8 +82,6 @@ class Gruff::Scatter < Gruff::Base
|
|
84
82
|
Gruff::Renderer::Circle.new(color: data_row.color, width: stroke_width).render(new_x, new_y, new_x - circle_radius, new_y)
|
85
83
|
end
|
86
84
|
end
|
87
|
-
|
88
|
-
Gruff::Renderer.finish
|
89
85
|
end
|
90
86
|
|
91
87
|
# The first parameter is the name of the dataset. The next two are the
|
@@ -195,7 +191,7 @@ private
|
|
195
191
|
calculate_spread
|
196
192
|
normalize
|
197
193
|
|
198
|
-
|
194
|
+
self.marker_count = (@x_spread / @x_axis_increment).to_i
|
199
195
|
@x_increment = @x_axis_increment
|
200
196
|
end
|
201
197
|
increment_x_scaled = @graph_width.to_f / (@x_spread / @x_increment)
|
data/lib/gruff/scene.rb
CHANGED
data/lib/gruff/side_bar.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'gruff/base'
|
4
|
-
|
5
3
|
# Graph with individual horizontal bars instead of vertical bars.
|
6
4
|
#
|
7
5
|
# Here's how to set up a Gruff::SideBar.
|
@@ -21,6 +19,8 @@ require 'gruff/base'
|
|
21
19
|
# g.write('sidebar.png')
|
22
20
|
#
|
23
21
|
class Gruff::SideBar < Gruff::Base
|
22
|
+
using String::GruffCommify
|
23
|
+
|
24
24
|
# Spacing factor applied between bars.
|
25
25
|
attr_writer :bar_spacing
|
26
26
|
|
@@ -35,12 +35,16 @@ class Gruff::SideBar < Gruff::Base
|
|
35
35
|
# Default is +false+.
|
36
36
|
attr_writer :show_labels_for_bar_values
|
37
37
|
|
38
|
+
# Prevent drawing of column labels left of a side bar graph. Default is +false+.
|
39
|
+
attr_writer :hide_labels
|
40
|
+
|
38
41
|
def initialize_ivars
|
39
42
|
super
|
40
43
|
@bar_spacing = 0.9
|
41
44
|
@group_spacing = 10
|
42
45
|
@label_formatting = nil
|
43
46
|
@show_labels_for_bar_values = false
|
47
|
+
@hide_labels = false
|
44
48
|
end
|
45
49
|
private :initialize_ivars
|
46
50
|
|
@@ -53,6 +57,20 @@ class Gruff::SideBar < Gruff::Base
|
|
53
57
|
draw_bars
|
54
58
|
end
|
55
59
|
|
60
|
+
protected
|
61
|
+
|
62
|
+
def hide_labels?
|
63
|
+
@hide_labels
|
64
|
+
end
|
65
|
+
|
66
|
+
def hide_left_label_area?
|
67
|
+
hide_labels?
|
68
|
+
end
|
69
|
+
|
70
|
+
def hide_bottom_label_area?
|
71
|
+
@hide_line_markers
|
72
|
+
end
|
73
|
+
|
56
74
|
private
|
57
75
|
|
58
76
|
def draw_bars
|
@@ -73,7 +91,7 @@ private
|
|
73
91
|
data_row.points.each_with_index do |data_point, point_index|
|
74
92
|
group_spacing = @group_spacing * @scale * point_index
|
75
93
|
|
76
|
-
# Using the original
|
94
|
+
# Using the original calculations from the stacked bar chart
|
77
95
|
# to get the difference between
|
78
96
|
# part of the bart chart we wish to stack.
|
79
97
|
temp1 = @graph_left + (@graph_width - data_point * @graph_width - height[point_index])
|
@@ -105,8 +123,6 @@ private
|
|
105
123
|
end
|
106
124
|
end
|
107
125
|
end
|
108
|
-
|
109
|
-
Gruff::Renderer.finish
|
110
126
|
end
|
111
127
|
|
112
128
|
# Instead of base class version, draws vertical background lines and label
|
@@ -114,7 +130,7 @@ private
|
|
114
130
|
return if @hide_line_markers
|
115
131
|
|
116
132
|
# Draw horizontal line markers and annotate with numbers
|
117
|
-
number_of_lines =
|
133
|
+
number_of_lines = marker_count
|
118
134
|
number_of_lines = 1 if number_of_lines == 0
|
119
135
|
|
120
136
|
# TODO: Round maximum marker value to a round number like 100, 0.1, 0.5, etc.
|
@@ -1,8 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'gruff/side_bar'
|
4
|
-
require 'gruff/helper/stacked_mixin'
|
5
|
-
|
6
3
|
#
|
7
4
|
# New gruff graph type added to enable sideways stacking bar charts
|
8
5
|
# (basically looks like a x/y flip of a standard stacking bar chart)
|
@@ -40,12 +37,16 @@ class Gruff::SideStackedBar < Gruff::SideBar
|
|
40
37
|
# Default is +false+.
|
41
38
|
attr_writer :show_labels_for_bar_values
|
42
39
|
|
40
|
+
# Prevent drawing of column labels left of a side stacked bar graph. Default is +false+.
|
41
|
+
attr_writer :hide_labels
|
42
|
+
|
43
43
|
def initialize_ivars
|
44
44
|
super
|
45
45
|
@bar_spacing = 0.9
|
46
46
|
@segment_spacing = 2.0
|
47
47
|
@label_formatting = nil
|
48
48
|
@show_labels_for_bar_values = false
|
49
|
+
@hide_labels = false
|
49
50
|
end
|
50
51
|
private :initialize_ivars
|
51
52
|
|
@@ -55,6 +56,20 @@ class Gruff::SideStackedBar < Gruff::SideBar
|
|
55
56
|
super
|
56
57
|
end
|
57
58
|
|
59
|
+
protected
|
60
|
+
|
61
|
+
def hide_labels?
|
62
|
+
@hide_labels
|
63
|
+
end
|
64
|
+
|
65
|
+
def hide_left_label_area?
|
66
|
+
hide_labels?
|
67
|
+
end
|
68
|
+
|
69
|
+
def hide_bottom_label_area?
|
70
|
+
@hide_line_markers
|
71
|
+
end
|
72
|
+
|
58
73
|
private
|
59
74
|
|
60
75
|
def draw_bars
|
@@ -69,7 +84,7 @@ private
|
|
69
84
|
|
70
85
|
store.norm_data.each_with_index do |data_row, row_index|
|
71
86
|
data_row.points.each_with_index do |data_point, point_index|
|
72
|
-
## using the original
|
87
|
+
## using the original calculations from the stacked bar chart to get the difference between
|
73
88
|
## part of the bart chart we wish to stack.
|
74
89
|
temp1 = @graph_left + (@graph_width -
|
75
90
|
data_point * @graph_width -
|
@@ -107,7 +122,5 @@ private
|
|
107
122
|
draw_value_label(x, y, text, true)
|
108
123
|
end
|
109
124
|
end
|
110
|
-
|
111
|
-
Gruff::Renderer.finish
|
112
125
|
end
|
113
126
|
end
|
data/lib/gruff/spider.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'gruff/base'
|
4
|
-
|
5
3
|
# Experimental!!! See also the Net graph.
|
6
4
|
#
|
7
5
|
# Here's how to set up a Gruff::Spider.
|
@@ -15,7 +13,7 @@ require 'gruff/base'
|
|
15
13
|
# g.data :Wisdom, [10]
|
16
14
|
# g.data 'Charisma', [16]
|
17
15
|
# g.write("spider.png")
|
18
|
-
|
16
|
+
#
|
19
17
|
class Gruff::Spider < Gruff::Base
|
20
18
|
# Hide all text.
|
21
19
|
attr_writer :hide_axes
|
@@ -64,8 +62,6 @@ class Gruff::Spider < Gruff::Base
|
|
64
62
|
|
65
63
|
# Draw polygon
|
66
64
|
draw_polygon(center_x, center_y, additive_angle)
|
67
|
-
|
68
|
-
Gruff::Renderer.finish
|
69
65
|
end
|
70
66
|
|
71
67
|
private
|
@@ -118,6 +114,6 @@ private
|
|
118
114
|
end
|
119
115
|
|
120
116
|
def sums_for_spider
|
121
|
-
store.data.
|
117
|
+
store.data.sum { |data_row| data_row.points.first }
|
122
118
|
end
|
123
119
|
end
|
data/lib/gruff/stacked_area.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'gruff/base'
|
4
|
-
require 'gruff/helper/stacked_mixin'
|
5
|
-
|
6
3
|
#
|
7
4
|
# Here's how to set up a Gruff::StackedArea.
|
8
5
|
#
|
@@ -69,7 +66,5 @@ class Gruff::StackedArea < Gruff::Base
|
|
69
66
|
|
70
67
|
Gruff::Renderer::Polygon.new(color: data_row.color).render(poly_points)
|
71
68
|
end
|
72
|
-
|
73
|
-
Gruff::Renderer.finish
|
74
69
|
end
|
75
70
|
end
|
data/lib/gruff/stacked_bar.rb
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'gruff/base'
|
4
|
-
require 'gruff/helper/stacked_mixin'
|
5
|
-
require 'gruff/helper/bar_value_label_mixin'
|
6
|
-
|
7
3
|
#
|
8
4
|
# Here's how to set up a Gruff::StackedBar.
|
9
5
|
#
|
@@ -32,12 +28,16 @@ class Gruff::StackedBar < Gruff::Base
|
|
32
28
|
# Default is +false+.
|
33
29
|
attr_writer :show_labels_for_bar_values
|
34
30
|
|
31
|
+
# Prevent drawing of column labels below a stacked bar graph. Default is +false+.
|
32
|
+
attr_writer :hide_labels
|
33
|
+
|
35
34
|
def initialize_ivars
|
36
35
|
super
|
37
36
|
@bar_spacing = 0.9
|
38
37
|
@segment_spacing = 2
|
39
38
|
@label_formatting = nil
|
40
39
|
@show_labels_for_bar_values = false
|
40
|
+
@hide_labels = false
|
41
41
|
end
|
42
42
|
private :initialize_ivars
|
43
43
|
|
@@ -88,7 +88,19 @@ class Gruff::StackedBar < Gruff::Base
|
|
88
88
|
draw_value_label(x, y, text, true)
|
89
89
|
end
|
90
90
|
end
|
91
|
+
end
|
92
|
+
|
93
|
+
protected
|
94
|
+
|
95
|
+
def hide_labels?
|
96
|
+
@hide_labels
|
97
|
+
end
|
98
|
+
|
99
|
+
def hide_left_label_area?
|
100
|
+
@hide_line_markers
|
101
|
+
end
|
91
102
|
|
92
|
-
|
103
|
+
def hide_bottom_label_area?
|
104
|
+
hide_labels?
|
93
105
|
end
|
94
106
|
end
|
@@ -1,13 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Gruff
|
4
|
-
# @private
|
5
4
|
class Store
|
6
|
-
|
5
|
+
# @private
|
6
|
+
class BasicData < Struct.new(:label, :points, :color)
|
7
7
|
def initialize(label, points, color)
|
8
|
-
|
9
|
-
self.points = Array(points)
|
10
|
-
self.color = color
|
8
|
+
super(label.to_s, Array(points), color)
|
11
9
|
end
|
12
10
|
|
13
11
|
def empty?
|
@@ -26,9 +24,9 @@ module Gruff
|
|
26
24
|
points.compact.max
|
27
25
|
end
|
28
26
|
|
29
|
-
def normalize(
|
27
|
+
def normalize(minimum:, spread:)
|
30
28
|
norm_points = points.map do |point|
|
31
|
-
point.nil? ? nil : (point.to_f -
|
29
|
+
point.nil? ? nil : (point.to_f - minimum.to_f) / spread
|
32
30
|
end
|
33
31
|
|
34
32
|
self.class.new(label, norm_points, color)
|