gruff 0.2.8 → 0.2.9
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.
- data/CHANGELOG +5 -1
- data/Manifest.txt +15 -10
- data/Rakefile +20 -3
- data/assets/bubble.png +0 -0
- data/assets/plastik/blue.png +0 -0
- data/assets/plastik/green.png +0 -0
- data/assets/plastik/red.png +0 -0
- data/lib/gruff.rb +1 -0
- data/lib/gruff/base.rb +213 -147
- data/lib/gruff/line.rb +11 -0
- data/lib/gruff/mini/legend.rb +3 -3
- data/lib/gruff/mini/side_bar.rb +13 -0
- data/lib/gruff/pie.rb +25 -11
- data/lib/gruff/scene.rb +15 -3
- data/lib/gruff/side_bar.rb +58 -61
- data/lib/gruff/side_stacked_bar.rb +51 -99
- data/lib/gruff/stacked_area.rb +66 -0
- data/lib/gruff/stacked_bar.rb +8 -4
- data/lib/gruff/stacked_mixin.rb +23 -0
- data/test/gruff_test_case.rb +1 -0
- data/test/test_pie.rb +25 -0
- metadata +41 -19
@@ -0,0 +1,66 @@
|
|
1
|
+
|
2
|
+
require File.dirname(__FILE__) + '/base'
|
3
|
+
require File.dirname(__FILE__) + '/stacked_mixin'
|
4
|
+
|
5
|
+
class Gruff::StackedArea < Gruff::Base
|
6
|
+
include StackedMixin
|
7
|
+
attr_accessor :last_series_goes_on_bottom
|
8
|
+
|
9
|
+
def draw
|
10
|
+
super
|
11
|
+
|
12
|
+
return unless @has_data
|
13
|
+
|
14
|
+
@x_increment = @graph_width / (@column_count - 1).to_f
|
15
|
+
@d = @d.stroke 'transparent'
|
16
|
+
|
17
|
+
height = Array.new(@column_count, 0)
|
18
|
+
|
19
|
+
data_points = nil
|
20
|
+
iterator = last_series_goes_on_bottom ? :reverse_each : :each
|
21
|
+
@norm_data.send(iterator) do |data_row|
|
22
|
+
prev_data_points = data_points
|
23
|
+
data_points = Array.new
|
24
|
+
|
25
|
+
@d = @d.fill data_row[DATA_COLOR_INDEX]
|
26
|
+
|
27
|
+
data_row[1].each_with_index do |data_point, index|
|
28
|
+
# Use incremented x and scaled y
|
29
|
+
new_x = @graph_left + (@x_increment * index)
|
30
|
+
new_y = @graph_top + (@graph_height - data_point * @graph_height - height[index])
|
31
|
+
|
32
|
+
height[index] += (data_point * @graph_height)
|
33
|
+
|
34
|
+
data_points << new_x
|
35
|
+
data_points << new_y
|
36
|
+
|
37
|
+
draw_label(new_x, index)
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
if prev_data_points
|
42
|
+
poly_points = data_points.dup
|
43
|
+
(prev_data_points.length/2 - 1).downto(0) do |i|
|
44
|
+
poly_points << prev_data_points[2*i]
|
45
|
+
poly_points << prev_data_points[2*i+1]
|
46
|
+
end
|
47
|
+
poly_points << data_points[0]
|
48
|
+
poly_points << data_points[1]
|
49
|
+
else
|
50
|
+
poly_points = data_points.dup
|
51
|
+
poly_points << @graph_right
|
52
|
+
poly_points << @graph_bottom - 1
|
53
|
+
poly_points << @graph_left
|
54
|
+
poly_points << @graph_bottom - 1
|
55
|
+
poly_points << data_points[0]
|
56
|
+
poly_points << data_points[1]
|
57
|
+
end
|
58
|
+
@d = @d.polyline(*poly_points)
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
@d.draw(@base_image)
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
end
|
data/lib/gruff/stacked_bar.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
|
2
2
|
require File.dirname(__FILE__) + '/base'
|
3
|
+
require File.dirname(__FILE__) + '/stacked_mixin'
|
3
4
|
|
4
5
|
class Gruff::StackedBar < Gruff::Base
|
6
|
+
include StackedMixin
|
5
7
|
|
6
8
|
# Draws a bar graph, but multiple sets are stacked on top of each other.
|
7
9
|
def draw
|
@@ -23,6 +25,11 @@ class Gruff::StackedBar < Gruff::Base
|
|
23
25
|
@d = @d.fill data_row[DATA_COLOR_INDEX]
|
24
26
|
|
25
27
|
data_row[1].each_with_index do |data_point, point_index|
|
28
|
+
# Calculate center based on bar_width and current row
|
29
|
+
label_center = @graph_left + (@bar_width * point_index) + (@bar_width * spacing_factor / 2.0)
|
30
|
+
draw_label(label_center, point_index)
|
31
|
+
|
32
|
+
next if (data_point == 0)
|
26
33
|
# Use incremented x and scaled y
|
27
34
|
left_x = @graph_left + (@bar_width * point_index)
|
28
35
|
left_y = @graph_top + (@graph_height -
|
@@ -32,13 +39,10 @@ class Gruff::StackedBar < Gruff::Base
|
|
32
39
|
right_y = @graph_top + @graph_height - height[point_index] - 1
|
33
40
|
|
34
41
|
# update the total height of the current stacked bar
|
35
|
-
height[point_index] += (data_point * @graph_height
|
42
|
+
height[point_index] += (data_point * @graph_height )
|
36
43
|
|
37
44
|
@d = @d.rectangle(left_x, left_y, right_x, right_y)
|
38
45
|
|
39
|
-
# Calculate center based on bar_width and current row
|
40
|
-
label_center = @graph_left + (@bar_width * point_index) + (@bar_width * spacing_factor / 2.0)
|
41
|
-
draw_label(label_center, point_index)
|
42
46
|
end
|
43
47
|
|
44
48
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
module Gruff::Base::StackedMixin
|
3
|
+
# Used by StackedBar and child classes.
|
4
|
+
#
|
5
|
+
# tsal: moved from Base 03 FEB 2007
|
6
|
+
DATA_VALUES_INDEX = Gruff::Base::DATA_VALUES_INDEX
|
7
|
+
def get_maximum_by_stack
|
8
|
+
# Get sum of each stack
|
9
|
+
max_hash = {}
|
10
|
+
@data.each do |data_set|
|
11
|
+
data_set[DATA_VALUES_INDEX].each_with_index do |data_point, i|
|
12
|
+
max_hash[i] = 0.0 unless max_hash[i]
|
13
|
+
max_hash[i] += data_point.to_f
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# @maximum_value = 0
|
18
|
+
max_hash.keys.each do |key|
|
19
|
+
@maximum_value = max_hash[key] if max_hash[key] > @maximum_value
|
20
|
+
end
|
21
|
+
@minimum_value = 0
|
22
|
+
end
|
23
|
+
end
|
data/test/gruff_test_case.rb
CHANGED
data/test/test_pie.rb
CHANGED
@@ -27,6 +27,31 @@ class TestGruffPie < GruffTestCase
|
|
27
27
|
g.write("test/output/pie_keynote.png")
|
28
28
|
end
|
29
29
|
|
30
|
+
def test_pie_graph_greyscale
|
31
|
+
g = Gruff::Pie.new
|
32
|
+
g.title = "Greyscale Pie Graph Test"
|
33
|
+
g.theme_greyscale
|
34
|
+
@datasets.each do |data|
|
35
|
+
g.data(data[0], data[1])
|
36
|
+
end
|
37
|
+
|
38
|
+
# Default theme
|
39
|
+
g.write("test/output/pie_grey.png")
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_pie_graph_pastel
|
43
|
+
g = Gruff::Pie.new
|
44
|
+
g.theme_pastel
|
45
|
+
g.title = "Pastel Pie Graph Test"
|
46
|
+
@datasets.each do |data|
|
47
|
+
g.data(data[0], data[1])
|
48
|
+
end
|
49
|
+
|
50
|
+
# Default theme
|
51
|
+
g.write("test/output/pie_pastel.png")
|
52
|
+
end
|
53
|
+
|
54
|
+
|
30
55
|
def test_pie_graph_small
|
31
56
|
g = Gruff::Pie.new(400)
|
32
57
|
g.title = "Visual Pie Graph Test Small"
|
metadata
CHANGED
@@ -3,12 +3,11 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: gruff
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date:
|
6
|
+
version: 0.2.9
|
7
|
+
date: 2007-11-07 00:00:00 -08:00
|
8
8
|
summary: Beautiful graphs for one or multiple datasets.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
|
-
- test
|
12
11
|
email: boss@topfunky.com
|
13
12
|
homepage: http://nubyonrails.com/pages/gruff
|
14
13
|
rubyforge_project: gruff
|
@@ -31,11 +30,11 @@ authors:
|
|
31
30
|
- Geoffrey Grosenbach
|
32
31
|
files:
|
33
32
|
- CHANGELOG
|
34
|
-
- Manifest.txt
|
35
33
|
- MIT-LICENSE
|
36
|
-
-
|
34
|
+
- Manifest.txt
|
37
35
|
- README.txt
|
38
|
-
-
|
36
|
+
- Rakefile
|
37
|
+
- assets/bubble.png
|
39
38
|
- assets/city_scene/background/0000.png
|
40
39
|
- assets/city_scene/background/0600.png
|
41
40
|
- assets/city_scene/background/2000.png
|
@@ -58,14 +57,22 @@ files:
|
|
58
57
|
- assets/city_scene/sky/1500.png
|
59
58
|
- assets/city_scene/sky/1700.png
|
60
59
|
- assets/city_scene/sky/2000.png
|
60
|
+
- assets/pc306715.jpg
|
61
|
+
- assets/plastik/blue.png
|
62
|
+
- assets/plastik/green.png
|
63
|
+
- assets/plastik/red.png
|
61
64
|
- lib/gruff.rb
|
65
|
+
- lib/gruff/accumulator_bar.rb
|
62
66
|
- lib/gruff/area.rb
|
63
67
|
- lib/gruff/bar.rb
|
64
68
|
- lib/gruff/bar_conversion.rb
|
65
|
-
- lib/gruff/accumulator_bar.rb
|
66
69
|
- lib/gruff/base.rb
|
67
70
|
- lib/gruff/deprecated.rb
|
68
71
|
- lib/gruff/line.rb
|
72
|
+
- lib/gruff/mini/bar.rb
|
73
|
+
- lib/gruff/mini/legend.rb
|
74
|
+
- lib/gruff/mini/pie.rb
|
75
|
+
- lib/gruff/mini/side_bar.rb
|
69
76
|
- lib/gruff/net.rb
|
70
77
|
- lib/gruff/photo_bar.rb
|
71
78
|
- lib/gruff/pie.rb
|
@@ -73,15 +80,30 @@ files:
|
|
73
80
|
- lib/gruff/side_bar.rb
|
74
81
|
- lib/gruff/side_stacked_bar.rb
|
75
82
|
- lib/gruff/spider.rb
|
83
|
+
- lib/gruff/stacked_area.rb
|
76
84
|
- lib/gruff/stacked_bar.rb
|
77
|
-
- lib/gruff/
|
78
|
-
- lib/gruff/mini/legend.rb
|
79
|
-
- lib/gruff/mini/pie.rb
|
80
|
-
- lib/gruff/mini/side_bar.rb
|
85
|
+
- lib/gruff/stacked_mixin.rb
|
81
86
|
- test/gruff_test_case.rb
|
82
|
-
- test/
|
87
|
+
- test/test_accumulator_bar.rb
|
83
88
|
- test/test_area.rb
|
89
|
+
- test/test_bar.rb
|
90
|
+
- test/test_base.rb
|
91
|
+
- test/test_legend.rb
|
92
|
+
- test/test_line.rb
|
93
|
+
- test/test_mini_bar.rb
|
94
|
+
- test/test_mini_pie.rb
|
95
|
+
- test/test_mini_side_bar.rb
|
96
|
+
- test/test_net.rb
|
97
|
+
- test/test_photo.rb
|
98
|
+
- test/test_pie.rb
|
99
|
+
- test/test_scene.rb
|
100
|
+
- test/test_side_bar.rb
|
101
|
+
- test/test_sidestacked_bar.rb
|
102
|
+
- test/test_spider.rb
|
103
|
+
- test/test_stacked_bar.rb
|
104
|
+
test_files:
|
84
105
|
- test/test_accumulator_bar.rb
|
106
|
+
- test/test_area.rb
|
85
107
|
- test/test_bar.rb
|
86
108
|
- test/test_base.rb
|
87
109
|
- test/test_legend.rb
|
@@ -97,12 +119,12 @@ files:
|
|
97
119
|
- test/test_sidestacked_bar.rb
|
98
120
|
- test/test_spider.rb
|
99
121
|
- test/test_stacked_bar.rb
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
122
|
+
rdoc_options:
|
123
|
+
- --main
|
124
|
+
- README.txt
|
125
|
+
extra_rdoc_files:
|
126
|
+
- Manifest.txt
|
127
|
+
- README.txt
|
106
128
|
executables: []
|
107
129
|
|
108
130
|
extensions: []
|
@@ -117,5 +139,5 @@ dependencies:
|
|
117
139
|
requirements:
|
118
140
|
- - ">="
|
119
141
|
- !ruby/object:Gem::Version
|
120
|
-
version: 1.
|
142
|
+
version: 1.3.0
|
121
143
|
version:
|