gruff 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -0
- data/Manifest.txt +2 -0
- data/lib/gruff.rb +1 -0
- data/lib/gruff/accumulator_bar.rb +27 -0
- data/lib/gruff/base.rb +26 -9
- data/lib/gruff/mini/bar.rb +1 -1
- data/lib/gruff/mini/side_bar.rb +1 -1
- data/lib/gruff/side_bar.rb +2 -2
- data/test/gruff_test_case.rb +1 -0
- data/test/test_accumulator_bar.rb +50 -0
- data/test/test_bar.rb +0 -27
- data/test/test_line.rb +2 -2
- metadata +4 -2
data/CHANGELOG
CHANGED
data/Manifest.txt
CHANGED
@@ -30,6 +30,7 @@ lib/gruff.rb
|
|
30
30
|
lib/gruff/area.rb
|
31
31
|
lib/gruff/bar.rb
|
32
32
|
lib/gruff/bar_conversion.rb
|
33
|
+
lib/gruff/accumulator_bar.rb
|
33
34
|
lib/gruff/base.rb
|
34
35
|
lib/gruff/deprecated.rb
|
35
36
|
lib/gruff/line.rb
|
@@ -48,6 +49,7 @@ lib/gruff/mini/side_bar.rb
|
|
48
49
|
test/gruff_test_case.rb
|
49
50
|
test/output
|
50
51
|
test/test_area.rb
|
52
|
+
test/test_accumulator_bar.rb
|
51
53
|
test/test_bar.rb
|
52
54
|
test/test_base.rb
|
53
55
|
test/test_legend.rb
|
data/lib/gruff.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/base'
|
2
|
+
|
3
|
+
##
|
4
|
+
# A special bar graph that shows a single dataset as a set of
|
5
|
+
# stacked bars. The bottom bar shows the running total and
|
6
|
+
# the top bar shows the new value being added to the array.
|
7
|
+
|
8
|
+
class Gruff::AccumulatorBar < Gruff::StackedBar
|
9
|
+
|
10
|
+
def draw
|
11
|
+
raise(Gruff::IncorrectNumberOfDatasetsException) unless @data.length == 1
|
12
|
+
|
13
|
+
accumulator_array = []
|
14
|
+
index = 0
|
15
|
+
|
16
|
+
increment_array = @data.first[DATA_VALUES_INDEX].inject([]) {|memo, value|
|
17
|
+
memo << ((index > 0) ? (value + memo.max) : value)
|
18
|
+
accumulator_array << memo[index] - value
|
19
|
+
index += 1
|
20
|
+
memo
|
21
|
+
}
|
22
|
+
data "Accumulator", accumulator_array
|
23
|
+
|
24
|
+
super
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/lib/gruff/base.rb
CHANGED
@@ -20,7 +20,7 @@ require File.dirname(__FILE__) + '/deprecated'
|
|
20
20
|
|
21
21
|
module Gruff
|
22
22
|
|
23
|
-
VERSION = '0.2.
|
23
|
+
VERSION = '0.2.8'
|
24
24
|
|
25
25
|
class Base
|
26
26
|
|
@@ -88,6 +88,9 @@ module Gruff
|
|
88
88
|
# Message shown when there is no data. Fits up to 20 characters. Defaults to "No Data."
|
89
89
|
attr_accessor :no_data_message
|
90
90
|
|
91
|
+
# The font size of the large title at the top of the graph
|
92
|
+
attr_accessor :title_font_size
|
93
|
+
|
91
94
|
# Optionally set the size of the font. Based on an 800x600px graph. Default is 20.
|
92
95
|
#
|
93
96
|
# Will be scaled down if graph is smaller than 800px wide.
|
@@ -102,8 +105,6 @@ module Gruff
|
|
102
105
|
# The number of horizontal lines shown for reference
|
103
106
|
attr_accessor :marker_count
|
104
107
|
|
105
|
-
# The font size of the large title at the top of the graph
|
106
|
-
attr_accessor :title_font_size
|
107
108
|
|
108
109
|
# You can manually set a minimum value instead of having the values guessed for you.
|
109
110
|
#
|
@@ -754,14 +755,26 @@ protected
|
|
754
755
|
# Creates a @base_image to draw on.
|
755
756
|
#
|
756
757
|
def render_background
|
757
|
-
|
758
|
+
case @theme_options[:background_colors]
|
759
|
+
when Array
|
758
760
|
@base_image = render_gradiated_background(*@theme_options[:background_colors])
|
761
|
+
when String
|
762
|
+
@base_image = render_solid_background(@theme_options[:background_colors])
|
759
763
|
else
|
760
764
|
@base_image = render_image_background(*@theme_options[:background_image])
|
761
765
|
end
|
762
766
|
end
|
763
767
|
|
764
|
-
|
768
|
+
##
|
769
|
+
# Make a new image at the current size with a solid +color+.
|
770
|
+
|
771
|
+
def render_solid_background(color)
|
772
|
+
Image.new(@columns, @rows) {
|
773
|
+
self.background_color = color
|
774
|
+
}
|
775
|
+
end
|
776
|
+
|
777
|
+
# Use with a theme definition method to draw a gradiated background.
|
765
778
|
def render_gradiated_background(top_color, bottom_color)
|
766
779
|
Image.new(@columns, @rows,
|
767
780
|
GradientFill.new(0, 0, 100, 0, top_color, bottom_color))
|
@@ -862,6 +875,11 @@ protected
|
|
862
875
|
total_sum
|
863
876
|
end
|
864
877
|
|
878
|
+
##
|
879
|
+
# Used by StackedBar and child classes.
|
880
|
+
#
|
881
|
+
# May need to be moved to the StackedBar class.
|
882
|
+
|
865
883
|
def get_maximum_by_stack
|
866
884
|
# Get sum of each stack
|
867
885
|
max_hash = {}
|
@@ -872,7 +890,7 @@ protected
|
|
872
890
|
end
|
873
891
|
end
|
874
892
|
|
875
|
-
@maximum_value = 0
|
893
|
+
# @maximum_value = 0
|
876
894
|
max_hash.keys.each do |key|
|
877
895
|
@maximum_value = max_hash[key] if max_hash[key] > @maximum_value
|
878
896
|
end
|
@@ -915,7 +933,6 @@ private
|
|
915
933
|
# Start over
|
916
934
|
@color_index = 0
|
917
935
|
return @colors[-1]
|
918
|
-
#raise(ColorlistExhaustedException, "There are no more colors left to use.")
|
919
936
|
end
|
920
937
|
end
|
921
938
|
end
|
@@ -961,8 +978,8 @@ private
|
|
961
978
|
|
962
979
|
end # Gruff::Base
|
963
980
|
|
964
|
-
class
|
965
|
-
|
981
|
+
class IncorrectNumberOfDatasetsException < StandardError; end
|
982
|
+
|
966
983
|
end # Gruff
|
967
984
|
|
968
985
|
|
data/lib/gruff/mini/bar.rb
CHANGED
data/lib/gruff/mini/side_bar.rb
CHANGED
data/lib/gruff/side_bar.rb
CHANGED
@@ -32,7 +32,7 @@ class Gruff::SideBar < Gruff::Base
|
|
32
32
|
marker_label = diff.abs * increment
|
33
33
|
|
34
34
|
unless @hide_line_numbers
|
35
|
-
@d.fill = @
|
35
|
+
@d.fill = @font_color
|
36
36
|
@d.font = @font if @font
|
37
37
|
@d.stroke = 'transparent'
|
38
38
|
@d.pointsize = scale_fontsize(@marker_font_size)
|
@@ -51,7 +51,7 @@ class Gruff::SideBar < Gruff::Base
|
|
51
51
|
|
52
52
|
def draw_label(y_offset, index)
|
53
53
|
if !@labels[index].nil? && @labels_seen[index].nil?
|
54
|
-
@d.fill = @
|
54
|
+
@d.fill = @font_color
|
55
55
|
@d.font = @font if @font
|
56
56
|
@d.stroke = 'transparent'
|
57
57
|
@d.font_weight = NormalWeight
|
data/test/gruff_test_case.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/gruff_test_case"
|
2
|
+
|
3
|
+
class TestGruffAccumulatorBar < GruffTestCase
|
4
|
+
|
5
|
+
# TODO Delete old output files once when starting tests
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@datasets = [
|
9
|
+
(1..20).to_a.map { rand(10) }
|
10
|
+
]
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_accumulator
|
14
|
+
g = Gruff::AccumulatorBar.new 500
|
15
|
+
g.title = "Your Savings"
|
16
|
+
g.hide_legend = true
|
17
|
+
|
18
|
+
# g.font = File.expand_path(File.dirname(__FILE__) + "/../assets/fonts/ATMA____.TTF")
|
19
|
+
|
20
|
+
g.marker_font_size = 18
|
21
|
+
|
22
|
+
g.theme = {
|
23
|
+
:colors => ['#aedaa9', '#12a702'], # 3077a9 blue, aedaa9 light green
|
24
|
+
:marker_color => '#dddddd',
|
25
|
+
:font_color => 'black',
|
26
|
+
:background_colors => "white"
|
27
|
+
# :background_image => File.expand_path(File.dirname(__FILE__) + "/../assets/backgrounds/43things.png")
|
28
|
+
}
|
29
|
+
|
30
|
+
# Attempt at negative numbers
|
31
|
+
# g.data 'Savings', (1..20).to_a.map { rand(10) * (rand(2) > 0 ? 1 : -1) }
|
32
|
+
g.data 'Savings', (1..12).to_a.map { rand(100) }
|
33
|
+
g.labels = (0..11).to_a.inject({}) {|memo, index| {index => '12-26'}.merge(memo)}
|
34
|
+
|
35
|
+
g.maximum_value = 1000
|
36
|
+
g.minimum_value = 0
|
37
|
+
|
38
|
+
g.write("test/output/accum_bar.png")
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_too_many_args
|
42
|
+
assert_raise(Gruff::IncorrectNumberOfDatasetsException) {
|
43
|
+
g = Gruff::AccumulatorBar.new
|
44
|
+
g.data 'First', [1,1,1]
|
45
|
+
g.data 'Too Many', [1,1,1]
|
46
|
+
g.write("test/output/_SHOULD_NOT_ACTUALLY_BE_WRITTEN.png")
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/test/test_bar.rb
CHANGED
@@ -132,33 +132,6 @@ class TestGruffBar < GruffTestCase
|
|
132
132
|
g.write("test/output/bar_x_y_labels.png")
|
133
133
|
end
|
134
134
|
|
135
|
-
def test_fireball
|
136
|
-
g = Gruff::Bar.new
|
137
|
-
g.title = "Daring Fireball-type Accumulation Graph"
|
138
|
-
g.hide_line_numbers = true
|
139
|
-
|
140
|
-
running_totals = []
|
141
|
-
new_additions = []
|
142
|
-
|
143
|
-
(0..19).each do |i|
|
144
|
-
add = rand(10)
|
145
|
-
case i
|
146
|
-
when 0
|
147
|
-
running_totals << 0
|
148
|
-
new_additions << add
|
149
|
-
else
|
150
|
-
running_totals << new_additions[i-1]
|
151
|
-
new_additions << running_totals[i-1] + add
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
g.data '1', running_totals
|
156
|
-
g.data '2', new_additions
|
157
|
-
|
158
|
-
g.write("test/output/bar_fireball.png")
|
159
|
-
end
|
160
|
-
|
161
|
-
|
162
135
|
def test_wide_graph
|
163
136
|
g = setup_basic_graph('800x400')
|
164
137
|
g.title = "Wide Graph"
|
data/test/test_line.rb
CHANGED
@@ -13,7 +13,7 @@ class TestGruffLine < GruffTestCase
|
|
13
13
|
|
14
14
|
def test_one_value
|
15
15
|
g = Gruff::Line.new
|
16
|
-
g.title = "One Value
|
16
|
+
g.title = "One Value"
|
17
17
|
g.labels = {
|
18
18
|
0 => '1',
|
19
19
|
1 => '2'
|
@@ -25,7 +25,7 @@ class TestGruffLine < GruffTestCase
|
|
25
25
|
|
26
26
|
def test_one_value_array
|
27
27
|
g = Gruff::Line.new
|
28
|
-
g.title = "One Value
|
28
|
+
g.title = "One Value in an Array"
|
29
29
|
g.labels = {
|
30
30
|
0 => '1',
|
31
31
|
1 => '2'
|
metadata
CHANGED
@@ -3,8 +3,8 @@ 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: 2006-11-
|
6
|
+
version: 0.2.8
|
7
|
+
date: 2006-11-06 00:00:00 -08:00
|
8
8
|
summary: Beautiful graphs for one or multiple datasets.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/gruff/area.rb
|
63
63
|
- lib/gruff/bar.rb
|
64
64
|
- lib/gruff/bar_conversion.rb
|
65
|
+
- lib/gruff/accumulator_bar.rb
|
65
66
|
- lib/gruff/base.rb
|
66
67
|
- lib/gruff/deprecated.rb
|
67
68
|
- lib/gruff/line.rb
|
@@ -80,6 +81,7 @@ files:
|
|
80
81
|
- test/gruff_test_case.rb
|
81
82
|
- test/output
|
82
83
|
- test/test_area.rb
|
84
|
+
- test/test_accumulator_bar.rb
|
83
85
|
- test/test_bar.rb
|
84
86
|
- test/test_base.rb
|
85
87
|
- test/test_legend.rb
|